comparison src/video/x11/SDL_x11gl.c @ 1315:e94b0d7c33bc

Merged useful fixes from 1.3 branch
author Sam Lantinga <slouken@libsdl.org>
date Wed, 01 Feb 2006 08:17:54 +0000
parents c9b51268668f
children 3692456e7b0f
comparison
equal deleted inserted replaced
1314:2b3ebc327017 1315:e94b0d7c33bc
42 #define GLX_ARB_multisample 42 #define GLX_ARB_multisample
43 #define GLX_SAMPLE_BUFFERS_ARB 100000 43 #define GLX_SAMPLE_BUFFERS_ARB 100000
44 #define GLX_SAMPLES_ARB 100001 44 #define GLX_SAMPLES_ARB 100001
45 #endif 45 #endif
46 46
47 /* return the preferred visual to use for openGL graphics */
48 XVisualInfo *X11_GL_GetVisual(_THIS) 47 XVisualInfo *X11_GL_GetVisual(_THIS)
49 { 48 {
50 #ifdef HAVE_OPENGL_X11 49 #ifdef HAVE_OPENGL_X11
51 /* 64 seems nice. */ 50 /* 64 seems nice. */
52 int attribs[64]; 51 int attribs[64];
160 #endif 159 #endif
161 if( !glx_visualinfo ) { 160 if( !glx_visualinfo ) {
162 SDL_SetError( "Couldn't find matching GLX visual"); 161 SDL_SetError( "Couldn't find matching GLX visual");
163 return NULL; 162 return NULL;
164 } 163 }
164 /*
165 printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid);
166 */
165 return glx_visualinfo; 167 return glx_visualinfo;
166 #else 168 #else
167 SDL_SetError("X11 driver not configured with OpenGL"); 169 SDL_SetError("X11 driver not configured with OpenGL");
168 return NULL; 170 return NULL;
169 #endif 171 #endif
236 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); 238 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
237 239
238 if (glx_context != NULL) 240 if (glx_context != NULL)
239 this->gl_data->glXDestroyContext(GFX_Display, glx_context); 241 this->gl_data->glXDestroyContext(GFX_Display, glx_context);
240 242
241 if( this->gl_data->glXReleaseBuffersMESA ) {
242 this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window);
243 }
244 glx_context = NULL; 243 glx_context = NULL;
245 } 244 }
246 gl_active = 0; 245 gl_active = 0;
247 #endif /* HAVE_OPENGL_X11 */ 246 #endif /* HAVE_OPENGL_X11 */
248 } 247 }
249 248
250 #ifdef HAVE_OPENGL_X11 249 #ifdef HAVE_OPENGL_X11
251
252 static int ExtensionSupported(const char *extension)
253 {
254 const GLubyte *extensions = NULL;
255 const GLubyte *start;
256 GLubyte *where, *terminator;
257
258 /* Extension names should not have spaces. */
259 where = (GLubyte *) strchr(extension, ' ');
260 if (where || *extension == '\0')
261 return 0;
262
263 extensions = current_video->glGetString(GL_EXTENSIONS);
264 /* It takes a bit of care to be fool-proof about parsing the
265 * OpenGL extensions string. Don't be fooled by sub-strings,
266 * etc. */
267
268 start = extensions;
269
270 for (;;)
271 {
272 where = (GLubyte *) strstr((const char *) start, extension);
273 if (!where) break;
274
275 terminator = where + strlen(extension);
276 if (where == start || *(where - 1) == ' ')
277 if (*terminator == ' ' || *terminator == '\0') return 1;
278
279 start = terminator;
280 }
281
282 return 0;
283 }
284 250
285 /* Make the current context active */ 251 /* Make the current context active */
286 int X11_GL_MakeCurrent(_THIS) 252 int X11_GL_MakeCurrent(_THIS)
287 { 253 {
288 int retval; 254 int retval;
292 SDL_Window, glx_context) ) { 258 SDL_Window, glx_context) ) {
293 SDL_SetError("Unable to make GL context current"); 259 SDL_SetError("Unable to make GL context current");
294 retval = -1; 260 retval = -1;
295 } 261 }
296 pXSync( GFX_Display, False ); 262 pXSync( GFX_Display, False );
297
298 /*
299 * The context is now current, check for glXReleaseBuffersMESA()
300 * extension. If extension is _not_ supported, destroy the pointer
301 * (to make sure it will not be called in X11_GL_Shutdown() ).
302 *
303 * DRI/Mesa drivers include glXReleaseBuffersMESA() in the libGL.so,
304 * but there's no need to call it (is is only needed for some old
305 * non-DRI drivers).
306 *
307 * When using for example glew (http://glew.sf.net), dlsym() for
308 * glXReleaseBuffersMESA() returns the pointer from the glew library
309 * (namespace conflict).
310 *
311 * The glXReleaseBuffersMESA() pointer in the glew is NULL, if the
312 * driver doesn't support this extension. So blindly calling it will
313 * cause segfault with DRI/Mesa drivers!
314 *
315 */
316
317 if ( ! ExtensionSupported("glXReleaseBuffersMESA") ) {
318 this->gl_data->glXReleaseBuffersMESA = NULL;
319 }
320 263
321 /* More Voodoo X server workarounds... Grr... */ 264 /* More Voodoo X server workarounds... Grr... */
322 SDL_Lock_EventThread(); 265 SDL_Lock_EventThread();
323 X11_CheckDGAMouse(this); 266 X11_CheckDGAMouse(this);
324 SDL_Unlock_EventThread(); 267 SDL_Unlock_EventThread();
494 this->gl_data->glXGetConfig = 437 this->gl_data->glXGetConfig =
495 (int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig"); 438 (int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig");
496 this->gl_data->glXQueryExtensionsString = 439 this->gl_data->glXQueryExtensionsString =
497 (const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString"); 440 (const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
498 441
499 /* We don't compare below for this in case we're not using Mesa. */ 442
500 this->gl_data->glXReleaseBuffersMESA =
501 (void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" );
502
503
504 if ( (this->gl_data->glXChooseVisual == NULL) || 443 if ( (this->gl_data->glXChooseVisual == NULL) ||
505 (this->gl_data->glXCreateContext == NULL) || 444 (this->gl_data->glXCreateContext == NULL) ||
506 (this->gl_data->glXDestroyContext == NULL) || 445 (this->gl_data->glXDestroyContext == NULL) ||
507 (this->gl_data->glXMakeCurrent == NULL) || 446 (this->gl_data->glXMakeCurrent == NULL) ||
508 (this->gl_data->glXSwapBuffers == NULL) || 447 (this->gl_data->glXSwapBuffers == NULL) ||