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.
This commit is contained in:
Chi-kwan Chan 2015-04-26 17:39:08 -04:00
parent d43776502b
commit 8b042c28e2
2 changed files with 7 additions and 3 deletions

View File

@ -1061,12 +1061,16 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
// should probably not be done every time any window is shown // should probably not be done every time any window is shown
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
_GLFWwindow* previous = _glfwPlatformGetCurrentContext();
[window->ns.object makeKeyAndOrderFront:nil]; [window->ns.object makeKeyAndOrderFront:nil];
_glfwPlatformMakeContextCurrent(previous);
} }
void _glfwPlatformUnhideWindow(_GLFWwindow* window) void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{ {
_GLFWwindow* previous = _glfwPlatformGetCurrentContext();
[window->ns.object orderFront:nil]; [window->ns.object orderFront:nil];
_glfwPlatformMakeContextCurrent(previous);
} }
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)

View File

@ -238,6 +238,9 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window); _glfwPlatformSwapBuffers(window);
// Restore the previously current context (or NULL)
_glfwPlatformMakeContextCurrent(previous);
if (wndconfig.monitor) if (wndconfig.monitor)
{ {
int width, height; 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; return (GLFWwindow*) window;
} }