diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index a1686219b..4fc478330 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -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]; } diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 47dc1052e..0ebb3c94a 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -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];