2 #include "bcresources.h"
4 #include "bcsynchronous.h"
5 #include "bcwindowbase.h"
10 BC_PBuffer::BC_PBuffer(int w, int h)
20 BC_PBuffer::~BC_PBuffer()
23 BC_WindowBase::get_synchronous()->release_pbuffer(window_id, pbuffer);
28 void BC_PBuffer::reset()
38 GLXPbuffer BC_PBuffer::get_pbuffer()
45 void BC_PBuffer::new_pbuffer(int w, int h)
51 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
52 // Try previously created PBuffers
53 pbuffer = BC_WindowBase::get_synchronous()->get_pbuffer(w,
67 // You're supposed to try different configurations of decreasing overhead
69 // In reality, only a very specific configuration works at all.
70 #define TOTAL_CONFIGS 1
71 static int framebuffer_attributes[] =
73 GLX_RENDER_TYPE, GLX_RGBA_BIT,
74 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT,
75 GLX_DOUBLEBUFFER, False,
77 GLX_ACCUM_RED_SIZE, 1,
78 GLX_ACCUM_GREEN_SIZE, 1,
79 GLX_ACCUM_BLUE_SIZE, 1,
80 GLX_ACCUM_ALPHA_SIZE, 1,
88 static int pbuffer_attributes[] =
91 GLX_PBUFFER_HEIGHT, 0,
92 GLX_LARGEST_PBUFFER, False,
93 GLX_PRESERVED_CONTENTS, True,
97 pbuffer_attributes[1] = w;
98 pbuffer_attributes[3] = h;
99 if(w % 4) pbuffer_attributes[1] += 4 - (w % 4);
100 if(h % 4) pbuffer_attributes[3] += 4 - (h % 4);
102 GLXFBConfig *config_result;
103 XVisualInfo *visinfo;
104 int config_result_count = 0;
105 config_result = glXChooseFBConfig(current_window->get_display(),
106 current_window->get_screen(),
107 framebuffer_attributes,
108 &config_result_count);
109 // printf("BC_PBuffer::new_pbuffer 1 config_result=%p config_result_count=%d\n",
111 // config_result_count);
113 if(!config_result || !config_result_count)
115 printf("BC_PBuffer::new_pbuffer: glXChooseFBConfig failed\n");
120 static int current_config = 0;
122 BC_Resources::error = 0;
123 pbuffer = glXCreatePbuffer(current_window->get_display(),
124 config_result[current_config],
126 visinfo = glXGetVisualFromFBConfig(current_window->get_display(),
127 config_result[current_config]);
128 // printf("BC_PBuffer::new_pbuffer 2 visual=%d current_config=%d error=%d pbuffer=%p\n",
131 // BC_Resources::error,
136 if(!BC_Resources::error && pbuffer && visinfo)
138 window_id = current_window->get_id();
139 gl_context = glXCreateContext(current_window->get_display(),
141 current_window->gl_win_context,
143 BC_WindowBase::get_synchronous()->put_pbuffer(w,
147 // printf("BC_PBuffer::new_pbuffer gl_context=%p window_id=%d\n",
149 // current_window->get_id());
152 if(config_result) XFree(config_result);
153 if(visinfo) XFree(visinfo);
157 if(!pbuffer) printf("BC_PBuffer::new_pbuffer: failed\n");
162 void BC_PBuffer::enable_opengl()
165 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
166 int result = glXMakeCurrent(current_window->get_display(),
169 BC_WindowBase::get_synchronous()->is_pbuffer = 1;