Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11gl.c @ 1737:eacc5bc01d1c
Implemented bug #5
Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Apr 2006 08:39:51 +0000 |
parents | 3b2a92126f4d |
children | 0495a8e98595 |
comparison
equal
deleted
inserted
replaced
1736:3b2a92126f4d | 1737:eacc5bc01d1c |
---|---|
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 |
208 const char *glXext; | |
209 | 255 |
210 /* 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. */ |
211 XSync( SDL_Display, False ); | 257 XSync( SDL_Display, False ); |
212 glx_context = this->gl_data->glXCreateContext(GFX_Display, | 258 glx_context = this->gl_data->glXCreateContext(GFX_Display, |
213 glx_visualinfo, NULL, True); | 259 glx_visualinfo, NULL, True); |
220 if ( X11_GL_MakeCurrent(this) < 0 ) { | 266 if ( X11_GL_MakeCurrent(this) < 0 ) { |
221 return(-1); | 267 return(-1); |
222 } | 268 } |
223 gl_active = 1; | 269 gl_active = 1; |
224 | 270 |
225 /* The use of strstr here should be safe */ | 271 if ( !glXExtensionSupported(this, "SGI_swap_control") ) { |
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; | 272 this->gl_data->glXSwapIntervalSGI = NULL; |
229 } | 273 } |
230 if ( !SDL_strstr(glXext, "GLX_MESA_swap_control") ) { | 274 if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { |
231 this->gl_data->glXSwapIntervalMESA = NULL; | 275 this->gl_data->glXSwapIntervalMESA = NULL; |
232 this->gl_data->glXGetSwapIntervalMESA = NULL; | 276 this->gl_data->glXGetSwapIntervalMESA = NULL; |
233 } | 277 } |
234 if ( this->gl_config.swap_control >= 0 ) { | 278 if ( this->gl_config.swap_control >= 0 ) { |
235 if ( this->gl_data->glXSwapIntervalMESA ) { | 279 if ( this->gl_data->glXSwapIntervalMESA ) { |
338 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; | 382 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; |
339 break; | 383 break; |
340 case SDL_GL_MULTISAMPLESAMPLES: | 384 case SDL_GL_MULTISAMPLESAMPLES: |
341 glx_attrib = GLX_SAMPLES_ARB; | 385 glx_attrib = GLX_SAMPLES_ARB; |
342 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; | |
343 case SDL_GL_SWAP_CONTROL: | 401 case SDL_GL_SWAP_CONTROL: |
344 if ( this->gl_data->glXGetSwapIntervalMESA ) { | 402 if ( this->gl_data->glXGetSwapIntervalMESA ) { |
345 return this->gl_data->glXGetSwapIntervalMESA(); | 403 return this->gl_data->glXGetSwapIntervalMESA(); |
346 } else { | 404 } else { |
347 return -1 /*(this->gl_config.swap_control > 0)*/; | 405 return(-1)/*(this->gl_config.swap_control > 0)*/; |
348 } | 406 } |
349 break; | 407 break; |
350 default: | 408 default: |
351 return(-1); | 409 return(-1); |
352 } | 410 } |