From d4079ad3a2b7de2bdbcf4a7d1d6fd988870c6cbc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Nov 2015 16:48:55 +0100 Subject: [PATCH] Move all context related members to _GLFWcontext --- src/cocoa_window.m | 4 ++-- src/context.c | 33 ++++++++++++++++---------- src/egl_context.c | 55 +++++++++++++++++++++--------------------- src/egl_context.h | 2 +- src/glx_context.c | 41 ++++++++++++++++---------------- src/glx_context.h | 2 +- src/internal.h | 37 +++++++++++++++++------------ src/nsgl_context.h | 2 +- src/nsgl_context.m | 31 ++++++++++++------------ src/wgl_context.c | 59 +++++++++++++++++++++++++--------------------- src/wgl_context.h | 4 ++-- 11 files changed, 146 insertions(+), 124 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 88e63c3b..15bc48e5 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -161,7 +161,7 @@ static int translateKey(unsigned int key) - (void)windowDidResize:(NSNotification *)notification { if (window->context.api != GLFW_NO_API) - [window->nsgl.context update]; + [window->context.nsgl.object update]; if (_glfw.cursorWindow == window && window->cursorMode == GLFW_CURSOR_DISABLED) @@ -179,7 +179,7 @@ static int translateKey(unsigned int key) - (void)windowDidMove:(NSNotification *)notification { if (window->context.api != GLFW_NO_API) - [window->nsgl.context update]; + [window->context.nsgl.object update]; if (_glfw.cursorWindow == window && window->cursorMode == GLFW_CURSOR_DISABLED) diff --git a/src/context.c b/src/context.c index 7bedd1ea..3da19864 100644 --- a/src/context.c +++ b/src/context.c @@ -52,7 +52,7 @@ static GLFWbool parseVersionString(int* api, int* major, int* minor, int* rev) window = _glfwPlatformGetCurrentContext(); - version = (const char*) window->GetString(GL_VERSION); + version = (const char*) window->context.GetString(GL_VERSION); if (!version) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -356,8 +356,10 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) { _GLFWwindow* window = _glfwPlatformGetCurrentContext(); - window->GetIntegerv = (PFNGLGETINTEGERVPROC) glfwGetProcAddress("glGetIntegerv"); - window->GetString = (PFNGLGETSTRINGPROC) glfwGetProcAddress("glGetString"); + window->context.GetIntegerv = (PFNGLGETINTEGERVPROC) + glfwGetProcAddress("glGetIntegerv"); + window->context.GetString = (PFNGLGETSTRINGPROC) + glfwGetProcAddress("glGetString"); if (!parseVersionString(&window->context.api, &window->context.major, @@ -373,8 +375,9 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) // We cache it here instead of in glfwExtensionSupported mostly to alert // users as early as possible that their build may be broken - window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); - if (!window->GetStringi) + window->context.GetStringi = (PFNGLGETSTRINGIPROC) + glfwGetProcAddress("glGetStringi"); + if (!window->context.GetStringi) { _glfwInputError(GLFW_PLATFORM_ERROR, "Entry point retrieval is broken"); @@ -388,7 +391,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) if (window->context.major >= 3) { GLint flags; - window->GetIntegerv(GL_CONTEXT_FLAGS, &flags); + window->context.GetIntegerv(GL_CONTEXT_FLAGS, &flags); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) window->context.forward = GLFW_TRUE; @@ -413,7 +416,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) (window->context.major == 3 && window->context.minor >= 2)) { GLint mask; - window->GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); + window->context.GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) 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 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) window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; @@ -453,7 +457,8 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) // one, so we can reuse them here 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) window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; @@ -465,7 +470,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) if (glfwExtensionSupported("GL_KHR_context_flush_control")) { GLint behavior; - window->GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior); + window->context.GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior); if (behavior == GL_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 - window->GetIntegerv(GL_NUM_EXTENSIONS, &count); + window->context.GetIntegerv(GL_NUM_EXTENSIONS, &count); 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) { _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 - const char* extensions = (const char*) window->GetString(GL_EXTENSIONS); + const char* extensions = (const char*) + window->context.GetString(GL_EXTENSIONS); if (!extensions) { _glfwInputError(GLFW_PLATFORM_ERROR, diff --git a/src/egl_context.c b/src/egl_context.c index 2d4eface..b9403dee 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -304,7 +304,7 @@ int _glfwCreateContext(_GLFWwindow* window, EGLContext share = NULL; if (ctxconfig->share) - share = ctxconfig->share->egl.context; + share = ctxconfig->share->context.egl.handle; if (!chooseFBConfigs(ctxconfig, fbconfig, &config)) { @@ -401,10 +401,10 @@ int _glfwCreateContext(_GLFWwindow* window, // Context release behaviors (GL_KHR_context_flush_control) are not yet // supported on EGL but are not a hard constraint, so ignore and continue - window->egl.context = _glfw_eglCreateContext(_glfw.egl.display, - config, share, attribs); + window->context.egl.handle = _glfw_eglCreateContext(_glfw.egl.display, + config, share, attribs); - if (window->egl.context == EGL_NO_CONTEXT) + if (window->context.egl.handle == EGL_NO_CONTEXT) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "EGL: Failed to create context: %s", @@ -412,12 +412,12 @@ int _glfwCreateContext(_GLFWwindow* window, return GLFW_FALSE; } - window->egl.surface = + window->context.egl.surface = _glfw_eglCreateWindowSurface(_glfw.egl.display, config, (EGLNativeWindowType)_GLFW_EGL_NATIVE_WINDOW, NULL); - if (window->egl.surface == EGL_NO_SURFACE) + if (window->context.egl.surface == EGL_NO_SURFACE) { _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: Failed to create window surface: %s", @@ -425,7 +425,7 @@ int _glfwCreateContext(_GLFWwindow* window, return GLFW_FALSE; } - window->egl.config = config; + window->context.egl.config = config; // Load the appropriate client library { @@ -478,12 +478,12 @@ int _glfwCreateContext(_GLFWwindow* window, for (i = 0; sonames[i]; i++) { - window->egl.client = _glfw_dlopen(sonames[i]); - if (window->egl.client) + window->context.egl.client = _glfw_dlopen(sonames[i]); + if (window->context.egl.client) break; } - if (!window->egl.client) + if (!window->context.egl.client) { _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to load client library"); @@ -506,23 +506,23 @@ void _glfwDestroyContext(_GLFWwindow* window) if (window->context.api != GLFW_OPENGL_API) #endif // _GLFW_X11 { - if (window->egl.client) + if (window->context.egl.client) { - _glfw_dlclose(window->egl.client); - window->egl.client = NULL; + _glfw_dlclose(window->context.egl.client); + window->context.egl.client = NULL; } } - if (window->egl.surface) + if (window->context.egl.surface) { - _glfw_eglDestroySurface(_glfw.egl.display, window->egl.surface); - window->egl.surface = EGL_NO_SURFACE; + _glfw_eglDestroySurface(_glfw.egl.display, window->context.egl.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); - window->egl.context = EGL_NO_CONTEXT; + _glfw_eglDestroyContext(_glfw.egl.display, window->context.egl.handle); + window->context.egl.handle = EGL_NO_CONTEXT; } } @@ -578,9 +578,9 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window) { _glfw_eglMakeCurrent(_glfw.egl.display, - window->egl.surface, - window->egl.surface, - window->egl.context); + window->context.egl.surface, + window->context.egl.surface, + window->context.egl.handle); } else { @@ -595,7 +595,7 @@ void _glfwPlatformMakeContextCurrent(_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) @@ -620,9 +620,10 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { _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) return proc; } @@ -652,7 +653,7 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle) return EGL_NO_CONTEXT; } - return window->egl.context; + return window->context.egl.handle; } GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) @@ -666,6 +667,6 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) return EGL_NO_SURFACE; } - return window->egl.surface; + return window->context.egl.surface; } diff --git a/src/egl_context.h b/src/egl_context.h index 660019dd..7de7439e 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -166,7 +166,7 @@ typedef GLFWglproc (EGLAPIENTRY * PFNEGLGETPROCADDRESSPROC)(const char*); typedef struct _GLFWcontextEGL { EGLConfig config; - EGLContext context; + EGLContext handle; EGLSurface surface; void* client; diff --git a/src/glx_context.c b/src/glx_context.c index d369843b..79753118 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -317,7 +317,7 @@ int _glfwCreateContext(_GLFWwindow* window, GLXContext share = NULL; if (ctxconfig->share) - share = ctxconfig->share->glx.context; + share = ctxconfig->share->context.glx.handle; if (!chooseFBConfig(fbconfig, &native)) { @@ -436,7 +436,7 @@ int _glfwCreateContext(_GLFWwindow* window, setGLXattrib(None, None); - window->glx.context = + window->context.glx.handle = _glfw.glx.CreateContextAttribsARB(_glfw.x11.display, native, share, @@ -447,31 +447,32 @@ int _glfwCreateContext(_GLFWwindow* window, // implementation of GLX_ARB_create_context_profile that fail // default 1.0 context creation with a GLXBadProfileARB error in // violation of the extension spec - if (!window->glx.context) + if (!window->context.glx.handle) { if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB && ctxconfig->api == GLFW_OPENGL_API && ctxconfig->profile == GLFW_OPENGL_ANY_PROFILE && ctxconfig->forward == GLFW_FALSE) { - window->glx.context = createLegacyContext(window, native, share); + window->context.glx.handle = + createLegacyContext(window, native, share); } } } else - window->glx.context = createLegacyContext(window, native, share); + window->context.glx.handle = createLegacyContext(window, native, share); _glfwReleaseXErrorHandler(); - if (!window->glx.context) + if (!window->context.glx.handle) { _glfwInputXError(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context"); return GLFW_FALSE; } - window->glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native, - window->x11.handle, NULL); - if (!window->glx.window) + window->context.glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native, + window->x11.handle, NULL); + if (!window->context.glx.window) { _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window"); return GLFW_FALSE; @@ -486,16 +487,16 @@ int _glfwCreateContext(_GLFWwindow* window, // void _glfwDestroyContext(_GLFWwindow* window) { - if (window->glx.window) + if (window->context.glx.window) { - _glfw_glXDestroyWindow(_glfw.x11.display, window->glx.window); - window->glx.window = None; + _glfw_glXDestroyWindow(_glfw.x11.display, window->context.glx.window); + window->context.glx.window = None; } - if (window->glx.context) + if (window->context.glx.handle) { - _glfw_glXDestroyContext(_glfw.x11.display, window->glx.context); - window->glx.context = NULL; + _glfw_glXDestroyContext(_glfw.x11.display, window->context.glx.handle); + window->context.glx.handle = NULL; } } @@ -540,8 +541,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window) { _glfw_glXMakeCurrent(_glfw.x11.display, - window->glx.window, - window->glx.context); + window->context.glx.window, + window->context.glx.handle); } else _glfw_glXMakeCurrent(_glfw.x11.display, None, NULL); @@ -551,7 +552,7 @@ void _glfwPlatformMakeContextCurrent(_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) @@ -561,7 +562,7 @@ void _glfwPlatformSwapInterval(int interval) if (_glfw.glx.EXT_swap_control) { _glfw.glx.SwapIntervalEXT(_glfw.x11.display, - window->glx.window, + window->context.glx.window, interval); } else if (_glfw.glx.MESA_swap_control) @@ -612,6 +613,6 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle) return NULL; } - return window->glx.context; + return window->context.glx.handle; } diff --git a/src/glx_context.h b/src/glx_context.h index 926e0930..141dfa6c 100644 --- a/src/glx_context.h +++ b/src/glx_context.h @@ -116,7 +116,7 @@ typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); // typedef struct _GLFWcontextGLX { - GLXContext context; + GLXContext handle; GLXWindow window; } _GLFWcontextGLX; diff --git a/src/internal.h b/src/internal.h index 9c6fbaaa..daa573ba 100644 --- a/src/internal.h +++ b/src/internal.h @@ -79,6 +79,7 @@ typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint); typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWctxconfig _GLFWctxconfig; typedef struct _GLFWfbconfig _GLFWfbconfig; +typedef struct _GLFWcontext _GLFWcontext; typedef struct _GLFWwindow _GLFWwindow; typedef struct _GLFWlibrary _GLFWlibrary; 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. */ struct _GLFWwindow @@ -265,19 +286,7 @@ struct _GLFWwindow char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char keys[GLFW_KEY_LAST + 1]; - // OpenGL extensions and context attributes - struct { - int api; - int major, minor, revision; - GLFWbool forward, debug, noerror; - int profile; - int robustness; - int release; - } context; - - PFNGLGETSTRINGIPROC GetStringi; - PFNGLGETINTEGERVPROC GetIntegerv; - PFNGLGETSTRINGPROC GetString; + _GLFWcontext context; struct { GLFWwindowposfun pos; @@ -299,8 +308,6 @@ struct _GLFWwindow // This is defined in the window API's platform.h _GLFW_PLATFORM_WINDOW_STATE; - // This is defined in the context API's context.h - _GLFW_PLATFORM_CONTEXT_STATE; }; diff --git a/src/nsgl_context.h b/src/nsgl_context.h index b9be70f7..97c92244 100644 --- a/src/nsgl_context.h +++ b/src/nsgl_context.h @@ -37,7 +37,7 @@ typedef struct _GLFWcontextNSGL { id pixelFormat; - id context; + id object; } _GLFWcontextNSGL; diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 87a977bc..dbefa2d1 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -195,9 +195,9 @@ int _glfwCreateContext(_GLFWwindow* window, #undef ADD_ATTR #undef ADD_ATTR2 - window->nsgl.pixelFormat = + window->context.nsgl.pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; - if (window->nsgl.pixelFormat == nil) + if (window->context.nsgl.pixelFormat == nil) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "NSGL: Failed to find a suitable pixel format"); @@ -207,19 +207,19 @@ int _glfwCreateContext(_GLFWwindow* window, NSOpenGLContext* share = NULL; if (ctxconfig->share) - share = ctxconfig->share->nsgl.context; + share = ctxconfig->share->context.nsgl.object; - window->nsgl.context = - [[NSOpenGLContext alloc] initWithFormat:window->nsgl.pixelFormat + window->context.nsgl.object = + [[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat shareContext:share]; - if (window->nsgl.context == nil) + if (window->context.nsgl.object == nil) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "NSGL: Failed to create OpenGL context"); return GLFW_FALSE; } - [window->nsgl.context setView:window->ns.view]; + [window->context.nsgl.object setView:window->ns.view]; return GLFW_TRUE; } @@ -227,11 +227,11 @@ int _glfwCreateContext(_GLFWwindow* window, // void _glfwDestroyContext(_GLFWwindow* window) { - [window->nsgl.pixelFormat release]; - window->nsgl.pixelFormat = nil; + [window->context.nsgl.pixelFormat release]; + window->context.nsgl.pixelFormat = nil; - [window->nsgl.context release]; - window->nsgl.context = nil; + [window->context.nsgl.object release]; + window->context.nsgl.object = nil; } @@ -242,7 +242,7 @@ void _glfwDestroyContext(_GLFWwindow* window) void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) - [window->nsgl.context makeCurrentContext]; + [window->context.nsgl.object makeCurrentContext]; else [NSOpenGLContext clearCurrentContext]; @@ -252,7 +252,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window) { // ARP appears to be unnecessary, but this is future-proof - [window->nsgl.context flushBuffer]; + [window->context.nsgl.object flushBuffer]; } void _glfwPlatformSwapInterval(int interval) @@ -260,7 +260,8 @@ void _glfwPlatformSwapInterval(int interval) _GLFWwindow* window = _glfwPlatformGetCurrentContext(); GLint sync = interval; - [window->nsgl.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; + [window->context.nsgl.object setValues:&sync + forParameter:NSOpenGLCPSwapInterval]; } int _glfwPlatformExtensionSupported(const char* extension) @@ -299,6 +300,6 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) return NULL; } - return window->nsgl.context; + return window->context.nsgl.object; } diff --git a/src/wgl_context.c b/src/wgl_context.c index d3e1ca16..de2f15cd 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -89,7 +89,7 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib assert(_glfw.wgl.ARB_pixel_format); - if (!_glfw.wgl.GetPixelFormatAttribivARB(window->wgl.dc, + if (!_glfw.wgl.GetPixelFormatAttribivARB(window->context.wgl.dc, pixelFormat, 0, 1, &attrib, &value)) { @@ -120,7 +120,7 @@ static GLFWbool choosePixelFormat(_GLFWwindow* window, } else { - nativeCount = DescribePixelFormat(window->wgl.dc, + nativeCount = DescribePixelFormat(window->context.wgl.dc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); @@ -192,7 +192,7 @@ static GLFWbool choosePixelFormat(_GLFWwindow* window, // Get pixel format attributes through legacy PFDs - if (!DescribePixelFormat(window->wgl.dc, + if (!DescribePixelFormat(window->context.wgl.dc, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) @@ -327,10 +327,10 @@ int _glfwCreateContext(_GLFWwindow* window, HGLRC share = NULL; if (ctxconfig->share) - share = ctxconfig->share->wgl.context; + share = ctxconfig->share->context.wgl.handle; - window->wgl.dc = GetDC(window->win32.handle); - if (!window->wgl.dc) + window->context.wgl.dc = GetDC(window->win32.handle); + if (!window->context.wgl.dc) { _glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to retrieve DC for window"); @@ -340,14 +340,15 @@ int _glfwCreateContext(_GLFWwindow* window, if (!choosePixelFormat(window, fbconfig, &pixelFormat)) 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, "WGL: Failed to retrieve PFD for selected pixel format"); return GLFW_FALSE; } - if (!SetPixelFormat(window->wgl.dc, pixelFormat, &pfd)) + if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd)) { _glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to set selected pixel format"); @@ -429,10 +430,10 @@ int _glfwCreateContext(_GLFWwindow* window, setWGLattrib(0, 0); - window->wgl.context = _glfw.wgl.CreateContextAttribsARB(window->wgl.dc, - share, - attribs); - if (!window->wgl.context) + window->context.wgl.handle = + _glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc, + share, attribs); + if (!window->context.wgl.handle) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "WGL: Failed to create OpenGL context"); @@ -441,8 +442,9 @@ int _glfwCreateContext(_GLFWwindow* window, } else { - window->wgl.context = _glfw_wglCreateContext(window->wgl.dc); - if (!window->wgl.context) + window->context.wgl.handle = + _glfw_wglCreateContext(window->context.wgl.dc); + if (!window->context.wgl.handle) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "WGL: Failed to create OpenGL context"); @@ -451,7 +453,7 @@ int _glfwCreateContext(_GLFWwindow* window, if (share) { - if (!_glfw_wglShareLists(share, window->wgl.context)) + if (!_glfw_wglShareLists(share, window->context.wgl.handle)) { _glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to enable sharing with specified OpenGL context"); @@ -469,16 +471,16 @@ int _glfwCreateContext(_GLFWwindow* window, // void _glfwDestroyContext(_GLFWwindow* window) { - if (window->wgl.context) + if (window->context.wgl.handle) { - _glfw_wglDeleteContext(window->wgl.context); - window->wgl.context = NULL; + _glfw_wglDeleteContext(window->context.wgl.handle); + window->context.wgl.handle = NULL; } - if (window->wgl.dc) + if (window->context.wgl.dc) { - ReleaseDC(window->win32.handle, window->wgl.dc); - window->wgl.dc = NULL; + ReleaseDC(window->win32.handle, window->context.wgl.dc); + window->context.wgl.dc = NULL; } } @@ -586,7 +588,10 @@ int _glfwAnalyzeContext(_GLFWwindow* window, void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) - _glfw_wglMakeCurrent(window->wgl.dc, window->wgl.context); + { + _glfw_wglMakeCurrent(window->context.wgl.dc, + window->context.wgl.handle); + } else _glfw_wglMakeCurrent(NULL, NULL); @@ -598,19 +603,19 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window) // HACK: Use DwmFlush when desktop composition is enabled if (_glfwIsCompositionEnabled() && !window->monitor) { - int count = abs(window->wgl.interval); + int count = abs(window->context.wgl.interval); while (count--) _glfw_DwmFlush(); } - SwapBuffers(window->wgl.dc); + SwapBuffers(window->context.wgl.dc); } void _glfwPlatformSwapInterval(int interval) { _GLFWwindow* window = _glfwPlatformGetCurrentContext(); - window->wgl.interval = interval; + window->context.wgl.interval = interval; // HACK: Disable WGL swap interval when desktop composition is enabled to // avoid interfering with DWM vsync @@ -639,7 +644,7 @@ int _glfwPlatformExtensionSupported(const char* extension) if (_glfw.wgl.GetExtensionsStringARB) { - extensions = _glfw.wgl.GetExtensionsStringARB(window->wgl.dc); + extensions = _glfw.wgl.GetExtensionsStringARB(window->context.wgl.dc); if (extensions) { if (_glfwStringInExtensionString(extension, extensions)) @@ -675,6 +680,6 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle) return NULL; } - return window->wgl.context; + return window->context.wgl.handle; } diff --git a/src/wgl_context.h b/src/wgl_context.h index 5c38f285..5f9d1e48 100644 --- a/src/wgl_context.h +++ b/src/wgl_context.h @@ -105,8 +105,8 @@ typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); // typedef struct _GLFWcontextWGL { - HDC dc; // Private GDI device context - HGLRC context; // Permanent rendering context + HDC dc; + HGLRC handle; int interval; } _GLFWcontextWGL;