comparison src/video/x11/SDL_x11gl.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
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,
230 ? BlackPixel(SDL_Display, SDL_Screen) : 0; 235 SDL_Screen))
231 attributes.background_pixel = black; 236 ? BlackPixel (SDL_Display, SDL_Screen) : 0;
232 attributes.border_pixel = black; 237 attributes.background_pixel = black;
233 attributes.colormap = SDL_XColorMap; 238 attributes.border_pixel = black;
234 mask = CWBackPixel | CWBorderPixel | CWColormap; 239 attributes.colormap = SDL_XColorMap;
235 240 mask = CWBackPixel | CWBorderPixel | CWColormap;
236 SDL_Window = XCreateWindow(SDL_Display, WMwindow, 241
237 0, 0, w, h, 0, glx_visualinfo->depth, 242 SDL_Window = XCreateWindow (SDL_Display, WMwindow,
238 InputOutput, glx_visualinfo->visual, 243 0, 0, w, h, 0, glx_visualinfo->depth,
239 mask, &attributes); 244 InputOutput, glx_visualinfo->visual,
240 if ( !SDL_Window ) { 245 mask, &attributes);
241 SDL_SetError("Could not create window"); 246 if (!SDL_Window) {
242 return -1; 247 SDL_SetError ("Could not create window");
243 } 248 return -1;
244 retval = 0; 249 }
250 retval = 0;
245 #else 251 #else
246 SDL_SetError("X11 driver not configured with OpenGL"); 252 SDL_SetError ("X11 driver not configured with OpenGL");
247 retval = -1; 253 retval = -1;
248 #endif 254 #endif
249 return(retval); 255 return (retval);
250 } 256 }
251 257
252 int X11_GL_CreateContext(_THIS) 258 int
253 { 259 X11_GL_CreateContext (_THIS)
254 int retval; 260 {
255 #if SDL_VIDEO_OPENGL_GLX 261 int retval;
256 262 #if SDL_VIDEO_OPENGL_GLX
257 /* We do this to create a clean separation between X and GLX errors. */ 263
258 XSync( SDL_Display, False ); 264 /* We do this to create a clean separation between X and GLX errors. */
259 glx_context = this->gl_data->glXCreateContext(GFX_Display, 265 XSync (SDL_Display, False);
260 glx_visualinfo, NULL, True); 266 glx_context = this->gl_data->glXCreateContext (GFX_Display,
261 XSync( GFX_Display, False ); 267 glx_visualinfo, NULL,
262 268 True);
263 if ( glx_context == NULL ) { 269 XSync (GFX_Display, False);
264 SDL_SetError("Could not create GL context"); 270
265 return(-1); 271 if (glx_context == NULL) {
266 } 272 SDL_SetError ("Could not create GL context");
267 if ( X11_GL_MakeCurrent(this) < 0 ) { 273 return (-1);
268 return(-1); 274 }
269 } 275 if (X11_GL_MakeCurrent (this) < 0) {
270 gl_active = 1; 276 return (-1);
271 277 }
272 if ( !glXExtensionSupported(this, "SGI_swap_control") ) { 278 gl_active = 1;
273 this->gl_data->glXSwapIntervalSGI = NULL; 279
274 } 280 if (!glXExtensionSupported (this, "SGI_swap_control")) {
275 if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { 281 this->gl_data->glXSwapIntervalSGI = NULL;
276 this->gl_data->glXSwapIntervalMESA = NULL; 282 }
277 this->gl_data->glXGetSwapIntervalMESA = NULL; 283 if (!glXExtensionSupported (this, "GLX_MESA_swap_control")) {
278 } 284 this->gl_data->glXSwapIntervalMESA = NULL;
279 if ( this->gl_config.swap_control >= 0 ) { 285 this->gl_data->glXGetSwapIntervalMESA = NULL;
280 if ( this->gl_data->glXSwapIntervalMESA ) { 286 }
281 this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control); 287 if (this->gl_config.swap_control >= 0) {
282 } else if ( this->gl_data->glXSwapIntervalSGI ) { 288 if (this->gl_data->glXSwapIntervalMESA) {
283 this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control); 289 this->gl_data->glXSwapIntervalMESA (this->gl_config.swap_control);
284 } 290 } else if (this->gl_data->glXSwapIntervalSGI) {
285 } 291 this->gl_data->glXSwapIntervalSGI (this->gl_config.swap_control);
292 }
293 }
286 #else 294 #else
287 SDL_SetError("X11 driver not configured with OpenGL"); 295 SDL_SetError ("X11 driver not configured with OpenGL");
288 #endif 296 #endif
289 if ( gl_active ) { 297 if (gl_active) {
290 retval = 0; 298 retval = 0;
291 } else { 299 } else {
292 retval = -1; 300 retval = -1;
293 } 301 }
294 return(retval); 302 return (retval);
295 } 303 }
296 304
297 void X11_GL_Shutdown(_THIS) 305 void
298 { 306 X11_GL_Shutdown (_THIS)
299 #if SDL_VIDEO_OPENGL_GLX 307 {
300 /* Clean up OpenGL */ 308 #if SDL_VIDEO_OPENGL_GLX
301 if( glx_context ) { 309 /* Clean up OpenGL */
302 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); 310 if (glx_context) {
303 311 this->gl_data->glXMakeCurrent (GFX_Display, None, NULL);
304 if (glx_context != NULL) 312
305 this->gl_data->glXDestroyContext(GFX_Display, glx_context); 313 if (glx_context != NULL)
306 314 this->gl_data->glXDestroyContext (GFX_Display, glx_context);
307 glx_context = NULL; 315
308 } 316 glx_context = NULL;
309 gl_active = 0; 317 }
318 gl_active = 0;
310 #endif /* SDL_VIDEO_OPENGL_GLX */ 319 #endif /* SDL_VIDEO_OPENGL_GLX */
311 } 320 }
312 321
313 #if SDL_VIDEO_OPENGL_GLX 322 #if SDL_VIDEO_OPENGL_GLX
314 323
315 /* Make the current context active */ 324 /* Make the current context active */
316 int X11_GL_MakeCurrent(_THIS) 325 int
317 { 326 X11_GL_MakeCurrent (_THIS)
318 int retval; 327 {
319 328 int retval;
320 retval = 0; 329
321 if ( ! this->gl_data->glXMakeCurrent(GFX_Display, 330 retval = 0;
322 SDL_Window, glx_context) ) { 331 if (!this->gl_data->glXMakeCurrent (GFX_Display, SDL_Window, glx_context)) {
323 SDL_SetError("Unable to make GL context current"); 332 SDL_SetError ("Unable to make GL context current");
324 retval = -1; 333 retval = -1;
325 } 334 }
326 XSync( GFX_Display, False ); 335 XSync (GFX_Display, False);
327 336
328 /* More Voodoo X server workarounds... Grr... */ 337 /* More Voodoo X server workarounds... Grr... */
329 SDL_Lock_EventThread(); 338 SDL_Lock_EventThread ();
330 X11_CheckDGAMouse(this); 339 X11_CheckDGAMouse (this);
331 SDL_Unlock_EventThread(); 340 SDL_Unlock_EventThread ();
332 341
333 return(retval); 342 return (retval);
334 } 343 }
335 344
336 /* Get attribute data from glX. */ 345 /* Get attribute data from glX. */
337 int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) 346 int
338 { 347 X11_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
339 int retval; 348 {
340 int glx_attrib = None; 349 int retval;
341 350 int glx_attrib = None;
342 switch( attrib ) { 351
343 case SDL_GL_RED_SIZE: 352 switch (attrib) {
344 glx_attrib = GLX_RED_SIZE; 353 case SDL_GL_RED_SIZE:
345 break; 354 glx_attrib = GLX_RED_SIZE;
346 case SDL_GL_GREEN_SIZE: 355 break;
347 glx_attrib = GLX_GREEN_SIZE; 356 case SDL_GL_GREEN_SIZE:
348 break; 357 glx_attrib = GLX_GREEN_SIZE;
349 case SDL_GL_BLUE_SIZE: 358 break;
350 glx_attrib = GLX_BLUE_SIZE; 359 case SDL_GL_BLUE_SIZE:
351 break; 360 glx_attrib = GLX_BLUE_SIZE;
352 case SDL_GL_ALPHA_SIZE: 361 break;
353 glx_attrib = GLX_ALPHA_SIZE; 362 case SDL_GL_ALPHA_SIZE:
354 break; 363 glx_attrib = GLX_ALPHA_SIZE;
355 case SDL_GL_DOUBLEBUFFER: 364 break;
356 glx_attrib = GLX_DOUBLEBUFFER; 365 case SDL_GL_DOUBLEBUFFER:
357 break; 366 glx_attrib = GLX_DOUBLEBUFFER;
358 case SDL_GL_BUFFER_SIZE: 367 break;
359 glx_attrib = GLX_BUFFER_SIZE; 368 case SDL_GL_BUFFER_SIZE:
360 break; 369 glx_attrib = GLX_BUFFER_SIZE;
361 case SDL_GL_DEPTH_SIZE: 370 break;
362 glx_attrib = GLX_DEPTH_SIZE; 371 case SDL_GL_DEPTH_SIZE:
363 break; 372 glx_attrib = GLX_DEPTH_SIZE;
364 case SDL_GL_STENCIL_SIZE: 373 break;
365 glx_attrib = GLX_STENCIL_SIZE; 374 case SDL_GL_STENCIL_SIZE:
366 break; 375 glx_attrib = GLX_STENCIL_SIZE;
367 case SDL_GL_ACCUM_RED_SIZE: 376 break;
368 glx_attrib = GLX_ACCUM_RED_SIZE; 377 case SDL_GL_ACCUM_RED_SIZE:
369 break; 378 glx_attrib = GLX_ACCUM_RED_SIZE;
370 case SDL_GL_ACCUM_GREEN_SIZE: 379 break;
371 glx_attrib = GLX_ACCUM_GREEN_SIZE; 380 case SDL_GL_ACCUM_GREEN_SIZE:
372 break; 381 glx_attrib = GLX_ACCUM_GREEN_SIZE;
373 case SDL_GL_ACCUM_BLUE_SIZE: 382 break;
374 glx_attrib = GLX_ACCUM_BLUE_SIZE; 383 case SDL_GL_ACCUM_BLUE_SIZE:
375 break; 384 glx_attrib = GLX_ACCUM_BLUE_SIZE;
376 case SDL_GL_ACCUM_ALPHA_SIZE: 385 break;
377 glx_attrib = GLX_ACCUM_ALPHA_SIZE; 386 case SDL_GL_ACCUM_ALPHA_SIZE:
378 break; 387 glx_attrib = GLX_ACCUM_ALPHA_SIZE;
379 case SDL_GL_STEREO: 388 break;
380 glx_attrib = GLX_STEREO; 389 case SDL_GL_STEREO:
381 break; 390 glx_attrib = GLX_STEREO;
382 case SDL_GL_MULTISAMPLEBUFFERS: 391 break;
383 glx_attrib = GLX_SAMPLE_BUFFERS_ARB; 392 case SDL_GL_MULTISAMPLEBUFFERS:
384 break; 393 glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
385 case SDL_GL_MULTISAMPLESAMPLES: 394 break;
386 glx_attrib = GLX_SAMPLES_ARB; 395 case SDL_GL_MULTISAMPLESAMPLES:
387 break; 396 glx_attrib = GLX_SAMPLES_ARB;
388 case SDL_GL_ACCELERATED_VISUAL: 397 break;
389 if ( glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { 398 case SDL_GL_ACCELERATED_VISUAL:
390 glx_attrib = GLX_VISUAL_CAVEAT_EXT; 399 if (glXExtensionSupported (this, "GLX_EXT_visual_rating")) {
391 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 400 glx_attrib = GLX_VISUAL_CAVEAT_EXT;
392 if ( *value == GLX_SLOW_VISUAL_EXT ) { 401 retval =
393 *value = SDL_FALSE; 402 this->gl_data->glXGetConfig (GFX_Display, glx_visualinfo,
394 } else { 403 glx_attrib, value);
395 *value = SDL_TRUE; 404 if (*value == GLX_SLOW_VISUAL_EXT) {
396 } 405 *value = SDL_FALSE;
397 return retval; 406 } else {
398 } else { 407 *value = SDL_TRUE;
399 return(-1); 408 }
400 } 409 return retval;
401 break; 410 } else {
402 case SDL_GL_SWAP_CONTROL: 411 return (-1);
403 if ( this->gl_data->glXGetSwapIntervalMESA ) { 412 }
404 return this->gl_data->glXGetSwapIntervalMESA(); 413 break;
405 } else { 414 case SDL_GL_SWAP_CONTROL:
406 return(-1)/*(this->gl_config.swap_control > 0)*/; 415 if (this->gl_data->glXGetSwapIntervalMESA) {
407 } 416 return this->gl_data->glXGetSwapIntervalMESA ();
408 break; 417 } else {
409 default: 418 return (-1) /*(this->gl_config.swap_control > 0) */ ;
410 return(-1); 419 }
411 } 420 break;
412 421 default:
413 retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value); 422 return (-1);
414 423 }
415 return retval; 424
416 } 425 retval =
417 426 this->gl_data->glXGetConfig (GFX_Display, glx_visualinfo, glx_attrib,
418 void X11_GL_SwapBuffers(_THIS) 427 value);
419 { 428
420 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); 429 return retval;
430 }
431
432 void
433 X11_GL_SwapBuffers (_THIS)
434 {
435 this->gl_data->glXSwapBuffers (GFX_Display, SDL_Window);
421 } 436 }
422 437
423 #endif /* SDL_VIDEO_OPENGL_GLX */ 438 #endif /* SDL_VIDEO_OPENGL_GLX */
424 439
425 void X11_GL_UnloadLibrary(_THIS) 440 void
426 { 441 X11_GL_UnloadLibrary (_THIS)
427 #if SDL_VIDEO_OPENGL_GLX 442 {
428 if ( this->gl_config.driver_loaded ) { 443 #if SDL_VIDEO_OPENGL_GLX
429 444 if (this->gl_config.driver_loaded) {
430 SDL_UnloadObject(this->gl_config.dll_handle); 445
431 446 SDL_UnloadObject (this->gl_config.dll_handle);
432 this->gl_data->glXGetProcAddress = NULL; 447
433 this->gl_data->glXChooseVisual = NULL; 448 this->gl_data->glXGetProcAddress = NULL;
434 this->gl_data->glXCreateContext = NULL; 449 this->gl_data->glXChooseVisual = NULL;
435 this->gl_data->glXDestroyContext = NULL; 450 this->gl_data->glXCreateContext = NULL;
436 this->gl_data->glXMakeCurrent = NULL; 451 this->gl_data->glXDestroyContext = NULL;
437 this->gl_data->glXSwapBuffers = NULL; 452 this->gl_data->glXMakeCurrent = NULL;
438 this->gl_data->glXSwapIntervalSGI = NULL; 453 this->gl_data->glXSwapBuffers = NULL;
439 this->gl_data->glXSwapIntervalMESA = NULL; 454 this->gl_data->glXSwapIntervalSGI = NULL;
440 this->gl_data->glXGetSwapIntervalMESA = NULL; 455 this->gl_data->glXSwapIntervalMESA = NULL;
441 456 this->gl_data->glXGetSwapIntervalMESA = NULL;
442 this->gl_config.dll_handle = NULL; 457
443 this->gl_config.driver_loaded = 0; 458 this->gl_config.dll_handle = NULL;
444 } 459 this->gl_config.driver_loaded = 0;
460 }
445 #endif 461 #endif
446 } 462 }
447 463
448 #if SDL_VIDEO_OPENGL_GLX 464 #if SDL_VIDEO_OPENGL_GLX
449 465
450 /* Passing a NULL path means load pointers from the application */ 466 /* Passing a NULL path means load pointers from the application */
451 int X11_GL_LoadLibrary(_THIS, const char* path) 467 int
452 { 468 X11_GL_LoadLibrary (_THIS, const char *path)
453 void* handle = NULL; 469 {
454 470 void *handle = NULL;
455 if ( gl_active ) { 471
456 SDL_SetError("OpenGL context already created"); 472 if (gl_active) {
457 return -1; 473 SDL_SetError ("OpenGL context already created");
458 } 474 return -1;
459 475 }
460 if ( path == NULL ) { 476
461 path = SDL_getenv("SDL_VIDEO_GL_DRIVER"); 477 if (path == NULL) {
462 if ( path == NULL ) { 478 path = SDL_getenv ("SDL_VIDEO_GL_DRIVER");
463 path = DEFAULT_OPENGL; 479 if (path == NULL) {
464 } 480 path = DEFAULT_OPENGL;
465 } 481 }
466 482 }
467 handle = SDL_LoadObject(path); 483
468 if ( handle == NULL ) { 484 handle = SDL_LoadObject (path);
469 /* SDL_LoadObject() will call SDL_SetError() for us. */ 485 if (handle == NULL) {
470 return -1; 486 /* SDL_LoadObject() will call SDL_SetError() for us. */
471 } 487 return -1;
472 488 }
473 /* Unload the old driver and reset the pointers */ 489
474 X11_GL_UnloadLibrary(this); 490 /* Unload the old driver and reset the pointers */
475 491 X11_GL_UnloadLibrary (this);
476 /* Load new function pointers */ 492
477 this->gl_data->glXGetProcAddress = 493 /* Load new function pointers */
478 (void *(*)(const GLubyte *)) SDL_LoadFunction(handle, "glXGetProcAddressARB"); 494 this->gl_data->glXGetProcAddress =
479 this->gl_data->glXChooseVisual = 495 (void *(*)(const GLubyte *)) SDL_LoadFunction (handle,
480 (XVisualInfo *(*)(Display *, int, int *)) SDL_LoadFunction(handle, "glXChooseVisual"); 496 "glXGetProcAddressARB");
481 this->gl_data->glXCreateContext = 497 this->gl_data->glXChooseVisual =
482 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) SDL_LoadFunction(handle, "glXCreateContext"); 498 (XVisualInfo * (*)(Display *, int, int *)) SDL_LoadFunction (handle,
483 this->gl_data->glXDestroyContext = 499 "glXChooseVisual");
484 (void (*)(Display *, GLXContext)) SDL_LoadFunction(handle, "glXDestroyContext"); 500 this->gl_data->glXCreateContext =
485 this->gl_data->glXMakeCurrent = 501 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int))
486 (int (*)(Display *, GLXDrawable, GLXContext)) SDL_LoadFunction(handle, "glXMakeCurrent"); 502 SDL_LoadFunction (handle, "glXCreateContext");
487 this->gl_data->glXSwapBuffers = 503 this->gl_data->glXDestroyContext =
488 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers"); 504 (void (*)(Display *, GLXContext)) SDL_LoadFunction (handle,
489 this->gl_data->glXGetConfig = 505 "glXDestroyContext");
490 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig"); 506 this->gl_data->glXMakeCurrent =
491 this->gl_data->glXQueryExtensionsString = 507 (int (*)(Display *, GLXDrawable, GLXContext))
492 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString"); 508 SDL_LoadFunction (handle, "glXMakeCurrent");
493 this->gl_data->glXSwapIntervalSGI = 509 this->gl_data->glXSwapBuffers =
494 (int (*)(int)) SDL_LoadFunction(handle, "glXSwapIntervalSGI"); 510 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction (handle,
495 this->gl_data->glXSwapIntervalMESA = 511 "glXSwapBuffers");
496 (GLint (*)(unsigned)) SDL_LoadFunction(handle, "glXSwapIntervalMESA"); 512 this->gl_data->glXGetConfig =
497 this->gl_data->glXGetSwapIntervalMESA = 513 (int (*)(Display *, XVisualInfo *, int, int *))
498 (GLint (*)(void)) SDL_LoadFunction(handle, "glXGetSwapIntervalMESA"); 514 SDL_LoadFunction (handle, "glXGetConfig");
499 515 this->gl_data->glXQueryExtensionsString =
500 if ( (this->gl_data->glXChooseVisual == NULL) || 516 (const char *(*)(Display *, int)) SDL_LoadFunction (handle,
501 (this->gl_data->glXCreateContext == NULL) || 517 "glXQueryExtensionsString");
502 (this->gl_data->glXDestroyContext == NULL) || 518 this->gl_data->glXSwapIntervalSGI =
503 (this->gl_data->glXMakeCurrent == NULL) || 519 (int (*)(int)) SDL_LoadFunction (handle, "glXSwapIntervalSGI");
504 (this->gl_data->glXSwapBuffers == NULL) || 520 this->gl_data->glXSwapIntervalMESA =
505 (this->gl_data->glXGetConfig == NULL) || 521 (GLint (*)(unsigned)) SDL_LoadFunction (handle,
506 (this->gl_data->glXQueryExtensionsString == NULL)) { 522 "glXSwapIntervalMESA");
507 SDL_SetError("Could not retrieve OpenGL functions"); 523 this->gl_data->glXGetSwapIntervalMESA =
508 return -1; 524 (GLint (*)(void)) SDL_LoadFunction (handle, "glXGetSwapIntervalMESA");
509 } 525
510 526 if ((this->gl_data->glXChooseVisual == NULL) ||
511 this->gl_config.dll_handle = handle; 527 (this->gl_data->glXCreateContext == NULL) ||
512 this->gl_config.driver_loaded = 1; 528 (this->gl_data->glXDestroyContext == NULL) ||
513 if ( path ) { 529 (this->gl_data->glXMakeCurrent == NULL) ||
514 SDL_strlcpy(this->gl_config.driver_path, path, 530 (this->gl_data->glXSwapBuffers == NULL) ||
515 SDL_arraysize(this->gl_config.driver_path)); 531 (this->gl_data->glXGetConfig == NULL) ||
516 } else { 532 (this->gl_data->glXQueryExtensionsString == NULL)) {
517 *this->gl_config.driver_path = '\0'; 533 SDL_SetError ("Could not retrieve OpenGL functions");
518 } 534 return -1;
519 return 0; 535 }
520 } 536
521 537 this->gl_config.dll_handle = handle;
522 void *X11_GL_GetProcAddress(_THIS, const char* proc) 538 this->gl_config.driver_loaded = 1;
523 { 539 if (path) {
524 void* handle; 540 SDL_strlcpy (this->gl_config.driver_path, path,
525 541 SDL_arraysize (this->gl_config.driver_path));
526 handle = this->gl_config.dll_handle; 542 } else {
527 if ( this->gl_data->glXGetProcAddress ) { 543 *this->gl_config.driver_path = '\0';
528 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); 544 }
529 } 545 return 0;
530 return SDL_LoadFunction(handle, proc); 546 }
547
548 void *
549 X11_GL_GetProcAddress (_THIS, const char *proc)
550 {
551 void *handle;
552
553 handle = this->gl_config.dll_handle;
554 if (this->gl_data->glXGetProcAddress) {
555 return this->gl_data->glXGetProcAddress ((const GLubyte *) proc);
556 }
557 return SDL_LoadFunction (handle, proc);
531 } 558 }
532 559
533 #endif /* SDL_VIDEO_OPENGL_GLX */ 560 #endif /* SDL_VIDEO_OPENGL_GLX */
561 /* vi: set ts=4 sw=4 expandtab: */