Move all context related members to _GLFWcontext

This commit is contained in:
Camilla Berglund 2015-11-09 16:48:55 +01:00
parent b22a0ec7d8
commit d4079ad3a2
11 changed files with 146 additions and 124 deletions

View File

@ -161,7 +161,7 @@ static int translateKey(unsigned int key)
- (void)windowDidResize:(NSNotification *)notification - (void)windowDidResize:(NSNotification *)notification
{ {
if (window->context.api != GLFW_NO_API) if (window->context.api != GLFW_NO_API)
[window->nsgl.context update]; [window->context.nsgl.object update];
if (_glfw.cursorWindow == window && if (_glfw.cursorWindow == window &&
window->cursorMode == GLFW_CURSOR_DISABLED) window->cursorMode == GLFW_CURSOR_DISABLED)
@ -179,7 +179,7 @@ static int translateKey(unsigned int key)
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
{ {
if (window->context.api != GLFW_NO_API) if (window->context.api != GLFW_NO_API)
[window->nsgl.context update]; [window->context.nsgl.object update];
if (_glfw.cursorWindow == window && if (_glfw.cursorWindow == window &&
window->cursorMode == GLFW_CURSOR_DISABLED) window->cursorMode == GLFW_CURSOR_DISABLED)

View File

@ -52,7 +52,7 @@ static GLFWbool parseVersionString(int* api, int* major, int* minor, int* rev)
window = _glfwPlatformGetCurrentContext(); window = _glfwPlatformGetCurrentContext();
version = (const char*) window->GetString(GL_VERSION); version = (const char*) window->context.GetString(GL_VERSION);
if (!version) if (!version)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -356,8 +356,10 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
{ {
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
window->GetIntegerv = (PFNGLGETINTEGERVPROC) glfwGetProcAddress("glGetIntegerv"); window->context.GetIntegerv = (PFNGLGETINTEGERVPROC)
window->GetString = (PFNGLGETSTRINGPROC) glfwGetProcAddress("glGetString"); glfwGetProcAddress("glGetIntegerv");
window->context.GetString = (PFNGLGETSTRINGPROC)
glfwGetProcAddress("glGetString");
if (!parseVersionString(&window->context.api, if (!parseVersionString(&window->context.api,
&window->context.major, &window->context.major,
@ -373,8 +375,9 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
// We cache it here instead of in glfwExtensionSupported mostly to alert // We cache it here instead of in glfwExtensionSupported mostly to alert
// users as early as possible that their build may be broken // users as early as possible that their build may be broken
window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); window->context.GetStringi = (PFNGLGETSTRINGIPROC)
if (!window->GetStringi) glfwGetProcAddress("glGetStringi");
if (!window->context.GetStringi)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Entry point retrieval is broken"); "Entry point retrieval is broken");
@ -388,7 +391,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
if (window->context.major >= 3) if (window->context.major >= 3)
{ {
GLint flags; GLint flags;
window->GetIntegerv(GL_CONTEXT_FLAGS, &flags); window->context.GetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
window->context.forward = GLFW_TRUE; window->context.forward = GLFW_TRUE;
@ -413,7 +416,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
(window->context.major == 3 && window->context.minor >= 2)) (window->context.major == 3 && window->context.minor >= 2))
{ {
GLint mask; GLint mask;
window->GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); window->context.GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
window->context.profile = GLFW_OPENGL_COMPAT_PROFILE; window->context.profile = GLFW_OPENGL_COMPAT_PROFILE;
@ -436,7 +439,8 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
// only present from 3.0 while the extension applies from 1.1 // only present from 3.0 while the extension applies from 1.1
GLint strategy; GLint strategy;
window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); window->context.GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB,
&strategy);
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET;
@ -453,7 +457,8 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
// one, so we can reuse them here // one, so we can reuse them here
GLint strategy; GLint strategy;
window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); window->context.GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB,
&strategy);
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET;
@ -465,7 +470,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
if (glfwExtensionSupported("GL_KHR_context_flush_control")) if (glfwExtensionSupported("GL_KHR_context_flush_control"))
{ {
GLint behavior; GLint behavior;
window->GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior); window->context.GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior);
if (behavior == GL_NONE) if (behavior == GL_NONE)
window->context.release = GLFW_RELEASE_BEHAVIOR_NONE; window->context.release = GLFW_RELEASE_BEHAVIOR_NONE;
@ -612,11 +617,12 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
// Check if extension is in the modern OpenGL extensions string list // Check if extension is in the modern OpenGL extensions string list
window->GetIntegerv(GL_NUM_EXTENSIONS, &count); window->context.GetIntegerv(GL_NUM_EXTENSIONS, &count);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
const char* en = (const char*) window->GetStringi(GL_EXTENSIONS, i); const char* en = (const char*)
window->context.GetStringi(GL_EXTENSIONS, i);
if (!en) if (!en)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -632,7 +638,8 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
{ {
// Check if extension is in the old style OpenGL extensions string // Check if extension is in the old style OpenGL extensions string
const char* extensions = (const char*) window->GetString(GL_EXTENSIONS); const char* extensions = (const char*)
window->context.GetString(GL_EXTENSIONS);
if (!extensions) if (!extensions)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,

View File

@ -304,7 +304,7 @@ int _glfwCreateContext(_GLFWwindow* window,
EGLContext share = NULL; EGLContext share = NULL;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->egl.context; share = ctxconfig->share->context.egl.handle;
if (!chooseFBConfigs(ctxconfig, fbconfig, &config)) if (!chooseFBConfigs(ctxconfig, fbconfig, &config))
{ {
@ -401,10 +401,10 @@ int _glfwCreateContext(_GLFWwindow* window,
// Context release behaviors (GL_KHR_context_flush_control) are not yet // Context release behaviors (GL_KHR_context_flush_control) are not yet
// supported on EGL but are not a hard constraint, so ignore and continue // supported on EGL but are not a hard constraint, so ignore and continue
window->egl.context = _glfw_eglCreateContext(_glfw.egl.display, window->context.egl.handle = _glfw_eglCreateContext(_glfw.egl.display,
config, share, attribs); config, share, attribs);
if (window->egl.context == EGL_NO_CONTEXT) if (window->context.egl.handle == EGL_NO_CONTEXT)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"EGL: Failed to create context: %s", "EGL: Failed to create context: %s",
@ -412,12 +412,12 @@ int _glfwCreateContext(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
window->egl.surface = window->context.egl.surface =
_glfw_eglCreateWindowSurface(_glfw.egl.display, _glfw_eglCreateWindowSurface(_glfw.egl.display,
config, config,
(EGLNativeWindowType)_GLFW_EGL_NATIVE_WINDOW, (EGLNativeWindowType)_GLFW_EGL_NATIVE_WINDOW,
NULL); NULL);
if (window->egl.surface == EGL_NO_SURFACE) if (window->context.egl.surface == EGL_NO_SURFACE)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to create window surface: %s", "EGL: Failed to create window surface: %s",
@ -425,7 +425,7 @@ int _glfwCreateContext(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
window->egl.config = config; window->context.egl.config = config;
// Load the appropriate client library // Load the appropriate client library
{ {
@ -478,12 +478,12 @@ int _glfwCreateContext(_GLFWwindow* window,
for (i = 0; sonames[i]; i++) for (i = 0; sonames[i]; i++)
{ {
window->egl.client = _glfw_dlopen(sonames[i]); window->context.egl.client = _glfw_dlopen(sonames[i]);
if (window->egl.client) if (window->context.egl.client)
break; break;
} }
if (!window->egl.client) if (!window->context.egl.client)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"EGL: Failed to load client library"); "EGL: Failed to load client library");
@ -506,23 +506,23 @@ void _glfwDestroyContext(_GLFWwindow* window)
if (window->context.api != GLFW_OPENGL_API) if (window->context.api != GLFW_OPENGL_API)
#endif // _GLFW_X11 #endif // _GLFW_X11
{ {
if (window->egl.client) if (window->context.egl.client)
{ {
_glfw_dlclose(window->egl.client); _glfw_dlclose(window->context.egl.client);
window->egl.client = NULL; window->context.egl.client = NULL;
} }
} }
if (window->egl.surface) if (window->context.egl.surface)
{ {
_glfw_eglDestroySurface(_glfw.egl.display, window->egl.surface); _glfw_eglDestroySurface(_glfw.egl.display, window->context.egl.surface);
window->egl.surface = EGL_NO_SURFACE; window->context.egl.surface = EGL_NO_SURFACE;
} }
if (window->egl.context) if (window->context.egl.handle)
{ {
_glfw_eglDestroyContext(_glfw.egl.display, window->egl.context); _glfw_eglDestroyContext(_glfw.egl.display, window->context.egl.handle);
window->egl.context = EGL_NO_CONTEXT; window->context.egl.handle = EGL_NO_CONTEXT;
} }
} }
@ -578,9 +578,9 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
if (window) if (window)
{ {
_glfw_eglMakeCurrent(_glfw.egl.display, _glfw_eglMakeCurrent(_glfw.egl.display,
window->egl.surface, window->context.egl.surface,
window->egl.surface, window->context.egl.surface,
window->egl.context); window->context.egl.handle);
} }
else else
{ {
@ -595,7 +595,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
_glfw_eglSwapBuffers(_glfw.egl.display, window->egl.surface); _glfw_eglSwapBuffers(_glfw.egl.display, window->context.egl.surface);
} }
void _glfwPlatformSwapInterval(int interval) void _glfwPlatformSwapInterval(int interval)
@ -620,9 +620,10 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
{ {
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
if (window->egl.client) if (window->context.egl.client)
{ {
GLFWglproc proc = (GLFWglproc) _glfw_dlsym(window->egl.client, procname); GLFWglproc proc = (GLFWglproc) _glfw_dlsym(window->context.egl.client,
procname);
if (proc) if (proc)
return proc; return proc;
} }
@ -652,7 +653,7 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle)
return EGL_NO_CONTEXT; return EGL_NO_CONTEXT;
} }
return window->egl.context; return window->context.egl.handle;
} }
GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
@ -666,6 +667,6 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
return EGL_NO_SURFACE; return EGL_NO_SURFACE;
} }
return window->egl.surface; return window->context.egl.surface;
} }

View File

@ -166,7 +166,7 @@ typedef GLFWglproc (EGLAPIENTRY * PFNEGLGETPROCADDRESSPROC)(const char*);
typedef struct _GLFWcontextEGL typedef struct _GLFWcontextEGL
{ {
EGLConfig config; EGLConfig config;
EGLContext context; EGLContext handle;
EGLSurface surface; EGLSurface surface;
void* client; void* client;

View File

@ -317,7 +317,7 @@ int _glfwCreateContext(_GLFWwindow* window,
GLXContext share = NULL; GLXContext share = NULL;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->glx.context; share = ctxconfig->share->context.glx.handle;
if (!chooseFBConfig(fbconfig, &native)) if (!chooseFBConfig(fbconfig, &native))
{ {
@ -436,7 +436,7 @@ int _glfwCreateContext(_GLFWwindow* window,
setGLXattrib(None, None); setGLXattrib(None, None);
window->glx.context = window->context.glx.handle =
_glfw.glx.CreateContextAttribsARB(_glfw.x11.display, _glfw.glx.CreateContextAttribsARB(_glfw.x11.display,
native, native,
share, share,
@ -447,31 +447,32 @@ int _glfwCreateContext(_GLFWwindow* window,
// implementation of GLX_ARB_create_context_profile that fail // implementation of GLX_ARB_create_context_profile that fail
// default 1.0 context creation with a GLXBadProfileARB error in // default 1.0 context creation with a GLXBadProfileARB error in
// violation of the extension spec // violation of the extension spec
if (!window->glx.context) if (!window->context.glx.handle)
{ {
if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB && if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
ctxconfig->api == GLFW_OPENGL_API && ctxconfig->api == GLFW_OPENGL_API &&
ctxconfig->profile == GLFW_OPENGL_ANY_PROFILE && ctxconfig->profile == GLFW_OPENGL_ANY_PROFILE &&
ctxconfig->forward == GLFW_FALSE) ctxconfig->forward == GLFW_FALSE)
{ {
window->glx.context = createLegacyContext(window, native, share); window->context.glx.handle =
createLegacyContext(window, native, share);
} }
} }
} }
else else
window->glx.context = createLegacyContext(window, native, share); window->context.glx.handle = createLegacyContext(window, native, share);
_glfwReleaseXErrorHandler(); _glfwReleaseXErrorHandler();
if (!window->glx.context) if (!window->context.glx.handle)
{ {
_glfwInputXError(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context"); _glfwInputXError(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context");
return GLFW_FALSE; return GLFW_FALSE;
} }
window->glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native, window->context.glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native,
window->x11.handle, NULL); window->x11.handle, NULL);
if (!window->glx.window) if (!window->context.glx.window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window"); _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window");
return GLFW_FALSE; return GLFW_FALSE;
@ -486,16 +487,16 @@ int _glfwCreateContext(_GLFWwindow* window,
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
if (window->glx.window) if (window->context.glx.window)
{ {
_glfw_glXDestroyWindow(_glfw.x11.display, window->glx.window); _glfw_glXDestroyWindow(_glfw.x11.display, window->context.glx.window);
window->glx.window = None; window->context.glx.window = None;
} }
if (window->glx.context) if (window->context.glx.handle)
{ {
_glfw_glXDestroyContext(_glfw.x11.display, window->glx.context); _glfw_glXDestroyContext(_glfw.x11.display, window->context.glx.handle);
window->glx.context = NULL; window->context.glx.handle = NULL;
} }
} }
@ -540,8 +541,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
if (window) if (window)
{ {
_glfw_glXMakeCurrent(_glfw.x11.display, _glfw_glXMakeCurrent(_glfw.x11.display,
window->glx.window, window->context.glx.window,
window->glx.context); window->context.glx.handle);
} }
else else
_glfw_glXMakeCurrent(_glfw.x11.display, None, NULL); _glfw_glXMakeCurrent(_glfw.x11.display, None, NULL);
@ -551,7 +552,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
_glfw_glXSwapBuffers(_glfw.x11.display, window->glx.window); _glfw_glXSwapBuffers(_glfw.x11.display, window->context.glx.window);
} }
void _glfwPlatformSwapInterval(int interval) void _glfwPlatformSwapInterval(int interval)
@ -561,7 +562,7 @@ void _glfwPlatformSwapInterval(int interval)
if (_glfw.glx.EXT_swap_control) if (_glfw.glx.EXT_swap_control)
{ {
_glfw.glx.SwapIntervalEXT(_glfw.x11.display, _glfw.glx.SwapIntervalEXT(_glfw.x11.display,
window->glx.window, window->context.glx.window,
interval); interval);
} }
else if (_glfw.glx.MESA_swap_control) else if (_glfw.glx.MESA_swap_control)
@ -612,6 +613,6 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
return NULL; return NULL;
} }
return window->glx.context; return window->context.glx.handle;
} }

View File

@ -116,7 +116,7 @@ typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow);
// //
typedef struct _GLFWcontextGLX typedef struct _GLFWcontextGLX
{ {
GLXContext context; GLXContext handle;
GLXWindow window; GLXWindow window;
} _GLFWcontextGLX; } _GLFWcontextGLX;

View File

@ -79,6 +79,7 @@ typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWwndconfig _GLFWwndconfig;
typedef struct _GLFWctxconfig _GLFWctxconfig; typedef struct _GLFWctxconfig _GLFWctxconfig;
typedef struct _GLFWfbconfig _GLFWfbconfig; typedef struct _GLFWfbconfig _GLFWfbconfig;
typedef struct _GLFWcontext _GLFWcontext;
typedef struct _GLFWwindow _GLFWwindow; typedef struct _GLFWwindow _GLFWwindow;
typedef struct _GLFWlibrary _GLFWlibrary; typedef struct _GLFWlibrary _GLFWlibrary;
typedef struct _GLFWmonitor _GLFWmonitor; typedef struct _GLFWmonitor _GLFWmonitor;
@ -240,6 +241,26 @@ struct _GLFWfbconfig
}; };
/*! @brief Context structure.
*/
struct _GLFWcontext
{
int api;
int major, minor, revision;
GLFWbool forward, debug, noerror;
int profile;
int robustness;
int release;
PFNGLGETSTRINGIPROC GetStringi;
PFNGLGETINTEGERVPROC GetIntegerv;
PFNGLGETSTRINGPROC GetString;
// This is defined in the context API's context.h
_GLFW_PLATFORM_CONTEXT_STATE;
};
/*! @brief Window and context structure. /*! @brief Window and context structure.
*/ */
struct _GLFWwindow struct _GLFWwindow
@ -265,19 +286,7 @@ struct _GLFWwindow
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
char keys[GLFW_KEY_LAST + 1]; char keys[GLFW_KEY_LAST + 1];
// OpenGL extensions and context attributes _GLFWcontext context;
struct {
int api;
int major, minor, revision;
GLFWbool forward, debug, noerror;
int profile;
int robustness;
int release;
} context;
PFNGLGETSTRINGIPROC GetStringi;
PFNGLGETINTEGERVPROC GetIntegerv;
PFNGLGETSTRINGPROC GetString;
struct { struct {
GLFWwindowposfun pos; GLFWwindowposfun pos;
@ -299,8 +308,6 @@ struct _GLFWwindow
// This is defined in the window API's platform.h // This is defined in the window API's platform.h
_GLFW_PLATFORM_WINDOW_STATE; _GLFW_PLATFORM_WINDOW_STATE;
// This is defined in the context API's context.h
_GLFW_PLATFORM_CONTEXT_STATE;
}; };

