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 1191 2bd4cec0de63
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
--- a/configure.in	Wed Nov 23 07:29:56 2005 +0000
+++ b/configure.in	Wed Nov 23 11:46:36 2005 +0000
@@ -1103,7 +1103,7 @@
               , enable_video_opengl=yes)
 
 dnl Find OpenGL
-CheckOpenGL()
+CheckOpenGLX11()
 {
     if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
         AC_MSG_CHECKING(for OpenGL (GLX) support)
@@ -1118,7 +1118,7 @@
         ])
         AC_MSG_RESULT($video_opengl)
         if test x$video_opengl = xyes; then
-            CFLAGS="$CFLAGS -DHAVE_OPENGL"
+            CFLAGS="$CFLAGS -DHAVE_OPENGL -DHAVE_OPENGL_X11"
             if test x$have_loadso != xyes; then
                 AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl")
             fi
@@ -2076,7 +2076,7 @@
         CheckAAlib
         CheckQtopia
         CheckPicoGUI
-        CheckOpenGL
+        CheckOpenGLX11
         CheckInputEvents
         CheckPTHREAD
         CheckSIGACTION
@@ -2157,7 +2157,7 @@
         CheckDGA
         CheckSVGA
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckRPATH
@@ -2203,7 +2203,7 @@
         CheckDGA
         CheckSVGA
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckUSBHID
@@ -2242,7 +2242,7 @@
         CheckX11
         CheckAAlib
 	CheckWscons
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckUSBHID
@@ -2284,7 +2284,7 @@
         CheckNAS
         CheckX11
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckUSBHID
@@ -2327,7 +2327,7 @@
         CheckNAS
         CheckX11
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckRPATH
@@ -2370,7 +2370,7 @@
         CheckNAS
         CheckX11
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckRPATH
@@ -2410,7 +2410,7 @@
         CheckNAS
         CheckX11
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         # We use the dmedia audio API, not the Sun audio API
@@ -2461,7 +2461,7 @@
         CheckX11
         CheckGGI
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         # Set up files for the audio library
@@ -2501,7 +2501,7 @@
         CheckX11
         CheckGGI
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         # Set up files for the audio library
@@ -2538,7 +2538,7 @@
         CheckX11
         CheckGGI
         CheckAAlib
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         # Set up files for the audio library
@@ -2578,7 +2578,7 @@
         CheckNAS
         CheckPHOTON
         CheckX11
-        CheckOpenGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         # Set up files for the audio library
@@ -2771,6 +2771,7 @@
         CheckCARBON
         CheckX11
         CheckMacGL
+        CheckOpenGLX11
         CheckPTHREAD
         CheckSIGACTION
         CheckAltivec
--- a/src/video/x11/SDL_x11gl.c	Wed Nov 23 07:29:56 2005 +0000
+++ b/src/video/x11/SDL_x11gl.c	Wed Nov 23 11:46:36 2005 +0000
@@ -37,6 +37,8 @@
 #if defined(sgi)
 /* IRIX doesn't have a GL library versioning system */
 #define DEFAULT_OPENGL	"libGL.so"
+#elif defined(MACOSX)
+#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
 #else
 #define DEFAULT_OPENGL	"libGL.so.1"
 #endif
