Skip to content

Commit

Permalink
Seperate glX from HAVE_OPENGL, for platforms that have both an X serv…
Browse files Browse the repository at this point in the history
…er 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().
  • Loading branch information
icculus committed Nov 23, 2005
1 parent b4b5899 commit c2c1bb9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 59 deletions.
29 changes: 15 additions & 14 deletions configure.in
Expand Up @@ -1103,7 +1103,7 @@ AC_ARG_ENABLE(video-opengl,
, 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)
Expand All @@ -1118,7 +1118,7 @@ CheckOpenGL()
])
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
Expand Down Expand Up @@ -2076,7 +2076,7 @@ case "$target" in
CheckAAlib
CheckQtopia
CheckPicoGUI
CheckOpenGL
CheckOpenGLX11
CheckInputEvents
CheckPTHREAD
CheckSIGACTION
Expand Down Expand Up @@ -2157,7 +2157,7 @@ case "$target" in
CheckDGA
CheckSVGA
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckRPATH
Expand Down Expand Up @@ -2203,7 +2203,7 @@ case "$target" in
CheckDGA
CheckSVGA
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckUSBHID
Expand Down Expand Up @@ -2242,7 +2242,7 @@ case "$target" in
CheckX11
CheckAAlib
CheckWscons
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckUSBHID
Expand Down Expand Up @@ -2284,7 +2284,7 @@ case "$target" in
CheckNAS
CheckX11
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckUSBHID
Expand Down Expand Up @@ -2327,7 +2327,7 @@ case "$target" in
CheckNAS
CheckX11
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckRPATH
Expand Down Expand Up @@ -2370,7 +2370,7 @@ case "$target" in
CheckNAS
CheckX11
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckRPATH
Expand Down Expand Up @@ -2410,7 +2410,7 @@ case "$target" in
CheckNAS
CheckX11
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
# We use the dmedia audio API, not the Sun audio API
Expand Down Expand Up @@ -2461,7 +2461,7 @@ case "$target" in
CheckX11
CheckGGI
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
# Set up files for the audio library
Expand Down Expand Up @@ -2501,7 +2501,7 @@ case "$target" in
CheckX11
CheckGGI
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
# Set up files for the audio library
Expand Down Expand Up @@ -2538,7 +2538,7 @@ case "$target" in
CheckX11
CheckGGI
CheckAAlib
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
# Set up files for the audio library
Expand Down Expand Up @@ -2578,7 +2578,7 @@ case "$target" in
CheckNAS
CheckPHOTON
CheckX11
CheckOpenGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
# Set up files for the audio library
Expand Down Expand Up @@ -2771,6 +2771,7 @@ case "$target" in
CheckCARBON
CheckX11
CheckMacGL
CheckOpenGLX11
CheckPTHREAD
CheckSIGACTION
CheckAltivec
Expand Down
96 changes: 58 additions & 38 deletions src/video/x11/SDL_x11gl.c
Expand Up @@ -37,6 +37,8 @@ static char rcsid =
#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
Expand All @@ -50,7 +52,7 @@ static char rcsid =
/* 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;
Expand Down Expand Up @@ -175,7 +177,7 @@ XVisualInfo *X11_GL_GetVisual(_THIS)
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;
Expand Down Expand Up @@ -207,7 +209,7 @@ int X11_GL_CreateWindow(_THIS, int w, int h)
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,
Expand All @@ -233,7 +235,7 @@ int X11_GL_CreateContext(_THIS)

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);
Expand All @@ -247,10 +249,10 @@ void X11_GL_Shutdown(_THIS)
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)
{
Expand Down Expand Up @@ -395,13 +397,19 @@ void X11_GL_SwapBuffers(_THIS)
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;
Expand All @@ -416,41 +424,53 @@ void X11_GL_UnloadLibrary(_THIS)
#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");
return -1;
}

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;
Expand All @@ -461,25 +481,25 @@ int X11_GL_LoadLibrary(_THIS, const char* path)

/* 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) ||
Expand Down Expand Up @@ -515,15 +535,15 @@ void *X11_GL_GetProcAddress(_THIS, const char* proc)
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 */
14 changes: 8 additions & 6 deletions src/video/x11/SDL_x11gl_c.h
Expand Up @@ -25,19 +25,21 @@ static char rcsid =
"@(#) $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 */

Expand Down Expand Up @@ -82,7 +84,7 @@ struct SDL_PrivateGLData {
int screen);


#endif /* HAVE_OPENGL */
#endif /* HAVE_OPENGL_X11 */
};

/* Old variable names */
Expand All @@ -95,7 +97,7 @@ extern XVisualInfo *X11_GL_GetVisual(_THIS);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11video.c
Expand Up @@ -166,7 +166,7 @@ static SDL_VideoDevice *X11_CreateDevice(int devindex)
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;
Expand Down

0 comments on commit c2c1bb9

Please sign in to comment.