From 21e77fe1a6a429558a6d50dcab376810078bd67b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Apr 2012 15:53:02 +0200 Subject: [PATCH] Split platform-specific global data. --- src/cocoa_init.m | 4 ++-- src/cocoa_opengl.m | 2 +- src/cocoa_platform.h | 17 +++++++++++++---- src/internal.h | 3 ++- src/win32_platform.h | 15 +++++++++++++-- src/x11_init.c | 14 +++++++------- src/x11_platform.h | 23 ++++++++++++++++------- src/x11_window.c | 2 +- 8 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 63c09e8a..329bcfa4 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -81,9 +81,9 @@ int _glfwPlatformInit(void) { _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; - _glfwLibrary.NS.OpenGLFramework = + _glfwLibrary.NSGL.framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); - if (_glfwLibrary.NS.OpenGLFramework == NULL) + if (_glfwLibrary.NSGL.framework == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, "glfwInit: Failed to locate OpenGL framework"); diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m index 0ea39076..33bf4ab5 100644 --- a/src/cocoa_opengl.m +++ b/src/cocoa_opengl.m @@ -94,7 +94,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) procname, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NS.OpenGLFramework, + void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework, symbolName); CFRelease(symbolName); diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 77aa3481..97e903d7 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -43,8 +43,9 @@ typedef void* id; #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryNS NS #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL //======================================================================== @@ -80,7 +81,7 @@ typedef struct _GLFWwindowNS //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for Cocoa //------------------------------------------------------------------------ typedef struct _GLFWlibraryNS { @@ -89,8 +90,6 @@ typedef struct _GLFWlibraryNS double resolution; } timer; - // dlopen handle for dynamically loading OpenGL extension entry points - void* OpenGLFramework; CGDisplayModeRef desktopMode; CGEventSourceRef eventSource; id delegate; @@ -100,6 +99,16 @@ typedef struct _GLFWlibraryNS } _GLFWlibraryNS; +//------------------------------------------------------------------------ +// Platform-specific library global data for NSGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryNSGL +{ + // dlopen handle for dynamically loading OpenGL extension entry points + void* framework; +} _GLFWlibraryNSGL; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/internal.h b/src/internal.h index 4e7bce1a..6398bdc5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -247,7 +247,8 @@ struct _GLFWlibrary int originalRampSize; // This is defined in the current port's platform.h - _GLFW_PLATFORM_LIBRARY_STATE; + _GLFW_PLATFORM_LIBRARY_WINDOW_STATE; + _GLFW_PLATFORM_LIBRARY_OPENGL_STATE; }; diff --git a/src/win32_platform.h b/src/win32_platform.h index 7c369767..e7b7b165 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -111,8 +111,9 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 Win32 +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL //======================================================================== @@ -169,7 +170,7 @@ typedef struct _GLFWwindowWin32 //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for Win32 //------------------------------------------------------------------------ typedef struct _GLFWlibraryWin32 { @@ -210,6 +211,16 @@ typedef struct _GLFWlibraryWin32 } _GLFWlibraryWin32; +//------------------------------------------------------------------------ +// Platform-specific library global data for WGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryWGL +{ + int dummy; + +} _GLFWlibraryWGL; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/x11_init.c b/src/x11_init.c index 3af08cf4..d59fbcc6 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -55,8 +55,8 @@ static void initLibraries(void) for (i = 0; libGL_names[i] != NULL; i++) { - _glfwLibrary.X11.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); - if (_glfwLibrary.X11.libGL) + _glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); + if (_glfwLibrary.GLX.libGL) break; } #endif @@ -569,8 +569,8 @@ static GLboolean initDisplay(void) } if (!glXQueryVersion(_glfwLibrary.X11.display, - &_glfwLibrary.X11.glxMajor, - &_glfwLibrary.X11.glxMinor)) + &_glfwLibrary.GLX.majorVersion, + &_glfwLibrary.GLX.minorVersion)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to query GLX version"); @@ -775,10 +775,10 @@ int _glfwPlatformTerminate(void) // Unload libGL.so if necessary #ifdef _GLFW_DLOPEN_LIBGL - if (_glfwLibrary.X11.libGL != NULL) + if (_glfwLibrary.GLX.libGL != NULL) { - dlclose(_glfwLibrary.X11.libGL); - _glfwLibrary.X11.libGL = NULL; + dlclose(_glfwLibrary.GLX.libGL); + _glfwLibrary.GLX.libGL = NULL; } #endif diff --git a/src/x11_platform.h b/src/x11_platform.h index 2de3367e..013ca4e0 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -75,15 +75,16 @@ #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) #elif defined(_GLFW_HAS_DLOPEN) - #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.X11.libGL, x) + #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.GLX.libGL, x) #define _GLFW_DLOPEN_LIBGL #else #error "No OpenGL entry point retrieval mechanism was enabled" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 @@ -157,7 +158,7 @@ typedef struct _GLFWwindowX11 //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for X11 //------------------------------------------------------------------------ typedef struct _GLFWlibraryX11 { @@ -177,9 +178,6 @@ typedef struct _GLFWlibraryX11 // True if window manager supports EWMH GLboolean hasEWMH; - // Server-side GLX version - int glxMajor, glxMinor; - struct { GLboolean available; int eventBase; @@ -248,10 +246,21 @@ typedef struct _GLFWlibraryX11 int status; } selection; +} _GLFWlibraryX11; + + +//------------------------------------------------------------------------ +// Platform-specific library global data for GLX +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryGLX +{ + // Server-side GLX version + int majorVersion, minorVersion; + #if defined(_GLFW_DLOPEN_LIBGL) void* libGL; // dlopen handle for libGL.so #endif -} _GLFWlibraryX11; +} _GLFWlibraryGLX; //------------------------------------------------------------------------ diff --git a/src/x11_window.c b/src/x11_window.c index 6fc8c2fd..ccd99a60 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -131,7 +131,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) *found = 0; - if (_glfwLibrary.X11.glxMajor == 1 && _glfwLibrary.X11.glxMinor < 3) + if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) { if (!window->GLX.SGIX_fbconfig) {