Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Mac no longer loses OpenGL context when window is hidden.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jorgenpt committed Apr 22, 2013
1 parent fa30d21 commit 0284c3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 7 additions & 12 deletions src/video/cocoa/SDL_cocoaopengl.m
Expand Up @@ -238,16 +238,14 @@
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 {
Expand Down Expand Up @@ -310,10 +308,7 @@
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];
}
Expand Down
11 changes: 9 additions & 2 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -591,6 +591,11 @@ - (void)rightMouseDown:(NSEvent *)theEvent
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;
Expand Down Expand Up @@ -633,7 +638,7 @@ - (void)rightMouseDown:(NSEvent *)theEvent
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]];
Expand Down Expand Up @@ -856,8 +861,10 @@ - (void)rightMouseDown:(NSEvent *)theEvent
}

[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];
Expand Down

0 comments on commit 0284c3e

Please sign in to comment.