View File

@ -37,7 +37,7 @@
typedef struct _GLFWcontextNSGL typedef struct _GLFWcontextNSGL
{ {
id pixelFormat; id pixelFormat;
id context; id object;
} _GLFWcontextNSGL; } _GLFWcontextNSGL;

View File

@ -195,9 +195,9 @@ int _glfwCreateContext(_GLFWwindow* window,
#undef ADD_ATTR #undef ADD_ATTR
#undef ADD_ATTR2 #undef ADD_ATTR2
window->nsgl.pixelFormat = window->context.nsgl.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->nsgl.pixelFormat == nil) if (window->context.nsgl.pixelFormat == nil)
{ {
_glfwInputError(GLFW_FORMAT_UNAVAILABLE, _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"NSGL: Failed to find a suitable pixel format"); "NSGL: Failed to find a suitable pixel format");
@ -207,19 +207,19 @@ int _glfwCreateContext(_GLFWwindow* window,
NSOpenGLContext* share = NULL; NSOpenGLContext* share = NULL;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->nsgl.context; share = ctxconfig->share->context.nsgl.object;
window->nsgl.context = window->context.nsgl.object =
[[NSOpenGLContext alloc] initWithFormat:window->nsgl.pixelFormat [[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat
shareContext:share]; shareContext:share];
if (window->nsgl.context == nil) if (window->context.nsgl.object == nil)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"NSGL: Failed to create OpenGL context"); "NSGL: Failed to create OpenGL context");
return GLFW_FALSE; return GLFW_FALSE;
} }
[window->nsgl.context setView:window->ns.view]; [window->context.nsgl.object setView:window->ns.view];
return GLFW_TRUE; return GLFW_TRUE;
} }
@ -227,11 +227,11 @@ int _glfwCreateContext(_GLFWwindow* window,
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
[window->nsgl.pixelFormat release]; [window->context.nsgl.pixelFormat release];
window->nsgl.pixelFormat = nil; window->context.nsgl.pixelFormat = nil;
[window->nsgl.context release]; [window->context.nsgl.object release];
window->nsgl.context = nil; window->context.nsgl.object = nil;
} }
@ -242,7 +242,7 @@ void _glfwDestroyContext(_GLFWwindow* window)
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
[window->nsgl.context makeCurrentContext]; [window->context.nsgl.object makeCurrentContext];
else else
[NSOpenGLContext clearCurrentContext]; [NSOpenGLContext clearCurrentContext];
@ -252,7 +252,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
// ARP appears to be unnecessary, but this is future-proof // ARP appears to be unnecessary, but this is future-proof
[window->nsgl.context flushBuffer]; [window->context.nsgl.object flushBuffer];
} }
void _glfwPlatformSwapInterval(int interval) void _glfwPlatformSwapInterval(int interval)
@ -260,7 +260,8 @@ void _glfwPlatformSwapInterval(int interval)
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
GLint sync = interval; GLint sync = interval;
[window->nsgl.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; [window->context.nsgl.object setValues:&sync
forParameter:NSOpenGLCPSwapInterval];
} }
int _glfwPlatformExtensionSupported(const char* extension) int _glfwPlatformExtensionSupported(const char* extension)
@ -299,6 +300,6 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
return NULL; return NULL;
} }
return window->nsgl.context; return window->context.nsgl.object;
} }

