Commit 3631611a authored by Ryan C. Gordon's avatar Ryan C. Gordon

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().

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