Fixed bug 1958 - Cocoa SwapWindow doesn't swap the specified window
authorSam Lantinga <slouken@libsdl.org>
Thu, 11 Jul 2013 21:51:09 -0700
changeset 7408c50e165abfdf
parent 7407 db8a19d767d7
child 7409 8b5ae6ff6a49
Fixed bug 1958 - Cocoa SwapWindow doesn't swap the specified window

Ryan C. Gordon

We have this in Cocoa_GL_SwapWindow()...

/* FIXME: Do we need to get the context for the window? */
[[NSOpenGLContext currentContext] flushBuffer];

...which means if the current GL context is not the one in (window), we swap a different one than requested.

Right now, we don't store information about which context is assigned to which window, and the OS doesn't give you a way to retrieve it from an NSView. We would have to track this per-window during SDL_GL_MakeCurrent() (and SDL_GL_CreateContext) calls.
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoawindow.h
     1.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Thu Jul 11 23:59:09 2013 -0400
     1.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Thu Jul 11 21:51:09 2013 -0700
     1.3 @@ -212,6 +212,7 @@
     1.4          SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
     1.5          NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
     1.6  
     1.7 +        windowdata->nscontext = nscontext;
     1.8          if ([nscontext view] != [windowdata->nswindow contentView]) {
     1.9              [nscontext setView:[windowdata->nswindow contentView]];
    1.10              [nscontext update];
    1.11 @@ -272,12 +273,12 @@
    1.12  Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
    1.13  {
    1.14      NSAutoreleasePool *pool;
    1.15 -    NSOpenGLContext *nscontext;
    1.16 +    SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
    1.17 +    NSOpenGLContext *nscontext = windowdata->nscontext;
    1.18  
    1.19      pool = [[NSAutoreleasePool alloc] init];
    1.20  
    1.21 -    /* FIXME: Do we need to get the context for the window? */
    1.22 -    [[NSOpenGLContext currentContext] flushBuffer];
    1.23 +    [nscontext flushBuffer];
    1.24  
    1.25      [pool release];
    1.26  }
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Thu Jul 11 23:59:09 2013 -0400
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Thu Jul 11 21:51:09 2013 -0700
     2.3 @@ -86,6 +86,7 @@
     2.4  {
     2.5      SDL_Window *window;
     2.6      NSWindow *nswindow;
     2.7 +    NSOpenGLContext *nscontext;
     2.8      SDL_bool created;
     2.9      Cocoa_WindowListener *listener;
    2.10      struct SDL_VideoData *videodata;