src/video/x11/SDL_x11gl.c
changeset 1191 2bd4cec0de63
parent 1182 e8e8dcb68e7a
child 1196 b81f54c3963f
     1.1 --- a/src/video/x11/SDL_x11gl.c	Wed Nov 23 07:29:56 2005 +0000
     1.2 +++ b/src/video/x11/SDL_x11gl.c	Wed Nov 23 11:46:36 2005 +0000
     1.3 @@ -37,6 +37,8 @@
     1.4  #if defined(sgi)
     1.5  /* IRIX doesn't have a GL library versioning system */
     1.6  #define DEFAULT_OPENGL	"libGL.so"
     1.7 +#elif defined(MACOSX)
     1.8 +#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
     1.9  #else
    1.10  #define DEFAULT_OPENGL	"libGL.so.1"
    1.11  #endif
    1.12 @@ -50,7 +52,7 @@
    1.13  /* return the preferred visual to use for openGL graphics */
    1.14  XVisualInfo *X11_GL_GetVisual(_THIS)
    1.15  {
    1.16 -#ifdef HAVE_OPENGL
    1.17 +#ifdef HAVE_OPENGL_X11
    1.18  	/* 64 seems nice. */
    1.19  	int attribs[64];
    1.20  	int i;
    1.21 @@ -175,7 +177,7 @@
    1.22  int X11_GL_CreateWindow(_THIS, int w, int h)
    1.23  {
    1.24  	int retval;
    1.25 -#ifdef HAVE_OPENGL
    1.26 +#ifdef HAVE_OPENGL_X11
    1.27  	XSetWindowAttributes attributes;
    1.28  	unsigned long mask;
    1.29  	unsigned long black;
    1.30 @@ -207,7 +209,7 @@
    1.31  int X11_GL_CreateContext(_THIS)
    1.32  {
    1.33  	int retval;
    1.34 -#ifdef HAVE_OPENGL
    1.35 +#ifdef HAVE_OPENGL_X11
    1.36  	/* We do this to create a clean separation between X and GLX errors. */
    1.37  	pXSync( SDL_Display, False );
    1.38  	glx_context = this->gl_data->glXCreateContext(GFX_Display, 
    1.39 @@ -233,7 +235,7 @@
    1.40  
    1.41  void X11_GL_Shutdown(_THIS)
    1.42  {
    1.43 -#ifdef HAVE_OPENGL
    1.44 +#ifdef HAVE_OPENGL_X11
    1.45  	/* Clean up OpenGL */
    1.46  	if( glx_context ) {
    1.47  		this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
    1.48 @@ -247,10 +249,10 @@
    1.49  		glx_context = NULL;
    1.50  	}
    1.51  	gl_active = 0;
    1.52 -#endif /* HAVE_OPENGL */
    1.53 +#endif /* HAVE_OPENGL_X11 */
    1.54  }
    1.55  
    1.56 -#ifdef HAVE_OPENGL
    1.57 +#ifdef HAVE_OPENGL_X11
    1.58  
    1.59  static int ExtensionSupported(const char *extension)
    1.60  {
    1.61 @@ -395,13 +397,19 @@
    1.62  	this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
    1.63  }
    1.64  
    1.65 -#endif /* HAVE_OPENGL */
    1.66 +#endif /* HAVE_OPENGL_X11 */
    1.67  
    1.68  void X11_GL_UnloadLibrary(_THIS)
    1.69  {
    1.70 -#ifdef HAVE_OPENGL
    1.71 +#ifdef HAVE_OPENGL_X11
    1.72  	if ( this->gl_config.driver_loaded ) {
    1.73 +
    1.74 +		/* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */
    1.75 +		#ifdef USE_DLOPEN
    1.76  		dlclose(this->gl_config.dll_handle);
    1.77 +		#else
    1.78 +		SDL_UnloadObject(this->gl_config.dll_handle);
    1.79 +		#endif
    1.80  
    1.81  		this->gl_data->glXGetProcAddress = NULL;
    1.82  		this->gl_data->glXChooseVisual = NULL;
    1.83 @@ -416,16 +424,26 @@
    1.84  #endif
    1.85  }
    1.86  
    1.87 -#ifdef HAVE_OPENGL
    1.88 +#ifdef HAVE_OPENGL_X11
    1.89  
    1.90 -/* If this is wrong, please put some #ifdefs for your platform! */
    1.91 -#define DEFAULT_GL_DRIVER_PATH "libGL.so.1"
    1.92 +static void *do_dlsym(void *handle, const char *name)
    1.93 +{
    1.94 +	/* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */
    1.95 +#ifdef USE_DLOPEN
    1.96 +	return dlsym(handle, name);
    1.97 +#else
    1.98 +	return SDL_LoadFunction(handle, name);
    1.99 +#endif
   1.100 +}
   1.101 +
   1.102 +#if defined(__OpenBSD__) && !defined(__ELF__)
   1.103 +#define do_dlsym(x,y) do_dlsym(x, "_" y)
   1.104 +#endif
   1.105  
   1.106  /* Passing a NULL path means load pointers from the application */
   1.107  int X11_GL_LoadLibrary(_THIS, const char* path) 
   1.108  {
   1.109 -	void* handle;
   1.110 -	int dlopen_flags;
   1.111 +	void* handle = NULL;
   1.112  
   1.113  	if ( gl_active ) {
   1.114  		SDL_SetError("OpenGL context already created");
   1.115 @@ -433,24 +451,26 @@
   1.116  	}
   1.117  
   1.118  	if ( path == NULL ) {
   1.119 -		path = DEFAULT_GL_DRIVER_PATH;
   1.120 -	}
   1.121 -
   1.122 -#ifdef RTLD_GLOBAL
   1.123 -	dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
   1.124 -#else
   1.125 -	dlopen_flags = RTLD_LAZY;
   1.126 -#endif
   1.127 -	handle = dlopen(path, dlopen_flags);
   1.128 -	/* Catch the case where the application isn't linked with GL */
   1.129 -	if ( (dlsym(handle, "glXChooseVisual") == NULL) && (path == NULL) ) {
   1.130 -		dlclose(handle);
   1.131  		path = getenv("SDL_VIDEO_GL_DRIVER");
   1.132  		if ( path == NULL ) {
   1.133  			path = DEFAULT_OPENGL;
   1.134  		}
   1.135 +	}
   1.136 +
   1.137 +	/* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */
   1.138 +	#ifdef USE_DLOPEN
   1.139 +	{
   1.140 +		#ifdef RTLD_GLOBAL
   1.141 +			int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
   1.142 +		#else
   1.143 +			int dlopen_flags = RTLD_LAZY;
   1.144 +		#endif
   1.145  		handle = dlopen(path, dlopen_flags);
   1.146  	}
   1.147 +	#else
   1.148 +		handle = SDL_LoadObject(path);
   1.149 +	#endif
   1.150 +
   1.151  	if ( handle == NULL ) {
   1.152  		SDL_SetError("Could not load OpenGL library");
   1.153  		return -1;
   1.154 @@ -461,25 +481,25 @@
   1.155  
   1.156  	/* Load new function pointers */
   1.157  	this->gl_data->glXGetProcAddress =
   1.158 -		(void *(*)(const GLubyte *)) dlsym(handle, "glXGetProcAddressARB");
   1.159 +		(void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB");
   1.160  	this->gl_data->glXChooseVisual =
   1.161 -		(XVisualInfo *(*)(Display *, int, int *)) dlsym(handle, "glXChooseVisual");
   1.162 +		(XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual");
   1.163  	this->gl_data->glXCreateContext =
   1.164 -		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) dlsym(handle, "glXCreateContext");
   1.165 +		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext");
   1.166  	this->gl_data->glXDestroyContext =
   1.167 -		(void (*)(Display *, GLXContext)) dlsym(handle, "glXDestroyContext");
   1.168 +		(void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext");
   1.169  	this->gl_data->glXMakeCurrent =
   1.170 -		(int (*)(Display *, GLXDrawable, GLXContext)) dlsym(handle, "glXMakeCurrent");
   1.171 +		(int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent");
   1.172  	this->gl_data->glXSwapBuffers =
   1.173 -		(void (*)(Display *, GLXDrawable)) dlsym(handle, "glXSwapBuffers");
   1.174 +		(void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers");
   1.175  	this->gl_data->glXGetConfig =
   1.176 -		(int (*)(Display *, XVisualInfo *, int, int *)) dlsym(handle, "glXGetConfig");
   1.177 +		(int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig");
   1.178  	this->gl_data->glXQueryExtensionsString =
   1.179 -		(const char *(*)(Display *, int)) dlsym(handle, "glXQueryExtensionsString");
   1.180 +		(const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
   1.181  	
   1.182  	/* We don't compare below for this in case we're not using Mesa. */
   1.183  	this->gl_data->glXReleaseBuffersMESA =
   1.184 -		(void (*)(Display *, GLXDrawable)) dlsym( handle, "glXReleaseBuffersMESA" );
   1.185 +		(void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" );
   1.186  	
   1.187  	
   1.188  	if ( (this->gl_data->glXChooseVisual == NULL) || 
   1.189 @@ -515,15 +535,15 @@
   1.190  		return this->gl_data->glXGetProcAddress(proc);
   1.191  	}
   1.192  #if defined(__OpenBSD__) && !defined(__ELF__)
   1.193 -#undef dlsym(x,y);
   1.194 +#undef do_dlsym
   1.195  #endif
   1.196 -	retval = dlsym(handle, proc);
   1.197 +	retval = do_dlsym(handle, proc);
   1.198  	if (!retval && strlen(proc) <= 1022) {
   1.199  		procname[0] = '_';
   1.200  		strcpy(procname + 1, proc);
   1.201 -		retval = dlsym(handle, procname);
   1.202 +		retval = do_dlsym(handle, procname);
   1.203  	}
   1.204  	return retval;
   1.205  }
   1.206  
   1.207 -#endif /* HAVE_OPENGL */
   1.208 +#endif /* HAVE_OPENGL_X11 */