@@ -50,7 +52,7 @@
 /* return the preferred visual to use for openGL graphics */
 XVisualInfo *X11_GL_GetVisual(_THIS)
 {
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 	/* 64 seems nice. */
 	int attribs[64];
 	int i;
@@ -175,7 +177,7 @@
 int X11_GL_CreateWindow(_THIS, int w, int h)
 {
 	int retval;
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 	XSetWindowAttributes attributes;
 	unsigned long mask;
 	unsigned long black;
@@ -207,7 +209,7 @@
 int X11_GL_CreateContext(_THIS)
 {
 	int retval;
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 	/* We do this to create a clean separation between X and GLX errors. */
 	pXSync( SDL_Display, False );
 	glx_context = this->gl_data->glXCreateContext(GFX_Display, 
@@ -233,7 +235,7 @@
 
 void X11_GL_Shutdown(_THIS)
 {
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 	/* Clean up OpenGL */
 	if( glx_context ) {
 		this->gl_data->glXMakeCurrent(GFX_Display, None, NULL);
@@ -247,10 +249,10 @@
 		glx_context = NULL;
 	}
 	gl_active = 0;
-#endif /* HAVE_OPENGL */
+#endif /* HAVE_OPENGL_X11 */
 }
 
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 
 static int ExtensionSupported(const char *extension)
 {
@@ -395,13 +397,19 @@
 	this->gl_data->glXSwapBuffers(GFX_Display, SDL_Window);
 }
 
-#endif /* HAVE_OPENGL */
+#endif /* HAVE_OPENGL_X11 */
 
 void X11_GL_UnloadLibrary(_THIS)
 {
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 	if ( this->gl_config.driver_loaded ) {
+
+		/* !!! FIXME: Can we just use SDL_UnloadObject() everywhere? */
+		#ifdef USE_DLOPEN
 		dlclose(this->gl_config.dll_handle);
+		#else
+		SDL_UnloadObject(this->gl_config.dll_handle);
+		#endif
 
 		this->gl_data->glXGetProcAddress = NULL;
 		this->gl_data->glXChooseVisual = NULL;
@@ -416,16 +424,26 @@
 #endif
 }
 
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 
-/* If this is wrong, please put some #ifdefs for your platform! */
-#define DEFAULT_GL_DRIVER_PATH "libGL.so.1"
+static void *do_dlsym(void *handle, const char *name)
+{
+	/* !!! FIXME: Can we just use SDL_LoadFunction() everywhere? */
+#ifdef USE_DLOPEN
+	return dlsym(handle, name);
+#else
+	return SDL_LoadFunction(handle, name);
+#endif
+}
+
+#if defined(__OpenBSD__) && !defined(__ELF__)
+#define do_dlsym(x,y) do_dlsym(x, "_" y)
+#endif
 
 /* Passing a NULL path means load pointers from the application */
 int X11_GL_LoadLibrary(_THIS, const char* path) 
 {
-	void* handle;
-	int dlopen_flags;
+	void* handle = NULL;
 
 	if ( gl_active ) {
 		SDL_SetError("OpenGL context already created");
@@ -433,24 +451,26 @@
 	}
 
 	if ( path == NULL ) {
-		path = DEFAULT_GL_DRIVER_PATH;
-	}
-
-#ifdef RTLD_GLOBAL
-	dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
-#else
-	dlopen_flags = RTLD_LAZY;
-#endif
-	handle = dlopen(path, dlopen_flags);
-	/* Catch the case where the application isn't linked with GL */
-	if ( (dlsym(handle, "glXChooseVisual") == NULL) && (path == NULL) ) {
-		dlclose(handle);
 		path = getenv("SDL_VIDEO_GL_DRIVER");
 		if ( path == NULL ) {
 			path = DEFAULT_OPENGL;
 		}
+	}
+
+	/* !!! FIXME: Can we just use SDL_LoadObject() everywhere? */
+	#ifdef USE_DLOPEN
+	{
+		#ifdef RTLD_GLOBAL
+			int dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
+		#else
+			int dlopen_flags = RTLD_LAZY;
+		#endif
 		handle = dlopen(path, dlopen_flags);
 	}
+	#else
+		handle = SDL_LoadObject(path);
+	#endif
+
 	if ( handle == NULL ) {
 		SDL_SetError("Could not load OpenGL library");
 		return -1;
@@ -461,25 +481,25 @@
 
 	/* Load new function pointers */
 	this->gl_data->glXGetProcAddress =
-		(void *(*)(const GLubyte *)) dlsym(handle, "glXGetProcAddressARB");
+		(void *(*)(const GLubyte *)) do_dlsym(handle, "glXGetProcAddressARB");
 	this->gl_data->glXChooseVisual =
-		(XVisualInfo *(*)(Display *, int, int *)) dlsym(handle, "glXChooseVisual");
+		(XVisualInfo *(*)(Display *, int, int *)) do_dlsym(handle, "glXChooseVisual");
 	this->gl_data->glXCreateContext =
-		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) dlsym(handle, "glXCreateContext");
+		(GLXContext (*)(Display *, XVisualInfo *, GLXContext, int)) do_dlsym(handle, "glXCreateContext");
 	this->gl_data->glXDestroyContext =
-		(void (*)(Display *, GLXContext)) dlsym(handle, "glXDestroyContext");
+		(void (*)(Display *, GLXContext)) do_dlsym(handle, "glXDestroyContext");
 	this->gl_data->glXMakeCurrent =
-		(int (*)(Display *, GLXDrawable, GLXContext)) dlsym(handle, "glXMakeCurrent");
+		(int (*)(Display *, GLXDrawable, GLXContext)) do_dlsym(handle, "glXMakeCurrent");
 	this->gl_data->glXSwapBuffers =
-		(void (*)(Display *, GLXDrawable)) dlsym(handle, "glXSwapBuffers");
+		(void (*)(Display *, GLXDrawable)) do_dlsym(handle, "glXSwapBuffers");
 	this->gl_data->glXGetConfig =
-		(int (*)(Display *, XVisualInfo *, int, int *)) dlsym(handle, "glXGetConfig");
+		(int (*)(Display *, XVisualInfo *, int, int *)) do_dlsym(handle, "glXGetConfig");
 	this->gl_data->glXQueryExtensionsString =
-		(const char *(*)(Display *, int)) dlsym(handle, "glXQueryExtensionsString");
+		(const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
 	
 	/* We don't compare below for this in case we're not using Mesa. */
 	this->gl_data->glXReleaseBuffersMESA =
-		(void (*)(Display *, GLXDrawable)) dlsym( handle, "glXReleaseBuffersMESA" );
+		(void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" );
 	
 	
 	if ( (this->gl_data->glXChooseVisual == NULL) || 
@@ -515,15 +535,15 @@
 		return this->gl_data->glXGetProcAddress(proc);
 	}
 #if defined(__OpenBSD__) && !defined(__ELF__)
-#undef dlsym(x,y);
+#undef do_dlsym
 #endif
-	retval = dlsym(handle, proc);
+	retval = do_dlsym(handle, proc);
 	if (!retval && strlen(proc) <= 1022) {
 		procname[0] = '_';
 		strcpy(procname + 1, proc);
-		retval = dlsym(handle, procname);
+		retval = do_dlsym(handle, procname);
 	}
 	return retval;
 }
 
-#endif /* HAVE_OPENGL */
+#endif /* HAVE_OPENGL_X11 */
--- a/src/video/x11/SDL_x11gl_c.h	Wed Nov 23 07:29:56 2005 +0000
+++ b/src/video/x11/SDL_x11gl_c.h	Wed Nov 23 11:46:36 2005 +0000
@@ -25,19 +25,21 @@
  "@(#) $Id$";
 #endif
 
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 #include <GL/glx.h>
+#ifdef USE_DLOPEN
 #include <dlfcn.h>
-#if defined(__OpenBSD__) && !defined(__ELF__)
-#define dlsym(x,y) dlsym(x, "_" y)
+#else
+#include "SDL_loadso.h"
 #endif
 #endif
+
 #include "SDL_sysvideo.h"
 
 struct SDL_PrivateGLData {
     int gl_active; /* to stop switching drivers while we have a valid context */
 
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
     GLXContext glx_context;	/* Current GL context */
     XVisualInfo* glx_visualinfo; /* XVisualInfo* returned by glXChooseVisual */
 
@@ -82,7 +84,7 @@
 	      int screen);
 
     
-#endif /* HAVE_OPENGL */
+#endif /* HAVE_OPENGL_X11 */
 };
 
 /* Old variable names */
@@ -95,7 +97,7 @@
 extern int X11_GL_CreateWindow(_THIS, int w, int h);
 extern int X11_GL_CreateContext(_THIS);
 extern void X11_GL_Shutdown(_THIS);
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 extern int X11_GL_MakeCurrent(_THIS);
 extern int X11_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
 extern void X11_GL_SwapBuffers(_THIS);
--- a/src/video/x11/SDL_x11video.c	Wed Nov 23 07:29:56 2005 +0000
+++ b/src/video/x11/SDL_x11video.c	Wed Nov 23 11:46:36 2005 +0000
@@ -166,7 +166,7 @@
 		device->GetGamma = X11_GetVidModeGamma;
 		device->SetGammaRamp = X11_SetGammaRamp;
 		device->GetGammaRamp = NULL;
-#ifdef HAVE_OPENGL
+#ifdef HAVE_OPENGL_X11
 		device->GL_LoadLibrary = X11_GL_LoadLibrary;
 		device->GL_GetProcAddress = X11_GL_GetProcAddress;
 		device->GL_GetAttribute = X11_GL_GetAttribute;