Mac: Immediately update current OpenGL context's shape.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Tue, 25 Feb 2014 15:28:12 -0800
changeset 8258569354dec4e9
parent 8257 a1563cbde7a5
child 8259 1816872373d5
Mac: Immediately update current OpenGL context's shape.

Previously we were postponing our -[NSOpenGLContext update] call to the next
SDL_GL_SwapWindow, even if the context was current on the current thread. This
changes it so that we will do the update immediately if it's the current
context.

If you're rendering on another thread, you need to call SDL_GL_SwapWindow once
after a resize event to ensure your drawable will produce non-garbage data.

Bug: https://bugzilla.libsdl.org/show_bug.cgi?id=2339
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Tue Feb 25 17:42:34 2014 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Tue Feb 25 15:28:12 2014 -0800
     1.3 @@ -110,11 +110,19 @@
     1.4  
     1.5          if ([self view] != [windowdata->nswindow contentView]) {
     1.6              [self setView:[windowdata->nswindow contentView]];
     1.7 -            [self scheduleUpdate];
     1.8 +            if (self == [NSOpenGLContext currentContext]) {
     1.9 +                [self update];
    1.10 +            } else {
    1.11 +                [self scheduleUpdate];
    1.12 +            }
    1.13          }
    1.14      } else {
    1.15          [self clearDrawable];
    1.16 -        [self scheduleUpdate];
    1.17 +        if (self == [NSOpenGLContext currentContext]) {
    1.18 +            [self update];
    1.19 +        } else {
    1.20 +            [self scheduleUpdate];
    1.21 +        }
    1.22      }
    1.23  }
    1.24  
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 25 17:42:34 2014 -0300
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 25 15:28:12 2014 -0800
     2.3 @@ -49,10 +49,15 @@
     2.4  static void
     2.5  ScheduleContextUpdates(SDL_WindowData *data)
     2.6  {
     2.7 +    NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
     2.8      NSMutableArray *contexts = data->nscontexts;
     2.9      @synchronized (contexts) {
    2.10          for (SDLOpenGLContext *context in contexts) {
    2.11 -            [context scheduleUpdate];
    2.12 +            if (context == currentContext) {
    2.13 +                [context update];
    2.14 +            } else {
    2.15 +                [context scheduleUpdate];
    2.16 +            }
    2.17          }
    2.18      }
    2.19  }