From 3c52cb1790668c5f4b428a8a0146ee33c81f844a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 May 2015 01:06:36 +0200 Subject: [PATCH] Simplified glXGetProcAddress logic. Removed compile-time selection of GLX entry point retrieval mechanism. Made dlopen a required dependency. This is a stopgap solution until we start requiring GLX 1.4. --- CMakeLists.txt | 21 +++------------------ README.md | 3 +++ docs/compile.dox | 11 ++--------- src/egl_context.h | 5 ----- src/glfw_config.h.in | 8 -------- src/glx_context.c | 35 ++++++++++++++++++----------------- src/glx_context.h | 32 ++++++-------------------------- src/x11_init.c | 9 --------- 8 files changed, 32 insertions(+), 92 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7ed1a9..41d56bf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -372,25 +372,10 @@ if (_GLFW_GLX) list(APPEND glfw_PKG_DEPS "gl") - include(CheckFunctionExists) - - set(CMAKE_REQUIRED_LIBRARIES "${OPENGL_gl_LIBRARY}") - check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) - check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB) - check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT) - - if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND - NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND - NOT _GLFW_HAS_GLXGETPROCADDRESSEXT) - message(WARNING "No glXGetProcAddressXXX variant found") - - set(_GLFW_HAS_DLOPEN 1) - if (CMAKE_DL_LIBS) - list(APPEND glfw_LIBRARIES "${CMAKE_DL_LIBS}") - list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") - endif() + if (CMAKE_DL_LIBS) + list(APPEND glfw_LIBRARIES "${CMAKE_DL_LIBS}") + list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") endif() - endif() #-------------------------------------------------------------------- diff --git a/README.md b/README.md index 185aa280..92f92314 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,9 @@ GLFW bundles a number of dependencies in the `deps/` directory. - [Cocoa] Bugfix: Resizing a window to its minimum size would segfault - [Cocoa] Bugfix: Creating or showing a window would make its context current - [X11] Bugfix: `glfwInit` would segfault on systems without RandR + - [GLX] Added dependency on `libdl` on systems where it provides `dlopen` + - [GLX] Removed `_GLFW_HAS_GLXGETPROCADDRESS*` and `_GLFW_HAS_DLOPEN` + compile-time options ## Contact diff --git a/docs/compile.dox b/docs/compile.dox index e1828162..5e36c1f1 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -288,15 +288,8 @@ libraries. If you are building GLFW as a shared library / dynamic library / DLL then you must also define `_GLFW_BUILD_DLL`. Otherwise, you may not define it. -If you are using the X11 window creation API then you _must_ also select an entry -point retrieval mechanism. - - - `_GLFW_HAS_GLXGETPROCADDRESS` to use `glXGetProcAddress` (recommended) - - `_GLFW_HAS_GLXGETPROCADDRESSARB` to use `glXGetProcAddressARB` (legacy) - - `_GLFW_HAS_GLXGETPROCADDRESSEXT` to use `glXGetProcAddressEXT` (legacy) - - `_GLFW_HAS_DLOPEN` to do manual retrieval with `dlopen` (fallback) - -In addition, support for the following X11 extensions can be enabled: +If you are using the X11 window creation API, support for the following X11 +extensions can be enabled: - `_GLFW_HAS_XINPUT` to use XInput2 for high-resolution cursor motion (recommended) diff --git a/src/egl_context.h b/src/egl_context.h index 21d68527..7786c35c 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -35,11 +35,6 @@ // extensions and not all operating systems come with an up-to-date version #include "../deps/EGL/eglext.h" -// Do we have support for dlopen/dlsym? -#if defined(_GLFW_HAS_DLOPEN) - #include -#endif - #define _GLFW_PLATFORM_FBCONFIG EGLConfig egl #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL egl #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryEGL egl diff --git a/src/glfw_config.h.in b/src/glfw_config.h.in index 13d5c783..b805a7af 100644 --- a/src/glfw_config.h.in +++ b/src/glfw_config.h.in @@ -64,14 +64,6 @@ #cmakedefine _GLFW_HAS_XINPUT // Define this to 1 if the Xxf86vm X11 extension is available #cmakedefine _GLFW_HAS_XF86VM -// Define this to 1 if glXGetProcAddress is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESS -// Define this to 1 if glXGetProcAddressARB is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSARB -// Define this to 1 if glXGetProcAddressEXT is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT -// Define this to 1 if dlopen is available -#cmakedefine _GLFW_HAS_DLOPEN // Define this to 1 if glfwInit should change the current directory #cmakedefine _GLFW_USE_CHDIR diff --git a/src/glx_context.c b/src/glx_context.c index 54635cdf..5e5ff201 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -30,11 +30,7 @@ #include #include #include - - -// This is the only glXGetProcAddress variant not declared by glxext.h -void (*glXGetProcAddressEXT(const GLubyte* procName))(); - +#include #ifndef GLXBadProfileARB #define GLXBadProfileARB 13 @@ -163,14 +159,17 @@ int _glfwInitContextAPI(void) if (!_glfwInitTLS()) return GL_FALSE; -#ifdef _GLFW_DLOPEN_LIBGL - _glfw.glx.libGL = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); - if (!_glfw.glx.libGL) + _glfw.glx.handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); + if (!_glfw.glx.handle) { - _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to find libGL"); + _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: %s", dlerror()); return GL_FALSE; } -#endif + + _glfw.glx.GetProcAddress = + dlsym(_glfw.glx.handle, "glXGetProcAddress"); + _glfw.glx.GetProcAddressARB = + dlsym(_glfw.glx.handle, "glXGetProcAddressARB"); if (!glXQueryExtension(_glfw.x11.display, &_glfw.glx.errorBase, @@ -257,14 +256,11 @@ int _glfwInitContextAPI(void) // void _glfwTerminateContextAPI(void) { - // Unload libGL.so if necessary -#ifdef _GLFW_DLOPEN_LIBGL - if (_glfw.glx.libGL != NULL) + if (_glfw.glx.handle) { - dlclose(_glfw.glx.libGL); - _glfw.glx.libGL = NULL; + dlclose(_glfw.glx.handle); + _glfw.glx.handle = NULL; } -#endif _glfwTerminateTLS(); } @@ -527,7 +523,12 @@ int _glfwPlatformExtensionSupported(const char* extension) GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return _glfw_glXGetProcAddress((const GLubyte*) procname); + if (_glfw.glx.GetProcAddress) + return _glfw.glx.GetProcAddress((const GLubyte*) procname); + else if (_glfw.glx.GetProcAddressARB) + return _glfw.glx.GetProcAddressARB((const GLubyte*) procname); + else + return dlsym(_glfw.glx.handle, procname); } diff --git a/src/glx_context.h b/src/glx_context.h index 918ab000..974a3f3c 100644 --- a/src/glx_context.h +++ b/src/glx_context.h @@ -34,29 +34,9 @@ // This path may need to be changed if you build GLFW using your own setup // We ship and use our own copy of glxext.h since GLFW uses fairly new // extensions and not all operating systems come with an up-to-date version +#define GLX_GLXEXT_PROTOTYPES #include "../deps/GL/glxext.h" -// Do we have support for dlopen/dlsym? -#if defined(_GLFW_HAS_DLOPEN) - #include -#endif - -// We support four different ways for getting addresses for GL/GLX -// extension functions: glXGetProcAddress, glXGetProcAddressARB, -// glXGetProcAddressEXT, and dlsym -#if defined(_GLFW_HAS_GLXGETPROCADDRESSARB) - #define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x) -#elif defined(_GLFW_HAS_GLXGETPROCADDRESS) - #define _glfw_glXGetProcAddress(x) glXGetProcAddress(x) -#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) - #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) -#elif defined(_GLFW_HAS_DLOPEN) - #define _glfw_glXGetProcAddress(x) dlsym(_glfw.glx.libGL, x) - #define _GLFW_DLOPEN_LIBGL -#else - #error "No OpenGL entry point retrieval mechanism was enabled" -#endif - #define _GLFW_PLATFORM_FBCONFIG GLXFBConfig glx #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx @@ -86,7 +66,12 @@ typedef struct _GLFWlibraryGLX int eventBase; int errorBase; + // dlopen handle for libGL.so.1 + void* handle; + // GLX extensions + PFNGLXGETPROCADDRESSPROC GetProcAddress; + PFNGLXGETPROCADDRESSPROC GetProcAddressARB; PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; @@ -102,11 +87,6 @@ typedef struct _GLFWlibraryGLX GLboolean EXT_create_context_es2_profile; GLboolean ARB_context_flush_control; -#if defined(_GLFW_DLOPEN_LIBGL) - // dlopen handle for libGL.so (for glfwGetProcAddress) - void* libGL; -#endif - } _GLFWlibraryGLX; diff --git a/src/x11_init.c b/src/x11_init.c index 19b5ab9d..36bfcc80 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -797,15 +797,6 @@ const char* _glfwPlatformGetVersionString(void) #elif defined(_GLFW_EGL) " EGL" #endif -#if defined(_GLFW_HAS_GLXGETPROCADDRESS) - " glXGetProcAddress" -#elif defined(_GLFW_HAS_GLXGETPROCADDRESSARB) - " glXGetProcAddressARB" -#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) - " glXGetProcAddressEXT" -#elif defined(_GLFW_DLOPEN_LIBGL) - " dlsym(libGL)" -#endif #if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) " clock_gettime" #endif