comparison src/video/x11/SDL_x11gl.c @ 1656:96c2f89cc7e1 SDL-1.3

SDL-trunk-1.3-merge-1
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Apr 2006 09:09:48 +0000
parents d75c2d78e87d
children 14717b52abc0
comparison
equal deleted inserted replaced
1655:59227394023d 1656:96c2f89cc7e1
41 #define GLX_ARB_multisample 41 #define GLX_ARB_multisample
42 #define GLX_SAMPLE_BUFFERS_ARB 100000 42 #define GLX_SAMPLE_BUFFERS_ARB 100000
43 #define GLX_SAMPLES_ARB 100001 43 #define GLX_SAMPLES_ARB 100001
44 #endif 44 #endif
45 45
46 #ifndef GLX_EXT_visual_rating
47 #define GLX_EXT_visual_rating
48 #define GLX_VISUAL_CAVEAT_EXT 0x20
49 #define GLX_SLOW_VISUAL_EXT 0x8001
50 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
51 #endif
52
53 #if SDL_VIDEO_OPENGL_GLX
54 static int glXExtensionSupported(_THIS, const char *extension)
55 {
56 const char *extensions;
57 const char *start;
58 const char *where, *terminator;
59
60 /* Extension names should not have spaces. */
61 where = SDL_strchr(extension, ' ');
62 if ( where || *extension == '\0' ) {
63 return 0;
64 }
65
66 extensions = this->gl_data->glXQueryExtensionsString(GFX_Display,SDL_Screen);
67 /* It takes a bit of care to be fool-proof about parsing the
68 * OpenGL extensions string. Don't be fooled by sub-strings, etc.
69 */
70
71 start = extensions;
72
73 for (;;) {
74 where = SDL_strstr(start, extension);
75 if (!where) break;
76
77 terminator = where + strlen(extension);
78 if (where == start || *(where - 1) == ' ')
79 if (*terminator == ' ' || *terminator == '\0') return 1;
80
81 start = terminator;
82 }
83 return 0;
84 }
85 #endif /* SDL_VIDEO_OPENGL_GLX */
86
46 XVisualInfo *X11_GL_GetVisual(_THIS) 87 XVisualInfo *X11_GL_GetVisual(_THIS)
47 { 88 {
48 #if SDL_VIDEO_OPENGL_GLX 89 #if SDL_VIDEO_OPENGL_GLX
49 /* 64 seems nice. */ 90 /* 64 seems nice. */
50 int attribs[64]; 91 int attribs[64];
136 if( this->gl_config.multisamplesamples ) { 177 if( this->gl_config.multisamplesamples ) {
137 attribs[i++] = GLX_SAMPLES_ARB; 178 attribs[i++] = GLX_SAMPLES_ARB;
138 attribs[i++] = this->gl_config.multisamplesamples; 179 attribs[i++] = this->gl_config.multisamplesamples;
139 } 180 }
140 181
182 if( this->gl_config.accelerated >= 0 &&
183 glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
184 attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
185 attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE;
186 }
187
141 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ 188 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
142 if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { 189 if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
143 attribs[i++] = GLX_X_VISUAL_TYPE; 190 attribs[i++] = GLX_X_VISUAL_TYPE;
144 attribs[i++] = GLX_DIRECT_COLOR; 191 attribs[i++] = GLX_DIRECT_COLOR;
145 } 192 }
203 250
204 int X11_GL_CreateContext(_THIS) 251 int X11_GL_CreateContext(_THIS)
205 { 252 {
206 int retval; 253 int retval;
207 #if SDL_VIDEO_OPENGL_GLX 254 #if SDL_VIDEO_OPENGL_GLX
255
208 /* We do this to create a clean separation between X and GLX errors. */ 256 /* We do this to create a clean separation between X and GLX errors. */
209 XSync( SDL_Display, False ); 257 XSync( SDL_Display, False );
210 glx_context = this->gl_data->glXCreateContext(GFX_Display, 258 glx_context = this->gl_data->glXCreateContext(GFX_Display,
211 glx_visualinfo, NULL, True); 259 glx_visualinfo, NULL, True);
212 XSync( GFX_Display, False ); 260 XSync( GFX_Display, False );
213 261
214 if (glx_context == NULL) { 262 if ( glx_context == NULL ) {
215 SDL_SetError("Could not create GL context"); 263 SDL_SetError("Could not create GL context");
216 return -1; 264 return(-1);
217 } 265 }
218 266 if ( X11_GL_MakeCurrent(this) < 0 ) {
267 return(-1);
268 }
219 gl_active = 1; 269 gl_active = 1;
270
271 if ( !glXExtensionSupported(this, "SGI_swap_control") ) {
272 this->gl_data->glXSwapIntervalSGI = NULL;
273 }
274 if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) {
275 this->gl_data->glXSwapIntervalMESA = NULL;
276 this->gl_data->glXGetSwapIntervalMESA = NULL;
277 }
278 if ( this->gl_config.swap_control >= 0 ) {
279 if ( this->gl_data->glXSwapIntervalMESA ) {
280 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control);
281 } else if ( this->gl_data->glXSwapIntervalSGI ) {
282 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control);
283 }
284 }
220 #else 285 #else
221 SDL_SetError("X11 driver not configured with OpenGL"); 286 SDL_SetError("X11 driver not configured with OpenGL");
222 #endif 287 #endif
223 if ( gl_active ) { 288 if ( gl_active ) {
224 retval = 0; 289 retval = 0;
317 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; 382 glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
318 break; 383 break;
319 case SDL_GL_MULTISAMPLESAMPLES: 384 case SDL_GL_MULTISAMPLESAMPLES:
320 glx_attrib = GLX_SAMPLES_ARB; 385 glx_attrib = GLX_SAMPLES_ARB;
321 break; 386 break;
387 case SDL_GL_ACCELERATED_VISUAL:
388 if ( glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
389 glx_attrib = GLX_VISUAL_CAVEAT_EXT;
390 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
391 if ( *value == GLX_SLOW_VISUAL_EXT ) {
392 *value = SDL_FALSE;
393 } else {
394 *value = SDL_TRUE;
395 }
396 return retval;
397 } else {
398 return(-1);
399 }
400 break;
401 case SDL_GL_SWAP_CONTROL:
402 if ( this->gl_data->glXGetSwapIntervalMESA ) {
403 return this->gl_data->glXGetSwapIntervalMESA();
404 } else {
405 return(-1)/*(this->gl_config.swap_control > 0)*/;
406 }
407 break;
322 default: 408 default:
323 return(-1); 409 return(-1);
324 } 410 }
325 411
326 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 412 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
346 this->gl_data->glXChooseVisual = NULL; 432 this->gl_data->glXChooseVisual = NULL;
347 this->gl_data->glXCreateContext = NULL; 433 this->gl_data->glXCreateContext = NULL;
348 this->gl_data->glXDestroyContext = NULL; 434 this->gl_data->glXDestroyContext = NULL;
349 this->gl_data->glXMakeCurrent = NULL; 435 this->gl_data->glXMakeCurrent = NULL;
350 this->gl_data->glXSwapBuffers = NULL; 436 this->gl_data->glXSwapBuffers = NULL;
437 this->gl_data->glXSwapIntervalSGI = NULL;
438 this->gl_data->glXSwapIntervalMESA = NULL;
439 this->gl_data->glXGetSwapIntervalMESA = NULL;
351 440
352 this->gl_config.dll_handle = NULL; 441 this->gl_config.dll_handle = NULL;
353 this->gl_config.driver_loaded = 0; 442 this->gl_config.driver_loaded = 0;
354 } 443 }
355 #endif 444 #endif
398 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers"); 487 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers");
399 this->gl_data->glXGetConfig = 488 this->gl_data->glXGetConfig =
400 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig"); 489 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig");
401 this->gl_data->glXQueryExtensionsString = 490 this->gl_data->glXQueryExtensionsString =
402 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString"); 491 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString");
403 492 this->gl_data->glXSwapIntervalSGI =
493 (int (*)(int)) SDL_LoadFunction(handle, "glXSwapIntervalSGI");
494 this->gl_data->glXSwapIntervalMESA =
495 (GLint (*)(unsigned)) SDL_LoadFunction(handle, "glXSwapIntervalMESA");
496 this->gl_data->glXGetSwapIntervalMESA =
497 (GLint (*)(void)) SDL_LoadFunction(handle, "glXGetSwapIntervalMESA");
404 498
405 if ( (this->gl_data->glXChooseVisual == NULL) || 499 if ( (this->gl_data->glXChooseVisual == NULL) ||
406 (this->gl_data->glXCreateContext == NULL) || 500 (this->gl_data->glXCreateContext == NULL) ||
407 (this->gl_data->glXDestroyContext == NULL) || 501 (this->gl_data->glXDestroyContext == NULL) ||
408 (this->gl_data->glXMakeCurrent == NULL) || 502 (this->gl_data->glXMakeCurrent == NULL) ||