mirror of
https://github.com/yawut/SDL.git
synced 2026-08-28 11:45:13 -05:00
Mac no longer loses OpenGL context when window is hidden.
This fixes an issue that would arise when you minimize / order out an
OpenGL window on Mac, where the window would lose it's window device.
Without a window device, you cannot render to the window.
It does so by making two changes:
- Windows are no longer "oneShot" (which caused their window device to
get destroyed when they're minified or ordered out)
- Windows are no longer "deferred" (which caused the OS to defer
window device creation until the window is shown, which meant that
we couldn't properly makeCurrent to it)
Thanks to http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
This commit is contained in:
@@ -238,16 +238,14 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
|
||||
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
|
||||
|
||||
if (window->flags & SDL_WINDOW_SHOWN) {
|
||||
#ifndef FULLSCREEN_TOGGLEABLE
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
[nscontext setFullScreen];
|
||||
} else
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
[nscontext setFullScreen];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
[nscontext setView:[windowdata->nswindow contentView]];
|
||||
[nscontext update];
|
||||
}
|
||||
{
|
||||
[nscontext setView:[windowdata->nswindow contentView]];
|
||||
[nscontext update];
|
||||
}
|
||||
[nscontext makeCurrentContext];
|
||||
} else {
|
||||
@@ -310,10 +308,7 @@ Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* FIXME: Do we need to get the context for the window? */
|
||||
nscontext = [NSOpenGLContext currentContext];
|
||||
if (nscontext != nil) {
|
||||
[nscontext flushBuffer];
|
||||
}
|
||||
[[NSOpenGLContext currentContext] flushBuffer];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
@@ -591,6 +591,11 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||
SDL_SetKeyboardFocus(data->window);
|
||||
}
|
||||
|
||||
/* Prevents the window's "window device" from being destroyed when it is
|
||||
* hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
|
||||
*/
|
||||
[nswindow setOneShot:NO];
|
||||
|
||||
/* All done! */
|
||||
[pool release];
|
||||
window->driverdata = data;
|
||||
@@ -633,7 +638,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
rect.origin.y -= screenRect.origin.y;
|
||||
}
|
||||
}
|
||||
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
|
||||
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
||||
|
||||
// Create a default view for this window
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
@@ -856,8 +861,10 @@ Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
|
||||
}
|
||||
|
||||
[data->listener close];
|
||||
data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:YES screen:[nswindow screen]];
|
||||
data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
|
||||
[data->nswindow setContentView:[nswindow contentView]];
|
||||
/* See comment in SetupWindowData. */
|
||||
[data->nswindow setOneShot:NO];
|
||||
[data->listener listen:data];
|
||||
|
||||
[nswindow close];
|
||||
|
||||
Reference in New Issue
Block a user