comparison src/video/x11/SDL_x11gl.c @ 1361:19418e4422cb

New configure-based build system. Still work in progress, but much improved
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Feb 2006 10:11:48 +0000
parents c71e05b4dc2e
children c0a74f199ecf
comparison
equal deleted inserted replaced
1360:70a9cfb4cf1b 1361:19418e4422cb
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 #include "SDL_x11video.h" 23 #include "SDL_x11video.h"
24 #include "SDL_events_c.h" 24 #include "../../events/SDL_events_c.h"
25 #include "SDL_x11dga_c.h" 25 #include "SDL_x11dga_c.h"
26 #include "SDL_x11gl_c.h" 26 #include "SDL_x11gl_c.h"
27 27
28 #if defined(sgi) 28 #if defined(sgi)
29 /* IRIX doesn't have a GL library versioning system */ 29 /* IRIX doesn't have a GL library versioning system */
40 #define GLX_SAMPLES_ARB 100001 40 #define GLX_SAMPLES_ARB 100001
41 #endif 41 #endif
42 42
43 XVisualInfo *X11_GL_GetVisual(_THIS) 43 XVisualInfo *X11_GL_GetVisual(_THIS)
44 { 44 {
45 #ifdef HAVE_OPENGL_X11 45 #if SDL_VIDEO_OPENGL_GLX
46 /* 64 seems nice. */ 46 /* 64 seems nice. */
47 int attribs[64]; 47 int attribs[64];
48 int i; 48 int i;
49 49
50 /* load the gl driver from a default path */ 50 /* load the gl driver from a default path */
168 } 168 }
169 169
170 int X11_GL_CreateWindow(_THIS, int w, int h) 170 int X11_GL_CreateWindow(_THIS, int w, int h)
171 { 171 {
172 int retval; 172 int retval;
173 #ifdef HAVE_OPENGL_X11 173 #if SDL_VIDEO_OPENGL_GLX
174 XSetWindowAttributes attributes; 174 XSetWindowAttributes attributes;
175 unsigned long mask; 175 unsigned long mask;
176 unsigned long black; 176 unsigned long black;
177 177
178 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display, 178 black = (glx_visualinfo->visual == DefaultVisual(SDL_Display,
200 } 200 }
201 201
202 int X11_GL_CreateContext(_THIS) 202 int X11_GL_CreateContext(_THIS)
203 { 203 {
204 int retval; 204 int retval;
205 #ifdef HAVE_OPENGL_X11 205 #if SDL_VIDEO_OPENGL_GLX
206 /* We do this to create a clean separation between X and GLX errors. */ 206 /* We do this to create a clean separation between X and GLX errors. */
207 pXSync( SDL_Display, False ); 207 pXSync( SDL_Display, False );
208 glx_context = this->gl_data->glXCreateContext(GFX_Display, 208 glx_context = this->gl_data->glXCreateContext(GFX_Display,
209 glx_visualinfo, NULL, True); 209 glx_visualinfo, NULL, True);
210 pXSync( GFX_Display, False ); 210 pXSync( GFX_Display, False );
226 return(retval); 226 return(retval);
227 } 227 }
228 228
229 void X11_GL_Shutdown(_THIS) 229 void X11_GL_Shutdown(_THIS)
230 { 230 {
231 #ifdef HAVE_OPENGL_X11 231 #if SDL_VIDEO_OPENGL_GLX
232 /* Clean up OpenGL */ 232 /* Clean up OpenGL */
233 if( glx_context ) { 233 if( glx_context ) {
234 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL); 234 this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
235 235
236 if (glx_context != NULL) 236 if (glx_context != NULL)
237 this->gl_data->glXDestroyContext(GFX_Display, glx_context); 237 this->gl_data->glXDestroyContext(GFX_Display, glx_context);
238 238
239 glx_context = NULL; 239 glx_context = NULL;
240 } 240 }
241 gl_active = 0; 241 gl_active = 0;
242 #endif /* HAVE_OPENGL_X11 */ 242 #endif /* SDL_VIDEO_OPENGL_GLX */
243 } 243 }
244 244
245 #ifdef HAVE_OPENGL_X11 245 #if SDL_VIDEO_OPENGL_GLX
246 246
247 /* Make the current context active */ 247 /* Make the current context active */
248 int X11_GL_MakeCurrent(_THIS) 248 int X11_GL_MakeCurrent(_THIS)
249 { 249 {
250 int retval; 250 int retval;
329 void X11_GL_SwapBuffers(_THIS) 329 void X11_GL_SwapBuffers(_THIS)
330 { 330 {
331 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window); 331 this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
332 } 332 }
333 333
334 #endif /* HAVE_OPENGL_X11 */ 334 #endif /* SDL_VIDEO_OPENGL_GLX */
335 335
336 void X11_GL_UnloadLibrary(_THIS) 336 void X11_GL_UnloadLibrary(_THIS)
337 { 337 {
338 #ifdef HAVE_OPENGL_X11 338 #if SDL_VIDEO_OPENGL_GLX
339 if ( this->gl_config.driver_loaded ) { 339 if ( this->gl_config.driver_loaded ) {
340 340
341 /* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */
342 #ifdef USE_DLOPEN
343 dlclose(this->gl_config.dll_handle);
344 #else
345 SDL_UnloadObject(this->gl_config.dll_handle); 341 SDL_UnloadObject(this->gl_config.dll_handle);
346 #endif
347 342
348 this->gl_data->glXGetProcAddress = NULL; 343 this->gl_data->glXGetProcAddress = NULL;
349 this->gl_data->glXChooseVisual = NULL; 344 this->gl_data->glXChooseVisual = NULL;
350 this->gl_data->glXCreateContext = NULL; 345 this->gl_data->glXCreateContext = NULL;
351 this->gl_data->glXDestroyContext = NULL; 346 this->gl_data->glXDestroyContext = NULL;
356 this->gl_config.driver_loaded = 0; 351 this->gl_config.driver_loaded = 0;
357 } 352 }
358 #endif 353 #endif
359 } 354 }
360 355
361 #ifdef HAVE_OPENGL_X11 356 #if SDL_VIDEO_OPENGL_GLX
362
363 static void *do_dlsym(void *handle, const char *name)
364 {
365 /* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */
366 #ifdef USE_DLOPEN
367 return dlsym(handle, name);
368 #else
369 return SDL_LoadFunction(handle, name);
370 #endif
371 }
372
373 #if defined(__OpenBSD__) && !defined(__ELF__)
374 #define do_dlsym(x,y) do_dlsym(x, "_" y)
375 #endif
376 357
377 /* Passing a NULL path means load pointers from the application */ 358 /* Passing a NULL path means load pointers from the application */
378 int X11_GL_LoadLibrary(_THIS, const char* path) 359 int X11_GL_LoadLibrary(_THIS, const char* path)
379 { 360 {
380 void* handle = NULL; 361 void* handle = NULL;
389 if ( path == NULL ) { 370 if ( path == NULL ) {
390 path = DEFAULT_OPENGL; 371 path = DEFAULT_OPENGL;
391 } 372 }
392 } 373 }
393 374
394 /* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */ 375 handle = SDL_LoadObject(path);
395 #ifdef USE_DLOPEN 376 if ( handle == NULL ) {
396 { 377 /* SDL_LoadObject() will call SDL_SetError() for us. */
397 #ifdef RTLD_GLOBAL 378 return -1;
398 int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL; 379 }
399 #else
400 int dlopen_flags = RTLD_LAZY;
401 #endif
402 handle = dlopen(path, dlopen_flags);
403 if ( handle == NULL ) {
404 SDL_SetError("Could not load OpenGL library: %s", (const char *) dlerror());
405 return -1;
406 }
407 }
408 #else
409 handle = SDL_LoadObject(path);
410 if ( handle == NULL ) {
411 /* SDL_LoadObject() will call SDL_SetError() for us. */
412 return -1;
413 }
414 #endif
415
416 380
417 /* Unload the old driver and reset the pointers */ 381 /* Unload the old driver and reset the pointers */
418 X11_GL_UnloadLibrary(this); 382 X11_GL_UnloadLibrary(this);
419 383
420 /* Load new function pointers */ 384 /* Load new function pointers */
421 this->gl_data->glXGetProcAddress = 385 this->gl_data->glXGetProcAddress =
422 (void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB"); 386 (void *(*)(const GLubyte *)) SDL_LoadFunction(handle, "glXGetProcAddressARB");
423 this->gl_data->glXChooseVisual = 387 this->gl_data->glXChooseVisual =
424 (XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual"); 388 (XVisualInfo *(*)(Display *, int, int *)) SDL_LoadFunction(handle, "glXChooseVisual");
425 this->gl_data->glXCreateContext = 389 this->gl_data->glXCreateContext =
426 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext"); 390 (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) SDL_LoadFunction(handle, "glXCreateContext");
427 this->gl_data->glXDestroyContext = 391 this->gl_data->glXDestroyContext =
428 (void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext"); 392 (void (*)(Display *, GLXContext)) SDL_LoadFunction(handle, "glXDestroyContext");
429 this->gl_data->glXMakeCurrent = 393 this->gl_data->glXMakeCurrent =
430 (int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent"); 394 (int (*)(Display *, GLXDrawable, GLXContext)) SDL_LoadFunction(handle, "glXMakeCurrent");
431 this->gl_data->glXSwapBuffers = 395 this->gl_data->glXSwapBuffers =
432 (void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers"); 396 (void (*)(Display *, GLXDrawable)) SDL_LoadFunction(handle, "glXSwapBuffers");
433 this->gl_data->glXGetConfig = 397 this->gl_data->glXGetConfig =
434 (int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig"); 398 (int (*)(Display *, XVisualInfo *, int, int *)) SDL_LoadFunction(handle, "glXGetConfig");
435 this->gl_data->glXQueryExtensionsString = 399 this->gl_data->glXQueryExtensionsString =
436 (const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString"); 400 (const char *(*)(Display *, int)) SDL_LoadFunction(handle, "glXQueryExtensionsString");
437 401
438 402
439 if ( (this->gl_data->glXChooseVisual == NULL) || 403 if ( (this->gl_data->glXChooseVisual == NULL) ||
440 (this->gl_data->glXCreateContext == NULL) || 404 (this->gl_data->glXCreateContext == NULL) ||
441 (this->gl_data->glXDestroyContext == NULL) || 405 (this->gl_data->glXDestroyContext == NULL) ||
458 return 0; 422 return 0;
459 } 423 }
460 424
461 void *X11_GL_GetProcAddress(_THIS, const char* proc) 425 void *X11_GL_GetProcAddress(_THIS, const char* proc)
462 { 426 {
463 static char procname[1024];
464 void* handle; 427 void* handle;
465 void* retval;
466 428
467 handle = this->gl_config.dll_handle; 429 handle = this->gl_config.dll_handle;
468 if ( this->gl_data->glXGetProcAddress ) { 430 if ( this->gl_data->glXGetProcAddress ) {
469 return this->gl_data->glXGetProcAddress((const GLubyte *)proc); 431 return this->gl_data->glXGetProcAddress((const GLubyte *)proc);
470 } 432 }
471 #if defined(__OpenBSD__) && !defined(__ELF__) 433 return SDL_LoadFunction(handle, proc);
472 #undef do_dlsym 434 }
473 #endif 435
474 retval = do_dlsym(handle, proc); 436 #endif /* SDL_VIDEO_OPENGL_GLX */
475 if (!retval && SDL_strlen(proc) <= 1022) {
476 procname[0] = '_';
477 SDL_strcpy(procname + 1, proc);
478 retval = do_dlsym(handle, procname);
479 }
480 return retval;
481 }
482
483 #endif /* HAVE_OPENGL_X11 */