Split platform-specific global data.

This commit is contained in:
Camilla Berglund 2012-04-22 15:53:02 +02:00
parent 2ac8da7465
commit 21e77fe1a6
8 changed files with 55 additions and 25 deletions

View File

@ -81,9 +81,9 @@ int _glfwPlatformInit(void)
{ {
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
_glfwLibrary.NS.OpenGLFramework = _glfwLibrary.NSGL.framework =
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfwLibrary.NS.OpenGLFramework == NULL) if (_glfwLibrary.NSGL.framework == NULL)
{ {
_glfwSetError(GLFW_PLATFORM_ERROR, _glfwSetError(GLFW_PLATFORM_ERROR,
"glfwInit: Failed to locate OpenGL framework"); "glfwInit: Failed to locate OpenGL framework");

View File

@ -94,7 +94,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
procname, procname,
kCFStringEncodingASCII); kCFStringEncodingASCII);
void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NS.OpenGLFramework, void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework,
symbolName); symbolName);
CFRelease(symbolName); CFRelease(symbolName);

View File

@ -43,8 +43,9 @@ typedef void* id;
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryNS NS
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL #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 typedef struct _GLFWlibraryNS
{ {
@ -89,8 +90,6 @@ typedef struct _GLFWlibraryNS
double resolution; double resolution;
} timer; } timer;
// dlopen handle for dynamically loading OpenGL extension entry points
void* OpenGLFramework;
CGDisplayModeRef desktopMode; CGDisplayModeRef desktopMode;
CGEventSourceRef eventSource; CGEventSourceRef eventSource;
id delegate; id delegate;
@ -100,6 +99,16 @@ typedef struct _GLFWlibraryNS
} _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 // Prototypes for platform specific internal functions
//======================================================================== //========================================================================

View File

@ -247,7 +247,8 @@ struct _GLFWlibrary
int originalRampSize; int originalRampSize;
// This is defined in the current port's platform.h // This is defined in the current port's platform.h
_GLFW_PLATFORM_LIBRARY_STATE; _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
_GLFW_PLATFORM_LIBRARY_OPENGL_STATE;
}; };

View File

@ -111,8 +111,9 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL #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 typedef struct _GLFWlibraryWin32
{ {
@ -210,6 +211,16 @@ typedef struct _GLFWlibraryWin32
} _GLFWlibraryWin32; } _GLFWlibraryWin32;
//------------------------------------------------------------------------
// Platform-specific library global data for WGL
//------------------------------------------------------------------------
typedef struct _GLFWlibraryWGL
{
int dummy;
} _GLFWlibraryWGL;
//======================================================================== //========================================================================
// Prototypes for platform specific internal functions // Prototypes for platform specific internal functions
//======================================================================== //========================================================================

View File

@ -55,8 +55,8 @@ static void initLibraries(void)
for (i = 0; libGL_names[i] != NULL; i++) for (i = 0; libGL_names[i] != NULL; i++)
{ {
_glfwLibrary.X11.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); _glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.X11.libGL) if (_glfwLibrary.GLX.libGL)
break; break;
} }
#endif #endif
@ -569,8 +569,8 @@ static GLboolean initDisplay(void)
} }
if (!glXQueryVersion(_glfwLibrary.X11.display, if (!glXQueryVersion(_glfwLibrary.X11.display,
&_glfwLibrary.X11.glxMajor, &_glfwLibrary.GLX.majorVersion,
&_glfwLibrary.X11.glxMinor)) &_glfwLibrary.GLX.minorVersion))
{ {
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, _glfwSetError(GLFW_OPENGL_UNAVAILABLE,
"X11/GLX: Failed to query GLX version"); "X11/GLX: Failed to query GLX version");
@ -775,10 +775,10 @@ int _glfwPlatformTerminate(void)
// Unload libGL.so if necessary // Unload libGL.so if necessary
#ifdef _GLFW_DLOPEN_LIBGL #ifdef _GLFW_DLOPEN_LIBGL
if (_glfwLibrary.X11.libGL != NULL) if (_glfwLibrary.GLX.libGL != NULL)
{ {
dlclose(_glfwLibrary.X11.libGL); dlclose(_glfwLibrary.GLX.libGL);
_glfwLibrary.X11.libGL = NULL; _glfwLibrary.GLX.libGL = NULL;
} }
#endif #endif

View File

@ -75,15 +75,16 @@
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x)
#elif defined(_GLFW_HAS_DLOPEN) #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 #define _GLFW_DLOPEN_LIBGL
#else #else
#error "No OpenGL entry point retrieval mechanism was enabled" #error "No OpenGL entry point retrieval mechanism was enabled"
#endif #endif
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #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 // Clipboard format atom indices
#define _GLFW_CLIPBOARD_FORMAT_UTF8 0 #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 typedef struct _GLFWlibraryX11
{ {
@ -177,9 +178,6 @@ typedef struct _GLFWlibraryX11
// True if window manager supports EWMH // True if window manager supports EWMH
GLboolean hasEWMH; GLboolean hasEWMH;
// Server-side GLX version
int glxMajor, glxMinor;
struct { struct {
GLboolean available; GLboolean available;
int eventBase; int eventBase;
@ -248,10 +246,21 @@ typedef struct _GLFWlibraryX11
int status; int status;
} selection; } selection;
} _GLFWlibraryX11;
//------------------------------------------------------------------------
// Platform-specific library global data for GLX
//------------------------------------------------------------------------
typedef struct _GLFWlibraryGLX
{
// Server-side GLX version
int majorVersion, minorVersion;
#if defined(_GLFW_DLOPEN_LIBGL) #if defined(_GLFW_DLOPEN_LIBGL)
void* libGL; // dlopen handle for libGL.so void* libGL; // dlopen handle for libGL.so
#endif #endif
} _GLFWlibraryX11; } _GLFWlibraryGLX;
//------------------------------------------------------------------------ //------------------------------------------------------------------------

View File

@ -131,7 +131,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
*found = 0; *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) if (!window->GLX.SGIX_fbconfig)
{ {