00001 #include "bcpbuffer.h"
00002 #include "bcresources.h"
00003 #include "bcsignals.h"
00004 #include "bcsynchronous.h"
00005 #include "bcwindowbase.h"
00006
00007
00008
00009
00010 BC_PBuffer::BC_PBuffer(int w, int h)
00011 {
00012 reset();
00013 this->w = w;
00014 this->h = h;
00015
00016
00017 new_pbuffer(w, h);
00018 }
00019
00020 BC_PBuffer::~BC_PBuffer()
00021 {
00022 #ifdef HAVE_GL
00023 BC_WindowBase::get_synchronous()->release_pbuffer(window_id, pbuffer);
00024 #endif
00025 }
00026
00027
00028 void BC_PBuffer::reset()
00029 {
00030 #ifdef HAVE_GL
00031 pbuffer = 0;
00032 window_id = -1;
00033 #endif
00034 }
00035
00036 #ifdef HAVE_GL
00037
00038 GLXPbuffer BC_PBuffer::get_pbuffer()
00039 {
00040 return pbuffer;
00041 }
00042 #endif
00043
00044
00045 void BC_PBuffer::new_pbuffer(int w, int h)
00046 {
00047 #ifdef HAVE_GL
00048
00049 if(!pbuffer)
00050 {
00051 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
00052
00053 pbuffer = BC_WindowBase::get_synchronous()->get_pbuffer(w,
00054 h,
00055 &window_id,
00056 &gl_context);
00057
00058 if(pbuffer)
00059 {
00060 return;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070 #define TOTAL_CONFIGS 1
00071 static int framebuffer_attributes[] =
00072 {
00073 GLX_RENDER_TYPE, GLX_RGBA_BIT,
00074 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT,
00075 GLX_DOUBLEBUFFER, False,
00076 GLX_DEPTH_SIZE, 1,
00077 GLX_ACCUM_RED_SIZE, 1,
00078 GLX_ACCUM_GREEN_SIZE, 1,
00079 GLX_ACCUM_BLUE_SIZE, 1,
00080 GLX_ACCUM_ALPHA_SIZE, 1,
00081 GLX_RED_SIZE, 8,
00082 GLX_GREEN_SIZE, 8,
00083 GLX_BLUE_SIZE, 8,
00084 GLX_ALPHA_SIZE, 8,
00085 None
00086 };
00087
00088 static int pbuffer_attributes[] =
00089 {
00090 GLX_PBUFFER_WIDTH, 0,
00091 GLX_PBUFFER_HEIGHT, 0,
00092 GLX_LARGEST_PBUFFER, False,
00093 GLX_PRESERVED_CONTENTS, True,
00094 None
00095 };
00096
00097 pbuffer_attributes[1] = w;
00098 pbuffer_attributes[3] = h;
00099 if(w % 4) pbuffer_attributes[1] += 4 - (w % 4);
00100 if(h % 4) pbuffer_attributes[3] += 4 - (h % 4);
00101
00102 GLXFBConfig *config_result;
00103 XVisualInfo *visinfo;
00104 int config_result_count = 0;
00105 config_result = glXChooseFBConfig(current_window->get_display(),
00106 current_window->get_screen(),
00107 framebuffer_attributes,
00108 &config_result_count);
00109
00110
00111
00112
00113 if(!config_result || !config_result_count)
00114 {
00115 printf("BC_PBuffer::new_pbuffer: glXChooseFBConfig failed\n");
00116 return;
00117 }
00118
00119
00120 static int current_config = 0;
00121
00122 BC_Resources::error = 0;
00123 pbuffer = glXCreatePbuffer(current_window->get_display(),
00124 config_result[current_config],
00125 pbuffer_attributes);
00126 visinfo = glXGetVisualFromFBConfig(current_window->get_display(),
00127 config_result[current_config]);
00128
00129
00130
00131
00132
00134
00135
00136 if(!BC_Resources::error && pbuffer && visinfo)
00137 {
00138 window_id = current_window->get_id();
00139 gl_context = glXCreateContext(current_window->get_display(),
00140 visinfo,
00141 current_window->gl_win_context,
00142 1);
00143 BC_WindowBase::get_synchronous()->put_pbuffer(w,
00144 h,
00145 pbuffer,
00146 gl_context);
00147
00148
00149
00150 }
00151
00152 if(config_result) XFree(config_result);
00153 if(visinfo) XFree(visinfo);
00154 }
00155
00156
00157 if(!pbuffer) printf("BC_PBuffer::new_pbuffer: failed\n");
00158 #endif
00159 }
00160
00161
00162 void BC_PBuffer::enable_opengl()
00163 {
00164 #ifdef HAVE_GL
00165 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
00166 int result = glXMakeCurrent(current_window->get_display(),
00167 pbuffer,
00168 gl_context);
00169 BC_WindowBase::get_synchronous()->is_pbuffer = 1;
00170 #endif
00171 }
00172