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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 803b4ec..5c44e31 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -110,11 +110,19 @@
if ([self view] != [windowdata->nswindow contentView]) {
[self setView:[windowdata->nswindow contentView]];
- [self scheduleUpdate];
+ if (self == [NSOpenGLContext currentContext]) {
+ [self update];
+ } else {
+ [self scheduleUpdate];
+ }
}
} else {
[self clearDrawable];
- [self scheduleUpdate];
+ if (self == [NSOpenGLContext currentContext]) {
+ [self update];
+ } else {
+ [self scheduleUpdate];
+ }
}
}
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 03ece7b..a773cb6 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -49,10 +49,15 @@ static void ConvertNSRect(NSRect *r)
static void
ScheduleContextUpdates(SDL_WindowData *data)
{
+ NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
NSMutableArray *contexts = data->nscontexts;
@synchronized (contexts) {
for (SDLOpenGLContext *context in contexts) {
- [context scheduleUpdate];
+ if (context == currentContext) {
+ [context update];
+ } else {
+ [context scheduleUpdate];
+ }
}
}
}