comparison src/video/x11/SDL_x11gl.c @ 1736:3b2a92126f4d

Implemented bug #2, 117: Date: Mon, 21 Mar 2005 12:06:14 +0100 From: Per Inge Mathisen Subject: Re: [SDL] Outstanding patches? The patch adds support for setting SDL_GL_SWAP_CONTROL to Windows and X11. In Windows you can also query this enum to check that it is working, or see what the default is - such functionality does not exist in GLX. For more information on the standards implemented: http://oss.sgi.com/projects/ogl-sample/registry/SGI/swap_control.txt http://oss.sgi.com/projects/ogl-sample/registry/EXT/wgl_swap_control.txt
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Apr 2006 07:59:16 +0000
parents d75c2d78e87d
children eacc5bc01d1c
comparison
equal deleted inserted replaced
1652:dc219ba4cf45 1736:3b2a92126f4d
203 203
204 int X11_GL_CreateContext(_THIS) 204 int X11_GL_CreateContext(_THIS)
205 { 205 {
206 int retval; 206 int retval;
207 #if SDL_VIDEO_OPENGL_GLX 207 #if SDL_VIDEO_OPENGL_GLX
208 const char *glXext;
209
208 /* We do this to create a clean separation between X and GLX errors. */ 210 /* We do this to create a clean separation between X and GLX errors. */
209 XSync( SDL_Display, False ); 211 XSync( SDL_Display, False );
210 glx_context = this->gl_data->glXCreateContext(GFX_Display, 212 glx_context = this->gl_data->glXCreateContext(GFX_Display,
211 glx_visualinfo, NULL, True); 213 glx_visualinfo, NULL, True);
212 XSync( GFX_Display, False ); 214 XSync( GFX_Display, False );
213 215
214 if (glx_context == NULL) { 216 if ( glx_context == NULL ) {
215 SDL_SetError("Could not create GL context"); 217 SDL_SetError("Could not create GL context");
216 return -1; 218 return(-1);
217 } 219 }
218 220 if ( X11_GL_MakeCurrent(this) < 0 ) {
221 return(-1);
222 }
219 gl_active = 1; 223 gl_active = 1;
224
225 /* The use of strstr here should be safe */
226 glXext = this->gl_data->glXQueryExtensionsString(GFX_Display, DefaultScreen(GFX_Display));
227 if ( !SDL_strstr(glXext, "SGI_swap_control") ) {
228 this->gl_data->glXSwapIntervalSGI = NULL;
229 }
230 if ( !SDL_strstr(glXext, "GLX_MESA_swap_control") ) {
231 this->gl_data->glXSwapIntervalMESA = NULL;
232 this->gl_data->glXGetSwapIntervalMESA = NULL;
233 }
234 if ( this->gl_config.swap_control >= 0 ) {
235 if ( this->gl_data->glXSwapIntervalMESA ) {
236 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control);
237 } else if ( this->gl_data->glXSwapIntervalSGI ) {
238 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control);
239 }
240 }
220 #else 241 #else
221 SDL_SetError("X11 driver not configured with OpenGL"); 242 SDL_SetError("X11 driver not configured with OpenGL");
222 #endif 243 #endif
223 if ( gl_active ) { 244 if ( gl_active ) {
224 retval = 0; 245 retval = 0;
317 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; 338 glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
318 break; 339 break;
319 case SDL_GL_MULTISAMPLESAMPLES: 340 case SDL_GL_MULTISAMPLESAMPLES:
320 glx_attrib = GLX_SAMPLES_ARB; 341 glx_attrib = GLX_SAMPLES_ARB;
321 break; 342 break;
343 case SDL_GL_SWAP_CONTROL:
344 if ( this->gl_data->glXGetSwapIntervalMESA ) {
345 return this->gl_data->glXGetSwapIntervalMESA();
346 } else {
347 return -1 /*(this->gl_config.swap_control > 0)*/;
348 }
349 break;
322 default: 350 default:
323 return(-1); 351 return(-1);
324 } 352 }
325 353
326 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 354 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
346 this->gl_data->glXChooseVisual = NULL; 374 this->gl_data->glXChooseVisual = NULL;
347 this->gl_data->glXCreateContext = NULL; 375 this->gl_data->glXCreateContext = NULL;
348 this->gl_data->glXDestroyContext = NULL; 376 this->gl_data->glXDestroyContext = NULL;
349 this->gl_data->glXMakeCurrent = NULL; 377 this->gl_data->glXMakeCurrent = NULL;
350 this->gl_data->glXSwapBuffers = NULL; 378 this->gl_data->glXSwapBuffers = NULL;
379 this->gl_data->glXSwapIntervalSGI = NULL;
380 this->gl_data->glXSwapIntervalMESA = NULL;
381 this->gl_data->glXGetSwapIntervalMESA = NULL;
351 382
352 this->gl_config.dll_handle = NULL; 383 this->gl_config.dll_handle = NULL;
353 this->gl_config.driver_loaded = 0; 384 this->gl_config.driver_loaded = 0;
354 } 385 }
355 #endif 386 #endif
398 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers"); 429 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers");
399 this->gl_data->glXGetConfig = 430 this->gl_data->glXGetConfig =
400 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig"); 431 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig");
401 this->gl_data->glXQueryExtensionsString = 432 this->gl_data->glXQueryExtensionsString =
402 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString"); 433 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString");
403 434 this->gl_data->glXSwapIntervalSGI =
435 (int (*)(int)) SDL_LoadFunction(handle, "glXSwapIntervalSGI");
436 this->gl_data->glXSwapIntervalMESA =
437 (GLint (*)(unsigned)) SDL_LoadFunction(handle, "glXSwapIntervalMESA");
438 this->gl_data->glXGetSwapIntervalMESA =
439 (GLint (*)(void)) SDL_LoadFunction(handle, "glXGetSwapIntervalMESA");
404 440
405 if ( (this->gl_data->glXChooseVisual == NULL) || 441 if ( (this->gl_data->glXChooseVisual == NULL) ||
406 (this->gl_data->glXCreateContext == NULL) || 442 (this->gl_data->glXCreateContext == NULL) ||
407 (this->gl_data->glXDestroyContext == NULL) || 443 (this->gl_data->glXDestroyContext == NULL) ||
408 (this->gl_data->glXMakeCurrent == NULL) || 444 (this->gl_data->glXMakeCurrent == NULL) ||