Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
authorRyan C. Gordon <icculus@icculus.org>
Wed, 23 Nov 2005 11:46:36 +0000
changeset 11912bd4cec0de63
parent 1190 173c063d4f55
child 1192 54aa9aa32327
Seperate glX from HAVE_OPENGL, for platforms that have both an X server and
a more official way to do OpenGL, explicitly check for glX on Mac OS X, and
use SDL_LoadObject for platforms that have glX but don't have dlopen().
configure.in
src/video/x11/SDL_x11gl.c
src/video/x11/SDL_x11gl_c.h
src/video/x11/SDL_x11video.c
     1.1 --- a/configure.in	Wed Nov 23 07:29:56 2005 +0000
     1.2 +++ b/configure.in	Wed Nov 23 11:46:36 2005 +0000
     1.3 @@ -1103,7 +1103,7 @@
     1.4                , enable_video_opengl=yes)
     1.5  
     1.6  dnl Find OpenGL
     1.7 -CheckOpenGL()
     1.8 +CheckOpenGLX11()
     1.9  {
    1.10      if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
    1.11          AC_MSG_CHECKING(for OpenGL (GLX) support)
    1.12 @@ -1118,7 +1118,7 @@
    1.13          ])
    1.14          AC_MSG_RESULT($video_opengl)
    1.15          if test x$video_opengl = xyes; then
    1.16 -            CFLAGS="$CFLAGS -DHAVE_OPENGL"
    1.17 +            CFLAGS="$CFLAGS -DHAVE_OPENGL -DHAVE_OPENGL_X11"
    1.18              if test x$have_loadso != xyes; then
    1.19                  AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl")
    1.20              fi
    1.21 @@ -2076,7 +2076,7 @@
    1.22          CheckAAlib
    1.23          CheckQtopia
    1.24          CheckPicoGUI
    1.25 -        CheckOpenGL
    1.26 +        CheckOpenGLX11
    1.27          CheckInputEvents
    1.28          CheckPTHREAD
    1.29          CheckSIGACTION
    1.30 @@ -2157,7 +2157,7 @@
    1.31          CheckDGA
    1.32          CheckSVGA
    1.33          CheckAAlib
    1.34 -        CheckOpenGL
    1.35 +        CheckOpenGLX11
    1.36          CheckPTHREAD
    1.37          CheckSIGACTION
    1.38          CheckRPATH
    1.39 @@ -2203,7 +2203,7 @@
    1.40          CheckDGA
    1.41          CheckSVGA
    1.42          CheckAAlib
    1.43 -        CheckOpenGL
    1.44 +        CheckOpenGLX11
    1.45          CheckPTHREAD
    1.46          CheckSIGACTION
    1.47          CheckUSBHID
    1.48 @@ -2242,7 +2242,7 @@
    1.49          CheckX11
    1.50          CheckAAlib
    1.51  	CheckWscons
    1.52 -        CheckOpenGL
    1.53 +        CheckOpenGLX11
    1.54          CheckPTHREAD
    1.55          CheckSIGACTION
    1.56          CheckUSBHID
    1.57 @@ -2284,7 +2284,7 @@
    1.58          CheckNAS
    1.59          CheckX11
    1.60          CheckAAlib
    1.61 -        CheckOpenGL
    1.62 +        CheckOpenGLX11
    1.63          CheckPTHREAD
    1.64          CheckSIGACTION
    1.65          CheckUSBHID
    1.66 @@ -2327,7 +2327,7 @@
    1.67          CheckNAS
    1.68          CheckX11
    1.69          CheckAAlib
    1.70 -        CheckOpenGL
    1.71 +        CheckOpenGLX11
    1.72          CheckPTHREAD
    1.73          CheckSIGACTION
    1.74          CheckRPATH
    1.75 @@ -2370,7 +2370,7 @@
    1.76          CheckNAS
    1.77          CheckX11
    1.78          CheckAAlib
    1.79 -        CheckOpenGL
    1.80 +        CheckOpenGLX11
    1.81          CheckPTHREAD
    1.82          CheckSIGACTION
    1.83          CheckRPATH
    1.84 @@ -2410,7 +2410,7 @@
    1.85          CheckNAS
    1.86          CheckX11
    1.87          CheckAAlib
    1.88 -        CheckOpenGL
    1.89 +        CheckOpenGLX11
    1.90          CheckPTHREAD
    1.91          CheckSIGACTION
    1.92          # We use the dmedia audio API, not the Sun audio API
    1.93 @@ -2461,7 +2461,7 @@
    1.94          CheckX11
    1.95          CheckGGI
    1.96          CheckAAlib
    1.97 -        CheckOpenGL
    1.98 +        CheckOpenGLX11
    1.99          CheckPTHREAD
   1.100          CheckSIGACTION
   1.101          # Set up files for the audio library
   1.102 @@ -2501,7 +2501,7 @@
   1.103          CheckX11
   1.104          CheckGGI
   1.105          CheckAAlib
   1.106 -        CheckOpenGL
   1.107 +        CheckOpenGLX11
   1.108          CheckPTHREAD
   1.109          CheckSIGACTION
   1.110          # Set up files for the audio library
   1.111 @@ -2538,7 +2538,7 @@
   1.112          CheckX11
   1.113          CheckGGI
   1.114          CheckAAlib
   1.115 -        CheckOpenGL
   1.116 +        CheckOpenGLX11
   1.117          CheckPTHREAD
   1.118          CheckSIGACTION
   1.119          # Set up files for the audio library
   1.120 @@ -2578,7 +2578,7 @@
   1.121          CheckNAS
   1.122          CheckPHOTON
   1.123          CheckX11
   1.124 -        CheckOpenGL
   1.125 +        CheckOpenGLX11
   1.126          CheckPTHREAD
   1.127          CheckSIGACTION
   1.128          # Set up files for the audio library
   1.129 @@ -2771,6 +2771,7 @@
   1.130          CheckCARBON
   1.131          CheckX11
   1.132          CheckMacGL
   1.133 +        CheckOpenGLX11
   1.134          CheckPTHREAD
   1.135          CheckSIGACTION
   1.136          CheckAltivec
     2.1 --- a/src/video/x11/SDL_x11gl.c	Wed Nov 23 07:29:56 2005 +0000
     2.2 +++ b/src/video/x11/SDL_x11gl.c	Wed Nov 23 11:46:36 2005 +0000
     2.3 @@ -37,6 +37,8 @@
     2.4  #if defined(sgi)
     2.5  /* IRIX doesn't have a GL library versioning system */
     2.6  #define DEFAULT_OPENGL	"libGL.so"
     2.7 +#elif defined(MACOSX)
     2.8 +#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
     2.9  #else
    2.10  #define DEFAULT_OPENGL	"libGL.so.1"
    2.11  #endif
    2.12 @@ -50,7 +52,7 @@
    2.13  /* return the preferred visual to use for openGL graphics */
    2.14  XVisualInfo *X11_GL_GetVisual(_THIS)
    2.15  {
    2.16 -#ifdef HAVE_OPENGL
    2.17 +#ifdef HAVE_OPENGL_X11
    2.18  	/* 64 seems nice. */
    2.19  	int attribs[64];
    2.20  	int i;
    2.21 @@ -175,7 +177,7 @@
    2.22  int X11_GL_CreateWindow(_THIS, int w, int h)
    2.23  {
    2.24  	int retval;
    2.25 -#ifdef HAVE_OPENGL
    2.26 +#ifdef HAVE_OPENGL_X11
    2.27  	XSetWindowAttributes attributes;
    2.28  	unsigned long mask;
    2.29  	unsigned long black;
    2.30 @@ -207,7 +209,7 @@
    2.31  int X11_GL_CreateContext(_THIS)
    2.32  {
    2.33  	int retval;
    2.34 -#ifdef HAVE_OPENGL
    2.35 +#ifdef HAVE_OPENGL_X11
    2.36  	/* We do this to create a clean separation between X and GLX errors. */
    2.37  	pXSync( SDL_Display, False );
    2.38  	glx_context = this->gl_data->glXCreateContext(GFX_Display, 
    2.39 @@ -233,7 +235,7 @@
    2.40  
    2.41  void X11_GL_Shutdown(_THIS)
    2.42  {
    2.43 -#ifdef HAVE_OPENGL
    2.44 +#ifdef HAVE_OPENGL_X11
    2.45  	/* Clean up OpenGL */
    2.46  	if( glx_context ) {
    2.47  		this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
    2.48 @@ -247,10 +249,10 @@
    2.49  		glx_context = NULL;
    2.50  	}
    2.51  	gl_active = 0;
    2.52 -#endif /* HAVE_OPENGL */
    2.53 +#endif /* HAVE_OPENGL_X11 */
    2.54  }
    2.55  
    2.56 -#ifdef HAVE_OPENGL
    2.57 +#ifdef HAVE_OPENGL_X11
    2.58  
    2.59  static int ExtensionSupported(const char *extension)
    2.60  {
    2.61 @@ -395,13 +397,19 @@
    2.62  	this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
    2.63  }
    2.64  
    2.65 -#endif /* HAVE_OPENGL */
    2.66 +#endif /* HAVE_OPENGL_X11 */
    2.67  
    2.68  void X11_GL_UnloadLibrary(_THIS)
    2.69  {
    2.70 -#ifdef HAVE_OPENGL
    2.71 +#ifdef HAVE_OPENGL_X11
    2.72  	if ( this->gl_config.driver_loaded ) {
    2.73 +
    2.74 +		/* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */
    2.75 +		#ifdef USE_DLOPEN
    2.76  		dlclose(this->gl_config.dll_handle);
    2.77 +		#else
    2.78 +		SDL_UnloadObject(this->gl_config.dll_handle);
    2.79 +		#endif
    2.80  
    2.81  		this->gl_data->glXGetProcAddress = NULL;
    2.82  		this->gl_data->glXChooseVisual = NULL;
    2.83 @@ -416,16 +424,26 @@
    2.84  #endif
    2.85  }
    2.86  
    2.87 -#ifdef HAVE_OPENGL
    2.88 +#ifdef HAVE_OPENGL_X11
    2.89  
    2.90 -/* If this is wrong, please put some #ifdefs for your platform! */
    2.91 -#define DEFAULT_GL_DRIVER_PATH "libGL.so.1"
    2.92 +static void *do_dlsym(void *handle, const char *name)
    2.93 +{
    2.94 +	/* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */
    2.95 +#ifdef USE_DLOPEN
    2.96 +	return dlsym(handle, name);
    2.97 +#else
    2.98 +	return SDL_LoadFunction(handle, name);
    2.99 +#endif
   2.100 +}
   2.101 +
   2.102 +#if defined(__OpenBSD__) && !defined(__ELF__)
   2.103 +#define do_dlsym(x,y) do_dlsym(x, "_" y)
   2.104 +#endif
   2.105  
   2.106  /* Passing a NULL path means load pointers from the application */
   2.107  int X11_GL_LoadLibrary(_THIS, const char* path) 
   2.108  {
   2.109 -	void* handle;
   2.110 -	int dlopen_flags;
   2.111 +	void* handle = NULL;
   2.112  
   2.113  	if ( gl_active ) {
   2.114  		SDL_SetError("OpenGL context already created");
   2.115 @@ -433,24 +451,26 @@
   2.116  	}
   2.117  
   2.118  	if ( path == NULL ) {
   2.119 -		path = DEFAULT_GL_DRIVER_PATH;
   2.120 -	}
   2.121 -
   2.122 -#ifdef RTLD_GLOBAL
   2.123 -	dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
   2.124 -#else
   2.125 -	dlopen_flags = RTLD_LAZY;
   2.126 -#endif
   2.127 -	handle = dlopen(path, dlopen_flags);
   2.128 -	/* Catch the case where the application isn't linked with GL */
   2.129 -	if ( (dlsym(handle, "glXChooseVisual") == NULL) && (path == NULL) ) {
   2.130 -		dlclose(handle);
   2.131  		path = getenv("SDL_VIDEO_GL_DRIVER");
   2.132  		if ( path == NULL ) {
   2.133  			path = DEFAULT_OPENGL;
   2.134  		}
   2.135 +	}
   2.136 +
   2.137 +	/* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */
   2.138 +	#ifdef USE_DLOPEN
   2.139 +	{
   2.140 +		#ifdef RTLD_GLOBAL
   2.141 +			int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
   2.142 +		#else
   2.143 +			int dlopen_flags = RTLD_LAZY;
   2.144 +		#endif
   2.145  		handle = dlopen(path, dlopen_flags);
   2.146  	}
   2.147 +	#else
   2.148 +		handle = SDL_LoadObject(path);
   2.149 +	#endif
   2.150 +
   2.151  	if ( handle == NULL ) {
   2.152  		SDL_SetError("Could not load OpenGL library");
   2.153  		return -1;
   2.154 @@ -461,25 +481,25 @@
   2.155  
   2.156  	/* Load new function pointers */
   2.157  	this->gl_data->glXGetProcAddress =
   2.158 -		(void *(*)(const GLubyte *)) dlsym(handle, "glXGetProcAddressARB");
   2.159 +		(void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB");
   2.160  	this->gl_data->glXChooseVisual =
   2.161 -		(XVisualInfo *(*)(Display *, int, int *)) dlsym(handle, "glXChooseVisual");
   2.162 +		(XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual");
   2.163  	this->gl_data->glXCreateContext =
   2.164 -		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) dlsym(handle, "glXCreateContext");
   2.165 +		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext");
   2.166  	this->gl_data->glXDestroyContext =
   2.167 -		(void (*)(Display *, GLXContext)) dlsym(handle, "glXDestroyContext");
   2.168 +		(void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext");
   2.169  	this->gl_data->glXMakeCurrent =
   2.170 -		(int (*)(Display *, GLXDrawable, GLXContext)) dlsym(handle, "glXMakeCurrent");
   2.171 +		(int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent");
   2.172  	this->gl_data->glXSwapBuffers =
   2.173 -		(void (*)(Display *, GLXDrawable)) dlsym(handle, "glXSwapBuffers");
   2.174 +		(void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers");
   2.175  	this->gl_data->glXGetConfig =
   2.176 -		(int (*)(Display *, XVisualInfo *, int, int *)) dlsym(handle, "glXGetConfig");
   2.177 +		(int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig");
   2.178  	this->gl_data->glXQueryExtensionsString =
   2.179 -		(const char *(*)(Display *, int)) dlsym(handle, "glXQueryExtensionsString");
   2.180 +		(const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
   2.181  	
   2.182  	/* We don't compare below for this in case we're not using Mesa. */
   2.183  	this->gl_data->glXReleaseBuffersMESA =
   2.184 -		(void (*)(Display *, GLXDrawable)) dlsym( handle, "glXReleaseBuffersMESA" );
   2.185 +		(void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" );
   2.186  	
   2.187  	
   2.188  	if ( (this->gl_data->glXChooseVisual == NULL) || 
   2.189 @@ -515,15 +535,15 @@
   2.190  		return this->gl_data->glXGetProcAddress(proc);
   2.191  	}
   2.192  #if defined(__OpenBSD__) && !defined(__ELF__)
   2.193 -#undef dlsym(x,y);
   2.194 +#undef do_dlsym
   2.195  #endif
   2.196 -	retval = dlsym(handle, proc);
   2.197 +	retval = do_dlsym(handle, proc);
   2.198  	if (!retval && strlen(proc) <= 1022) {
   2.199  		procname[0] = '_';
   2.200  		strcpy(procname + 1, proc);
   2.201 -		retval = dlsym(handle, procname);
   2.202 +		retval = do_dlsym(handle, procname);
   2.203  	}
   2.204  	return retval;
   2.205  }
   2.206  
   2.207 -#endif /* HAVE_OPENGL */
   2.208 +#endif /* HAVE_OPENGL_X11 */
     3.1 --- a/src/video/x11/SDL_x11gl_c.h	Wed Nov 23 07:29:56 2005 +0000
     3.2 +++ b/src/video/x11/SDL_x11gl_c.h	Wed Nov 23 11:46:36 2005 +0000
     3.3 @@ -25,19 +25,21 @@
     3.4   "@(#) $Id$";
     3.5  #endif
     3.6  
     3.7 -#ifdef HAVE_OPENGL
     3.8 +#ifdef HAVE_OPENGL_X11
     3.9  #include <GL/glx.h>
    3.10 +#ifdef USE_DLOPEN
    3.11  #include <dlfcn.h>
    3.12 -#if defined(__OpenBSD__) && !defined(__ELF__)
    3.13 -#define dlsym(x,y) dlsym(x, "_" y)
    3.14 +#else
    3.15 +#include "SDL_loadso.h"
    3.16  #endif
    3.17  #endif
    3.18 +
    3.19  #include "SDL_sysvideo.h"
    3.20  
    3.21  struct SDL_PrivateGLData {
    3.22      int gl_active; /* to stop switching drivers while we have a valid context */
    3.23  
    3.24 -#ifdef HAVE_OPENGL
    3.25 +#ifdef HAVE_OPENGL_X11
    3.26      GLXContext glx_context;	/* Current GL context */
    3.27      XVisualInfo* glx_visualinfo; /* XVisualInfo* returned by glXChooseVisual */
    3.28  
    3.29 @@ -82,7 +84,7 @@
    3.30  	      int screen);
    3.31  
    3.32      
    3.33 -#endif /* HAVE_OPENGL */
    3.34 +#endif /* HAVE_OPENGL_X11 */
    3.35  };
    3.36  
    3.37  /* Old variable names */
    3.38 @@ -95,7 +97,7 @@
    3.39  extern int X11_GL_CreateWindow(_THIS, int w, int h);
    3.40  extern int X11_GL_CreateContext(_THIS);
    3.41  extern void X11_GL_Shutdown(_THIS);
    3.42 -#ifdef HAVE_OPENGL
    3.43 +#ifdef HAVE_OPENGL_X11
    3.44  extern int X11_GL_MakeCurrent(_THIS);
    3.45  extern int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
    3.46  extern void X11_GL_SwapBuffers(_THIS);
     4.1 --- a/src/video/x11/SDL_x11video.c	Wed Nov 23 07:29:56 2005 +0000
     4.2 +++ b/src/video/x11/SDL_x11video.c	Wed Nov 23 11:46:36 2005 +0000
     4.3 @@ -166,7 +166,7 @@
     4.4  		device->GetGamma = X11_GetVidModeGamma;
     4.5  		device->SetGammaRamp = X11_SetGammaRamp;
     4.6  		device->GetGammaRamp = NULL;
     4.7 -#ifdef HAVE_OPENGL
     4.8 +#ifdef HAVE_OPENGL_X11
     4.9  		device->GL_LoadLibrary = X11_GL_LoadLibrary;
    4.10  		device->GL_GetProcAddress = X11_GL_GetProcAddress;
    4.11  		device->GL_GetAttribute = X11_GL_GetAttribute;