From d43776502b2fbcbfd0f81b89f77586df9b97cd0d Mon Sep 17 00:00:00 2001 From: Chi-kwan Chan Date: Sun, 26 Apr 2015 06:27:59 -0400 Subject: [PATCH 1/2] Properly restore previous context _glfwPlatformShowWindow(window) and _glfwPlatformUnhideWindow(window) implicitly make the context of window current on OS X Yosemite, which undoes _glfwPlatformMakeContextCurrent(previous). To properly restore the previous context, we call _glfwPlatformMakeContextCurrent(previous) just before glfwCreateWindow() returns. --- src/window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/window.c b/src/window.c index 3acd48c48..c3e7a8180 100644 --- a/src/window.c +++ b/src/window.c @@ -238,9 +238,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); - // Restore the previously current context (or NULL) - _glfwPlatformMakeContextCurrent(previous); - if (wndconfig.monitor) { int width, height; @@ -262,6 +259,9 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, } } + // Restore the previously current context (or NULL) + _glfwPlatformMakeContextCurrent(previous); + return (GLFWwindow*) window; } From 8b042c28e2e7a5a98fb37587c0a413dc42a840fa Mon Sep 17 00:00:00 2001 From: Chi-kwan Chan Date: Sun, 26 Apr 2015 17:39:08 -0400 Subject: [PATCH 2/2] Restore previous context in _glfwPlatformShow/UnhideWindow() for Cocoa [window->ns.object makeKeyAndOrderFront:nil] and [window->ns.object orderFront:nil] seem to implicitly make the context of window current on OS X Yosemite. Hence we get the current context before sending these messages, and restore them afterward. --- src/cocoa_window.m | 4 ++++ src/window.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d005ced23..56ad666b5 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1061,12 +1061,16 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) // should probably not be done every time any window is shown [NSApp activateIgnoringOtherApps:YES]; + _GLFWwindow* previous = _glfwPlatformGetCurrentContext(); [window->ns.object makeKeyAndOrderFront:nil]; + _glfwPlatformMakeContextCurrent(previous); } void _glfwPlatformUnhideWindow(_GLFWwindow* window) { + _GLFWwindow* previous = _glfwPlatformGetCurrentContext(); [window->ns.object orderFront:nil]; + _glfwPlatformMakeContextCurrent(previous); } void _glfwPlatformHideWindow(_GLFWwindow* window) diff --git a/src/window.c b/src/window.c index c3e7a8180..3acd48c48 100644 --- a/src/window.c +++ b/src/window.c @@ -238,6 +238,9 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); + // Restore the previously current context (or NULL) + _glfwPlatformMakeContextCurrent(previous); + if (wndconfig.monitor) { int width, height; @@ -259,9 +262,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, } } - // Restore the previously current context (or NULL) - _glfwPlatformMakeContextCurrent(previous); - return (GLFWwindow*) window; }