View File

@ -89,7 +89,7 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib
assert(_glfw.wgl.ARB_pixel_format); assert(_glfw.wgl.ARB_pixel_format);
if (!_glfw.wgl.GetPixelFormatAttribivARB(window->wgl.dc, if (!_glfw.wgl.GetPixelFormatAttribivARB(window->context.wgl.dc,
pixelFormat, pixelFormat,
0, 1, &attrib, &value)) 0, 1, &attrib, &value))
{ {
@ -120,7 +120,7 @@ static GLFWbool choosePixelFormat(_GLFWwindow* window,
} }
else else
{ {
nativeCount = DescribePixelFormat(window->wgl.dc, nativeCount = DescribePixelFormat(window->context.wgl.dc,
1, 1,
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
NULL); NULL);
@ -192,7 +192,7 @@ static GLFWbool choosePixelFormat(_GLFWwindow* window,
// Get pixel format attributes through legacy PFDs // Get pixel format attributes through legacy PFDs
if (!DescribePixelFormat(window->wgl.dc, if (!DescribePixelFormat(window->context.wgl.dc,
n, n,
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
&pfd)) &pfd))
@ -327,10 +327,10 @@ int _glfwCreateContext(_GLFWwindow* window,
HGLRC share = NULL; HGLRC share = NULL;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->wgl.context; share = ctxconfig->share->context.wgl.handle;
window->wgl.dc = GetDC(window->win32.handle); window->context.wgl.dc = GetDC(window->win32.handle);
if (!window->wgl.dc) if (!window->context.wgl.dc)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve DC for window"); "WGL: Failed to retrieve DC for window");
@ -340,14 +340,15 @@ int _glfwCreateContext(_GLFWwindow* window,
if (!choosePixelFormat(window, fbconfig, &pixelFormat)) if (!choosePixelFormat(window, fbconfig, &pixelFormat))
return GLFW_FALSE; return GLFW_FALSE;
if (!DescribePixelFormat(window->wgl.dc, pixelFormat, sizeof(pfd), &pfd)) if (!DescribePixelFormat(window->context.wgl.dc,
pixelFormat, sizeof(pfd), &pfd))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve PFD for selected pixel format"); "WGL: Failed to retrieve PFD for selected pixel format");
return GLFW_FALSE; return GLFW_FALSE;
} }
if (!SetPixelFormat(window->wgl.dc, pixelFormat, &pfd)) if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to set selected pixel format"); "WGL: Failed to set selected pixel format");
@ -429,10 +430,10 @@ int _glfwCreateContext(_GLFWwindow* window,
setWGLattrib(0, 0); setWGLattrib(0, 0);
window->wgl.context = _glfw.wgl.CreateContextAttribsARB(window->wgl.dc, window->context.wgl.handle =
share, _glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc,
attribs); share, attribs);
if (!window->wgl.context) if (!window->context.wgl.handle)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: Failed to create OpenGL context"); "WGL: Failed to create OpenGL context");
@ -441,8 +442,9 @@ int _glfwCreateContext(_GLFWwindow* window,
} }
else else
{ {
window->wgl.context = _glfw_wglCreateContext(window->wgl.dc); window->context.wgl.handle =
if (!window->wgl.context) _glfw_wglCreateContext(window->context.wgl.dc);
if (!window->context.wgl.handle)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: Failed to create OpenGL context"); "WGL: Failed to create OpenGL context");
@ -451,7 +453,7 @@ int _glfwCreateContext(_GLFWwindow* window,
if (share) if (share)
{ {
if (!_glfw_wglShareLists(share, window->wgl.context)) if (!_glfw_wglShareLists(share, window->context.wgl.handle))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to enable sharing with specified OpenGL context"); "WGL: Failed to enable sharing with specified OpenGL context");
@ -469,16 +471,16 @@ int _glfwCreateContext(_GLFWwindow* window,
// //
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
if (window->wgl.context) if (window->context.wgl.handle)
{ {
_glfw_wglDeleteContext(window->wgl.context); _glfw_wglDeleteContext(window->context.wgl.handle);
window->wgl.context = NULL; window->context.wgl.handle = NULL;
} }
if (window->wgl.dc) if (window->context.wgl.dc)
{ {
ReleaseDC(window->win32.handle, window->wgl.dc); ReleaseDC(window->win32.handle, window->context.wgl.dc);
window->wgl.dc = NULL; window->context.wgl.dc = NULL;
} }
} }
@ -586,7 +588,10 @@ int _glfwAnalyzeContext(_GLFWwindow* window,
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
_glfw_wglMakeCurrent(window->wgl.dc, window->wgl.context); {
_glfw_wglMakeCurrent(window->context.wgl.dc,
window->context.wgl.handle);
}
else else
_glfw_wglMakeCurrent(NULL, NULL); _glfw_wglMakeCurrent(NULL, NULL);
@ -598,19 +603,19 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window)
// HACK: Use DwmFlush when desktop composition is enabled // HACK: Use DwmFlush when desktop composition is enabled
if (_glfwIsCompositionEnabled() && !window->monitor) if (_glfwIsCompositionEnabled() && !window->monitor)
{ {
int count = abs(window->wgl.interval); int count = abs(window->context.wgl.interval);
while (count--) while (count--)
_glfw_DwmFlush(); _glfw_DwmFlush();
} }
SwapBuffers(window->wgl.dc); SwapBuffers(window->context.wgl.dc);
} }
void _glfwPlatformSwapInterval(int interval) void _glfwPlatformSwapInterval(int interval)
{ {
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
window->wgl.interval = interval; window->context.wgl.interval = interval;
// HACK: Disable WGL swap interval when desktop composition is enabled to // HACK: Disable WGL swap interval when desktop composition is enabled to
// avoid interfering with DWM vsync // avoid interfering with DWM vsync
@ -639,7 +644,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
if (_glfw.wgl.GetExtensionsStringARB) if (_glfw.wgl.GetExtensionsStringARB)
{ {
extensions = _glfw.wgl.GetExtensionsStringARB(window->wgl.dc); extensions = _glfw.wgl.GetExtensionsStringARB(window->context.wgl.dc);
if (extensions) if (extensions)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))
@ -675,6 +680,6 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
return NULL; return NULL;
} }
return window->wgl.context; return window->context.wgl.handle;
} }

View File

@ -105,8 +105,8 @@ typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC);
// //
typedef struct _GLFWcontextWGL typedef struct _GLFWcontextWGL
{ {
HDC dc; // Private GDI device context HDC dc;
HGLRC context; // Permanent rendering context HGLRC handle;
int interval; int interval;
} _GLFWcontextWGL; } _GLFWcontextWGL;