comparison src/video/x11/SDL_x11gl.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 9d940db55a91
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
50 #define GLX_SLOW_VISUAL_EXT 0x8001 50 #define GLX_SLOW_VISUAL_EXT 0x8001
51 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D 51 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
52 #endif 52 #endif
53 53
54 #if SDL_VIDEO_OPENGL_GLX 54 #if SDL_VIDEO_OPENGL_GLX
55 static int glXExtensionSupported(_THIS, const char *extension) 55 static int
56 { 56 glXExtensionSupported(_THIS, const char *extension)
57 const char *extensions; 57 {
58 const char *start; 58 const char *extensions;
59 const char *where, *terminator; 59 const char *start;
60 60 const char *where, *terminator;
61 /* Extension names should not have spaces. */ 61
62 where = SDL_strchr(extension, ' '); 62 /* Extension names should not have spaces. */
63 if ( where || *extension == '\0' ) { 63 where = SDL_strchr(extension, ' ');
64 return 0; 64 if (where || *extension == '\0') {
65 } 65 return 0;
66 66 }
67 extensions = this->gl_data->glXQueryExtensionsString(GFX_Display,SDL_Screen); 67
68 /* It takes a bit of care to be fool-proof about parsing the 68 extensions =
69 * OpenGL extensions string. Don't be fooled by sub-strings, etc. 69 this->gl_data->glXQueryExtensionsString(GFX_Display, SDL_Screen);
70 */ 70 /* It takes a bit of care to be fool-proof about parsing the
71 71 * OpenGL extensions string. Don't be fooled by sub-strings, etc.
72 start = extensions; 72 */
73 73
74 for (;;) { 74 start = extensions;
75 where = SDL_strstr(start, extension); 75
76 if (!where) break; 76 for (;;) {
77 77 where = SDL_strstr(start, extension);
78 terminator = where + strlen(extension); 78 if (!where)
79 if (where == start || *(where - 1) == ' ') 79 break;
80 if (*terminator == ' ' || *terminator == '\0') return 1; 80
81 81 terminator = where + strlen(extension);
82 start = terminator; 82 if (where == start || *(where - 1) == ' ')
83 } 83 if (*terminator == ' ' || *terminator == '\0')
84 return 0; 84 return 1;
85
86 start = terminator;
87 }
88 return 0;
85 } 89 }
86 #endif /* SDL_VIDEO_OPENGL_GLX */ 90 #endif /* SDL_VIDEO_OPENGL_GLX */
87 91
88 XVisualInfo *X11_GL_GetVisual(_THIS) 92 XVisualInfo *
89 { 93 X11_GL_GetVisual(_THIS)
90 #if SDL_VIDEO_OPENGL_GLX 94 {
91 /* 64 seems nice. */ 95 #if SDL_VIDEO_OPENGL_GLX
92 int attribs[64]; 96 /* 64 seems nice. */
93 int i; 97 int attribs[64];
94 98 int i;
95 /* load the gl driver from a default path */ 99
96 if ( ! this->gl_config.driver_loaded ) { 100 /* load the gl driver from a default path */
97 /* no driver has been loaded, use default (ourselves) */ 101 if (!this->gl_config.driver_loaded) {
98 if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { 102 /* no driver has been loaded, use default (ourselves) */
99 return NULL; 103 if (X11_GL_LoadLibrary(this, NULL) < 0) {
100 } 104 return NULL;
101 } 105 }
102 106 }
103 /* See if we already have a window which we must use */ 107
104 if ( SDL_windowid ) { 108 /* See if we already have a window which we must use */
105 XWindowAttributes a; 109 if (SDL_windowid) {
106 XVisualInfo vi_in; 110 XWindowAttributes a;
107 int out_count; 111 XVisualInfo vi_in;
108 112 int out_count;
109 XGetWindowAttributes(SDL_Display, SDL_Window, &a); 113
110 vi_in.screen = SDL_Screen; 114 XGetWindowAttributes(SDL_Display, SDL_Window, &a);
111 vi_in.visualid = XVisualIDFromVisual(a.visual); 115 vi_in.screen = SDL_Screen;
112 glx_visualinfo = XGetVisualInfo(SDL_Display, 116 vi_in.visualid = XVisualIDFromVisual(a.visual);
113 VisualScreenMask|VisualIDMask, &vi_in, &out_count); 117 glx_visualinfo = XGetVisualInfo(SDL_Display,
114 return glx_visualinfo; 118 VisualScreenMask | VisualIDMask,
115 } 119 &vi_in, &out_count);
116 120 return glx_visualinfo;
117 /* Setup our GLX attributes according to the gl_config. */ 121 }
118 i = 0; 122
119 attribs[i++] = GLX_RGBA; 123 /* Setup our GLX attributes according to the gl_config. */
120 attribs[i++] = GLX_RED_SIZE; 124 i = 0;
121 attribs[i++] = this->gl_config.red_size; 125 attribs[i++] = GLX_RGBA;
122 attribs[i++] = GLX_GREEN_SIZE; 126 attribs[i++] = GLX_RED_SIZE;
123 attribs[i++] = this->gl_config.green_size; 127 attribs[i++] = this->gl_config.red_size;
124 attribs[i++] = GLX_BLUE_SIZE; 128 attribs[i++] = GLX_GREEN_SIZE;
125 attribs[i++] = this->gl_config.blue_size; 129 attribs[i++] = this->gl_config.green_size;
126 130 attribs[i++] = GLX_BLUE_SIZE;
127 if( this->gl_config.alpha_size ) { 131 attribs[i++] = this->gl_config.blue_size;
128 attribs[i++] = GLX_ALPHA_SIZE; 132
129 attribs[i++] = this->gl_config.alpha_size; 133 if (this->gl_config.alpha_size) {
130 } 134 attribs[i++] = GLX_ALPHA_SIZE;
131 135 attribs[i++] = this->gl_config.alpha_size;
132 if( this->gl_config.buffer_size ) { 136 }
133 attribs[i++] = GLX_BUFFER_SIZE; 137
134 attribs[i++] = this->gl_config.buffer_size; 138 if (this->gl_config.buffer_size) {
135 } 139 attribs[i++] = GLX_BUFFER_SIZE;
136 140 attribs[i++] = this->gl_config.buffer_size;
137 if( this->gl_config.double_buffer ) { 141 }
138 attribs[i++] = GLX_DOUBLEBUFFER; 142
139 } 143 if (this->gl_config.double_buffer) {
140 144 attribs[i++] = GLX_DOUBLEBUFFER;
141 attribs[i++] = GLX_DEPTH_SIZE; 145 }
142 attribs[i++] = this->gl_config.depth_size; 146
143 147 attribs[i++] = GLX_DEPTH_SIZE;
144 if( this->gl_config.stencil_size ) { 148 attribs[i++] = this->gl_config.depth_size;
145 attribs[i++] = GLX_STENCIL_SIZE; 149
146 attribs[i++] = this->gl_config.stencil_size; 150 if (this->gl_config.stencil_size) {
147 } 151 attribs[i++] = GLX_STENCIL_SIZE;
148 152 attribs[i++] = this->gl_config.stencil_size;
149 if( this->gl_config.accum_red_size ) { 153 }
150 attribs[i++] = GLX_ACCUM_RED_SIZE; 154
151 attribs[i++] = this->gl_config.accum_red_size; 155 if (this->gl_config.accum_red_size) {
152 } 156 attribs[i++] = GLX_ACCUM_RED_SIZE;
153 157 attribs[i++] = this->gl_config.accum_red_size;
154 if( this->gl_config.accum_green_size ) { 158 }
155 attribs[i++] = GLX_ACCUM_GREEN_SIZE; 159
156 attribs[i++] = this->gl_config.accum_green_size; 160 if (this->gl_config.accum_green_size) {
157 } 161 attribs[i++] = GLX_ACCUM_GREEN_SIZE;
158 162 attribs[i++] = this->gl_config.accum_green_size;
159 if( this->gl_config.accum_blue_size ) { 163 }
160 attribs[i++] = GLX_ACCUM_BLUE_SIZE; 164
161 attribs[i++] = this->gl_config.accum_blue_size; 165 if (this->gl_config.accum_blue_size) {
162 } 166 attribs[i++] = GLX_ACCUM_BLUE_SIZE;
163 167 attribs[i++] = this->gl_config.accum_blue_size;
164 if( this->gl_config.accum_alpha_size ) { 168 }
165 attribs[i++] = GLX_ACCUM_ALPHA_SIZE; 169
166 attribs[i++] = this->gl_config.accum_alpha_size; 170 if (this->gl_config.accum_alpha_size) {
167 } 171 attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
168 172 attribs[i++] = this->gl_config.accum_alpha_size;
169 if( this->gl_config.stereo ) { 173 }
170 attribs[i++] = GLX_STEREO; 174
171 } 175 if (this->gl_config.stereo) {
172 176 attribs[i++] = GLX_STEREO;
173 if( this->gl_config.multisamplebuffers ) { 177 }
174 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; 178
175 attribs[i++] = this->gl_config.multisamplebuffers; 179 if (this->gl_config.multisamplebuffers) {
176 } 180 attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
177 181 attribs[i++] = this->gl_config.multisamplebuffers;
178 if( this->gl_config.multisamplesamples ) { 182 }
179 attribs[i++] = GLX_SAMPLES_ARB; 183
180 attribs[i++] = this->gl_config.multisamplesamples; 184 if (this->gl_config.multisamplesamples) {
181 } 185 attribs[i++] = GLX_SAMPLES_ARB;
182 186 attribs[i++] = this->gl_config.multisamplesamples;
183 if( this->gl_config.accelerated >= 0 && 187 }
184 glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { 188
185 attribs[i++] = GLX_VISUAL_CAVEAT_EXT; 189 if (this->gl_config.accelerated >= 0 &&
186 attribs[i++] = GLX_NONE_EXT; 190 glXExtensionSupported(this, "GLX_EXT_visual_rating")) {
187 } 191 attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
188 192 attribs[i++] = GLX_NONE_EXT;
189 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ 193 }
190 if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { 194 #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
191 attribs[i++] = GLX_X_VISUAL_TYPE; 195 if (!SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR")) {
192 attribs[i++] = GLX_DIRECT_COLOR; 196 attribs[i++] = GLX_X_VISUAL_TYPE;
193 } 197 attribs[i++] = GLX_DIRECT_COLOR;
194 #endif 198 }
195 attribs[i++] = None; 199 #endif
196 200 attribs[i++] = None;
197 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, 201
198 SDL_Screen, attribs); 202 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display,
203 SDL_Screen, attribs);
199 #ifdef GLX_DIRECT_COLOR 204 #ifdef GLX_DIRECT_COLOR
200 if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ 205 if (!glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR")) { /* No DirectColor visual? Try again.. */
201 attribs[i-3] = None; 206 attribs[i - 3] = None;
202 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, 207 glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display,
203 SDL_Screen, attribs); 208 SDL_Screen, attribs);
204 } 209 }
205 #endif 210 #endif
206 if( !glx_visualinfo ) { 211 if (!glx_visualinfo) {
207 SDL_SetError( "Couldn't find matching GLX visual"); 212 SDL_SetError("Couldn't find matching GLX visual");
208 return NULL; 213 return NULL;
209 } 214 }
210 /* 215 /*
211 printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid); 216 printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid);
212 */ 217 */
213 return glx_visualinfo; 218 return glx_visualinfo;
214 #else 219 #else
215 SDL_SetError("X11 driver not configured with OpenGL"); 220 SDL_SetError("X11 driver not configured with OpenGL");
216 return NULL; 221 return NULL;
217 #endif 222 #endif
218 } 223 }
219 224
220 int X11_GL_CreateWindow(_THIS, int w, int h) 225 int
221 { 226 X11_GL_CreateWindow(_THIS, int w, int h)
222 int retval; 227 {
223 #if SDL_VIDEO_OPENGL_GLX 228 int retval;
224 XSetWindowAttributes attributes; 229 #if SDL_VIDEO_OPENGL_GLX
225 unsigned long mask; 230 XSetWindowAttributes attributes;
226 unsigned long black; 231 unsigned long mask;
227 232 unsigned long black;
228 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, 233
229 SDL_Screen)) 234 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, SDL_Screen))
230 ? BlackPixel(SDL_Display, SDL_Screen) : 0; 235 ? BlackPixel(SDL_Display, SDL_Screen) : 0;
231 attributes.background_pixel = black; 236 attributes.background_pixel = black;
232 attributes.border_pixel = black; 237 attributes.border_pixel = black;
233 attributes.colormap = SDL_XColorMap; 238 attributes.colormap = SDL_XColorMap;
234 mask = CWBackPixel | CWBorderPixel | CWColormap; 239 mask = CWBackPixel | CWBorderPixel | CWColormap;
235 240
236 SDL_Window = XCreateWindow(SDL_Display, WMwindow, 241 SDL_Window = XCreateWindow(SDL_Display, WMwindow,
237 0, 0, w, h, 0, glx_visualinfo->depth, 242 0, 0, w, h, 0, glx_visualinfo->depth,
238 InputOutput, glx_visualinfo->visual, 243 InputOutput, glx_visualinfo->visual,
239 mask, &attributes); 244 mask, &attributes);
240 if ( !SDL_Window ) { 245 if (!SDL_Window) {
241 SDL_SetError("Could not create window"); 246 SDL_SetError("Could not create window");
242 return -1; 247 return -1;
243 } 248 }
244 retval = 0; 249 retval = 0;
245 #else 250 #else
246 SDL_SetError("X11 driver not configured with OpenGL"); 251 SDL_SetError("X11 driver not configured with OpenGL");
247 retval = -1; 252 retval = -1;
248 #endif 253 #endif
249 return(retval); 254 return (retval);
250 } 255 }
251 256
252 int X11_GL_CreateContext(_THIS) 257 int
253 { 258 X11_GL_CreateContext(_THIS)
254 int retval; 259 {
255 #if SDL_VIDEO_OPENGL_GLX 260 int retval;
256 261 #if SDL_VIDEO_OPENGL_GLX
257 /* We do this to create a clean separation between X and GLX errors. */ 262
258 XSync( SDL_Display, False ); 263 /* We do this to create a clean separation between X and GLX errors. */
259 glx_context = this->gl_data->glXCreateContext(GFX_Display, 264 XSync(SDL_Display, False);
260 glx_visualinfo, NULL, True); 265 glx_context = this->gl_data->glXCreateContext(GFX_Display,
261 XSync( GFX_Display, False ); 266 glx_visualinfo, NULL, True);
262 267 XSync(GFX_Display, False);
263 if ( glx_context == NULL ) { 268
264 SDL_SetError("Could not create GL context"); 269 if (glx_context == NULL) {
265 return(-1); 270 SDL_SetError("Could not create GL context");
266 } 271 return (-1);
267 if ( X11_GL_MakeCurrent(this) < 0 ) { 272 }
268 return(-1); 273 if (X11_GL_MakeCurrent(this) < 0) {
269 } 274 return (-1);
270 gl_active = 1; 275 }
271 276 gl_active = 1;
272 if ( !glXExtensionSupported(this, "SGI_swap_control") ) { 277
273 this->gl_data->glXSwapIntervalSGI = NULL; 278 if (!glXExtensionSupported(this, "SGI_swap_control")) {
274 } 279 this->gl_data->glXSwapIntervalSGI = NULL;
275 if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { 280 }
276 this->gl_data->glXSwapIntervalMESA = NULL; 281 if (!glXExtensionSupported(this, "GLX_MESA_swap_control")) {
277 this->gl_data->glXGetSwapIntervalMESA = NULL; 282 this->gl_data->glXSwapIntervalMESA = NULL;
278 } 283 this->gl_data->glXGetSwapIntervalMESA = NULL;
279 if ( this->gl_config.swap_control >= 0 ) { 284 }
280 if ( this->gl_data->glXSwapIntervalMESA ) { 285 if (this->gl_config.swap_control >= 0) {
281 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control); 286 if (this->gl_data->glXSwapIntervalMESA) {
282 } else if ( this->gl_data->glXSwapIntervalSGI ) { 287 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control);
283 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control); 288 } else if (this->gl_data->glXSwapIntervalSGI) {
284 } 289 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control);
285 } 290 }
291 }
286 #else 292 #else
287 SDL_SetError("X11 driver not configured with OpenGL"); 293 SDL_SetError("X11 driver not configured with OpenGL");
288 #endif 294 #endif
289 if ( gl_active ) { 295 if (gl_active) {
290 retval = 0; 296 retval = 0;
291 } else { 297 } else {
292 retval = -1; 298 retval = -1;
293 } 299 }
294 return(retval); 300 return (retval);
295 } 301 }
296 302
297 void X11_GL_Shutdown(_THIS) 303 void
298 { 304 X11_GL_Shutdown(_THIS)
299 #if SDL_VIDEO_OPENGL_GLX 305 {
300 /* Clean up OpenGL */ 306 #if SDL_VIDEO_OPENGL_GLX
301 if( glx_context ) { 307 /* Clean up OpenGL */
302 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); 308 if (glx_context) {
303 309 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
304 if (glx_context != NULL) 310
305 this->gl_data->glXDestroyContext(GFX_Display, glx_context); 311 if (glx_context != NULL)
306 312 this->gl_data->glXDestroyContext(GFX_Display, glx_context);
307 glx_context = NULL; 313
308 } 314 glx_context = NULL;
309 gl_active = 0; 315 }
316 gl_active = 0;
310 #endif /* SDL_VIDEO_OPENGL_GLX */ 317 #endif /* SDL_VIDEO_OPENGL_GLX */
311 } 318 }
312 319
313 #if SDL_VIDEO_OPENGL_GLX 320 #if SDL_VIDEO_OPENGL_GLX
314 321
315 /* Make the current context active */ 322 /* Make the current context active */
316 int X11_GL_MakeCurrent(_THIS) 323 int
317 { 324 X11_GL_MakeCurrent(_THIS)
318 int retval; 325 {
319 326 int retval;
320 retval = 0; 327
321 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, 328 retval = 0;
322 SDL_Window, glx_context) ) { 329 if (!this->gl_data->glXMakeCurrent(GFX_Display, SDL_Window, glx_context)) {
323 SDL_SetError("Unable to make GL context current"); 330 SDL_SetError("Unable to make GL context current");
324 retval = -1; 331 retval = -1;
325 } 332 }
326 XSync( GFX_Display, False ); 333 XSync(GFX_Display, False);
327 334
328 /* More Voodoo X server workarounds... Grr... */ 335 /* More Voodoo X server workarounds... Grr... */
329 SDL_Lock_EventThread(); 336 SDL_Lock_EventThread();
330 X11_CheckDGAMouse(this); 337 X11_CheckDGAMouse(this);
331 SDL_Unlock_EventThread(); 338 SDL_Unlock_EventThread();
332 339
333 return(retval); 340 return (retval);
334 } 341 }
335 342
336 /* Get attribute data from glX. */ 343 /* Get attribute data from glX. */
337 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) 344 int
338 { 345 X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
339 int retval; 346 {
340 int glx_attrib = None; 347 int retval;
341 348 int glx_attrib = None;
342 switch( attrib ) { 349
343 case SDL_GL_RED_SIZE: 350 switch (attrib) {
344 glx_attrib = GLX_RED_SIZE; 351 case SDL_GL_RED_SIZE:
345 break; 352 glx_attrib = GLX_RED_SIZE;
346 case SDL_GL_GREEN_SIZE: 353 break;
347 glx_attrib = GLX_GREEN_SIZE; 354 case SDL_GL_GREEN_SIZE:
348 break; 355 glx_attrib = GLX_GREEN_SIZE;
349 case SDL_GL_BLUE_SIZE: 356 break;
350 glx_attrib = GLX_BLUE_SIZE; 357 case SDL_GL_BLUE_SIZE:
351 break; 358 glx_attrib = GLX_BLUE_SIZE;
352 case SDL_GL_ALPHA_SIZE: 359 break;
353 glx_attrib = GLX_ALPHA_SIZE; 360 case SDL_GL_ALPHA_SIZE:
354 break; 361 glx_attrib = GLX_ALPHA_SIZE;
355 case SDL_GL_DOUBLEBUFFER: 362 break;
356 glx_attrib = GLX_DOUBLEBUFFER; 363 case SDL_GL_DOUBLEBUFFER:
357 break; 364 glx_attrib = GLX_DOUBLEBUFFER;
358 case SDL_GL_BUFFER_SIZE: 365 break;
359 glx_attrib = GLX_BUFFER_SIZE; 366 case SDL_GL_BUFFER_SIZE:
360 break; 367 glx_attrib = GLX_BUFFER_SIZE;
361 case SDL_GL_DEPTH_SIZE: 368 break;
362 glx_attrib = GLX_DEPTH_SIZE; 369 case SDL_GL_DEPTH_SIZE:
363 break; 370 glx_attrib = GLX_DEPTH_SIZE;
364 case SDL_GL_STENCIL_SIZE: 371 break;
365 glx_attrib = GLX_STENCIL_SIZE; 372 case SDL_GL_STENCIL_SIZE:
366 break; 373 glx_attrib = GLX_STENCIL_SIZE;
367 case SDL_GL_ACCUM_RED_SIZE: 374 break;
368 glx_attrib = GLX_ACCUM_RED_SIZE; 375 case SDL_GL_ACCUM_RED_SIZE:
369 break; 376 glx_attrib = GLX_ACCUM_RED_SIZE;
370 case SDL_GL_ACCUM_GREEN_SIZE: 377 break;
371 glx_attrib = GLX_ACCUM_GREEN_SIZE; 378 case SDL_GL_ACCUM_GREEN_SIZE:
372 break; 379 glx_attrib = GLX_ACCUM_GREEN_SIZE;
373 case SDL_GL_ACCUM_BLUE_SIZE: 380 break;
374 glx_attrib = GLX_ACCUM_BLUE_SIZE; 381 case SDL_GL_ACCUM_BLUE_SIZE:
375 break; 382 glx_attrib = GLX_ACCUM_BLUE_SIZE;
376 case SDL_GL_ACCUM_ALPHA_SIZE: 383 break;
377 glx_attrib = GLX_ACCUM_ALPHA_SIZE; 384 case SDL_GL_ACCUM_ALPHA_SIZE:
378 break; 385 glx_attrib = GLX_ACCUM_ALPHA_SIZE;
379 case SDL_GL_STEREO: 386 break;
380 glx_attrib = GLX_STEREO; 387 case SDL_GL_STEREO:
381 break; 388 glx_attrib = GLX_STEREO;
382 case SDL_GL_MULTISAMPLEBUFFERS: 389 break;
383 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; 390 case SDL_GL_MULTISAMPLEBUFFERS:
384 break; 391 glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
385 case SDL_GL_MULTISAMPLESAMPLES: 392 break;
386 glx_attrib = GLX_SAMPLES_ARB; 393 case SDL_GL_MULTISAMPLESAMPLES:
387 break; 394 glx_attrib = GLX_SAMPLES_ARB;
388 case SDL_GL_ACCELERATED_VISUAL: 395 break;
389 if ( glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { 396 case SDL_GL_ACCELERATED_VISUAL:
390 glx_attrib = GLX_VISUAL_CAVEAT_EXT; 397 if (glXExtensionSupported(this, "GLX_EXT_visual_rating")) {
391 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 398 glx_attrib = GLX_VISUAL_CAVEAT_EXT;
392 if ( *value == GLX_SLOW_VISUAL_EXT ) { 399 retval =
393 *value = SDL_FALSE; 400 this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo,
394 } else { 401 glx_attrib, value);
395 *value = SDL_TRUE; 402 if (*value == GLX_SLOW_VISUAL_EXT) {
396 } 403 *value = SDL_FALSE;
397 return retval; 404 } else {
398 } else { 405 *value = SDL_TRUE;
399 return(-1); 406 }
400 } 407 return retval;
401 break; 408 } else {
402 case SDL_GL_SWAP_CONTROL: 409 return (-1);
403 if ( this->gl_data->glXGetSwapIntervalMESA ) { 410 }
404 *value = this->gl_data->glXGetSwapIntervalMESA(); 411 break;
405 return(0); 412 case SDL_GL_SWAP_CONTROL:
406 } else { 413 if (this->gl_data->glXGetSwapIntervalMESA) {
407 return(-1); 414 *value = this->gl_data->glXGetSwapIntervalMESA();
408 } 415 return (0);
409 break; 416 } else {
410 default: 417 return (-1);
411 return(-1); 418 }
412 } 419 break;
413 420 default:
414 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 421 return (-1);
415 422 }
416 return retval; 423
417 } 424 retval =
418 425 this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib,
419 void X11_GL_SwapBuffers(_THIS) 426 value);
420 { 427
421 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); 428 return retval;
429 }
430
431 void
432 X11_GL_SwapBuffers(_THIS)
433 {
434 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
422 } 435 }
423 436
424 #endif /* SDL_VIDEO_OPENGL_GLX */ 437 #endif /* SDL_VIDEO_OPENGL_GLX */
425 438
426 #define OPENGL_REQUIRS_DLOPEN 439 #define OPENGL_REQUIRS_DLOPEN
433 #define GL_LoadObject SDL_LoadObject 446 #define GL_LoadObject SDL_LoadObject
434 #define GL_LoadFunction SDL_LoadFunction 447 #define GL_LoadFunction SDL_LoadFunction
435 #define GL_UnloadObject SDL_UnloadObject 448 #define GL_UnloadObject SDL_UnloadObject
436 #endif 449 #endif
437 450
438 void X11_GL_UnloadLibrary(_THIS) 451 void
439 { 452 X11_GL_UnloadLibrary(_THIS)
440 #if SDL_VIDEO_OPENGL_GLX 453 {
441 if ( this->gl_config.driver_loaded ) { 454 #if SDL_VIDEO_OPENGL_GLX
442 455 if (this->gl_config.driver_loaded) {
443 GL_UnloadObject(this->gl_config.dll_handle); 456
444 457 GL_UnloadObject(this->gl_config.dll_handle);
445 this->gl_data->glXGetProcAddress = NULL; 458
446 this->gl_data->glXChooseVisual = NULL; 459 this->gl_data->glXGetProcAddress = NULL;
447 this->gl_data->glXCreateContext = NULL; 460 this->gl_data->glXChooseVisual = NULL;
448 this->gl_data->glXDestroyContext = NULL; 461 this->gl_data->glXCreateContext = NULL;
449 this->gl_data->glXMakeCurrent = NULL; 462 this->gl_data->glXDestroyContext = NULL;
450 this->gl_data->glXSwapBuffers = NULL; 463 this->gl_data->glXMakeCurrent = NULL;
451 this->gl_data->glXSwapIntervalSGI = NULL; 464 this->gl_data->glXSwapBuffers = NULL;
452 this->gl_data->glXSwapIntervalMESA = NULL; 465 this->gl_data->glXSwapIntervalSGI = NULL;
453 this->gl_data->glXGetSwapIntervalMESA = NULL; 466 this->gl_data->glXSwapIntervalMESA = NULL;
454 467 this->gl_data->glXGetSwapIntervalMESA = NULL;
455 this->gl_config.dll_handle = NULL; 468
456 this->gl_config.driver_loaded = 0; 469 this->gl_config.dll_handle = NULL;
457 } 470 this->gl_config.driver_loaded = 0;
471 }
458 #endif 472 #endif
459 } 473 }
460 474
461 #if SDL_VIDEO_OPENGL_GLX 475 #if SDL_VIDEO_OPENGL_GLX
462 476
463 /* Passing a NULL path means load pointers from the application */ 477 /* Passing a NULL path means load pointers from the application */
464 int X11_GL_LoadLibrary(_THIS, const char* path) 478 int
465 { 479 X11_GL_LoadLibrary(_THIS, const char *path)
466 void* handle = NULL; 480 {
467 481 void *handle = NULL;
468 if ( gl_active ) { 482
469 SDL_SetError("OpenGL context already created"); 483 if (gl_active) {
470 return -1; 484 SDL_SetError("OpenGL context already created");
471 } 485 return -1;
472 486 }
473 if ( path == NULL ) { 487
474 path = SDL_getenv("SDL_VIDEO_GL_DRIVER"); 488 if (path == NULL) {
475 if ( path == NULL ) { 489 path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
476 path = DEFAULT_OPENGL; 490 if (path == NULL) {
477 } 491 path = DEFAULT_OPENGL;
478 } 492 }
479 493 }
480 handle = GL_LoadObject(path); 494
481 if ( handle == NULL ) { 495 handle = GL_LoadObject(path);
482 /* SDL_LoadObject() will call SDL_SetError() for us. */ 496 if (handle == NULL) {
483 return -1; 497 /* SDL_LoadObject() will call SDL_SetError() for us. */
484 } 498 return -1;
485 499 }
486 /* Unload the old driver and reset the pointers */ 500
487 X11_GL_UnloadLibrary(this); 501 /* Unload the old driver and reset the pointers */
488 502 X11_GL_UnloadLibrary(this);
489 /* Load new function pointers */ 503
490 this->gl_data->glXGetProcAddress = 504 /* Load new function pointers */
491 (void *(*)(const GLubyte *)) GL_LoadFunction(handle, "glXGetProcAddressARB"); 505 this->gl_data->glXGetProcAddress =
492 this->gl_data->glXChooseVisual = 506 (void *(*)(const GLubyte *)) GL_LoadFunction(handle,
493 (XVisualInfo *(*)(Display *, int, int *)) GL_LoadFunction(handle, "glXChooseVisual"); 507 "glXGetProcAddressARB");
494 this->gl_data->glXCreateContext = 508 this->gl_data->glXChooseVisual =
495 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) GL_LoadFunction(handle, "glXCreateContext"); 509 (XVisualInfo * (*)(Display *, int, int *)) GL_LoadFunction(handle,
496 this->gl_data->glXDestroyContext = 510 "glXChooseVisual");
497 (void (*)(Display *, GLXContext)) GL_LoadFunction(handle, "glXDestroyContext"); 511 this->gl_data->glXCreateContext =
498 this->gl_data->glXMakeCurrent = 512 (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
499 (int (*)(Display *, GLXDrawable, GLXContext)) GL_LoadFunction(handle, "glXMakeCurrent"); 513 GL_LoadFunction(handle, "glXCreateContext");
500 this->gl_data->glXSwapBuffers = 514 this->gl_data->glXDestroyContext =
501 (void (*)(Display *, GLXDrawable)) GL_LoadFunction(handle, "glXSwapBuffers"); 515 (void (*)(Display *, GLXContext)) GL_LoadFunction(handle,
502 this->gl_data->glXGetConfig = 516 "glXDestroyContext");
503 (int (*)(Display *, XVisualInfo *, int, int *)) GL_LoadFunction(handle, "glXGetConfig"); 517 this->gl_data->glXMakeCurrent =
504 this->gl_data->glXQueryExtensionsString = 518 (int (*)(Display *, GLXDrawable, GLXContext)) GL_LoadFunction(handle,
505 (const char *(*)(Display *, int)) GL_LoadFunction(handle, "glXQueryExtensionsString"); 519 "glXMakeCurrent");
506 this->gl_data->glXSwapIntervalSGI = 520 this->gl_data->glXSwapBuffers =
507 (int (*)(int)) GL_LoadFunction(handle, "glXSwapIntervalSGI"); 521 (void (*)(Display *, GLXDrawable)) GL_LoadFunction(handle,
508 this->gl_data->glXSwapIntervalMESA = 522 "glXSwapBuffers");
509 (GLint (*)(unsigned)) GL_LoadFunction(handle, "glXSwapIntervalMESA"); 523 this->gl_data->glXGetConfig =
510 this->gl_data->glXGetSwapIntervalMESA = 524 (int (*)(Display *, XVisualInfo *, int, int *))
511 (GLint (*)(void)) GL_LoadFunction(handle, "glXGetSwapIntervalMESA"); 525 GL_LoadFunction(handle, "glXGetConfig");
512 526 this->gl_data->glXQueryExtensionsString =
513 if ( (this->gl_data->glXChooseVisual == NULL) || 527 (const char *(*)(Display *, int)) GL_LoadFunction(handle,
514 (this->gl_data->glXCreateContext == NULL) || 528 "glXQueryExtensionsString");
515 (this->gl_data->glXDestroyContext == NULL) || 529 this->gl_data->glXSwapIntervalSGI =
516 (this->gl_data->glXMakeCurrent == NULL) || 530 (int (*)(int)) GL_LoadFunction(handle, "glXSwapIntervalSGI");
517 (this->gl_data->glXSwapBuffers == NULL) || 531 this->gl_data->glXSwapIntervalMESA =
518 (this->gl_data->glXGetConfig == NULL) || 532 (GLint(*)(unsigned)) GL_LoadFunction(handle, "glXSwapIntervalMESA");
519 (this->gl_data->glXQueryExtensionsString == NULL)) { 533 this->gl_data->glXGetSwapIntervalMESA =
520 SDL_SetError("Could not retrieve OpenGL functions"); 534 (GLint(*)(void)) GL_LoadFunction(handle, "glXGetSwapIntervalMESA");
521 return -1; 535
522 } 536 if ((this->gl_data->glXChooseVisual == NULL) ||
523 537 (this->gl_data->glXCreateContext == NULL) ||
524 this->gl_config.dll_handle = handle; 538 (this->gl_data->glXDestroyContext == NULL) ||
525 this->gl_config.driver_loaded = 1; 539 (this->gl_data->glXMakeCurrent == NULL) ||
526 if ( path ) { 540 (this->gl_data->glXSwapBuffers == NULL) ||
527 SDL_strlcpy(this->gl_config.driver_path, path, 541 (this->gl_data->glXGetConfig == NULL) ||
528 SDL_arraysize(this->gl_config.driver_path)); 542 (this->gl_data->glXQueryExtensionsString == NULL)) {
529 } else { 543 SDL_SetError("Could not retrieve OpenGL functions");
530 *this->gl_config.driver_path = '\0'; 544 return -1;
531 } 545 }
532 return 0; 546
533 } 547 this->gl_config.dll_handle = handle;
534 548 this->gl_config.driver_loaded = 1;
535 void *X11_GL_GetProcAddress(_THIS, const char* proc) 549 if (path) {
536 { 550 SDL_strlcpy(this->gl_config.driver_path, path,
537 void* handle; 551 SDL_arraysize(this->gl_config.driver_path));
538 552 } else {
539 handle = this->gl_config.dll_handle; 553 *this->gl_config.driver_path = '\0';
540 if ( this->gl_data->glXGetProcAddress ) { 554 }
541 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); 555 return 0;
542 } 556 }
543 return GL_LoadFunction(handle, proc); 557
558 void *
559 X11_GL_GetProcAddress(_THIS, const char *proc)
560 {
561 void *handle;
562
563 handle = this->gl_config.dll_handle;
564 if (this->gl_data->glXGetProcAddress) {
565 return this->gl_data->glXGetProcAddress((const GLubyte *) proc);
566 }
567 return GL_LoadFunction(handle, proc);
544 } 568 }
545 569
546 #endif /* SDL_VIDEO_OPENGL_GLX */ 570 #endif /* SDL_VIDEO_OPENGL_GLX */
571
572 /* vi: set ts=4 sw=4 expandtab: */