Cocoa: Update the current GL context when its window moves or resizes.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Jul 2011 11:52:09 -0700
changeset 5564 7ed38a8ad304
parent 5563 2a152e7e82f2
child 5566 0d221d6ffac8
Cocoa: Update the current GL context when its window moves or resizes. According to the NSOpenGLContext docs, you need to do this, and we were previously masking the need in the SDL_GL_MakeCurrent() implementation.
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Fri Jul 15 17:05:32 2011 -0700
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 16 11:52:09 2011 -0700
@@ -114,6 +114,7 @@
 - (void)windowDidMove:(NSNotification *)aNotification
 {
     int x, y;
+    SDL_VideoDevice *device = SDL_GetVideoDevice();
     SDL_Window *window = _data->window;
     NSWindow *nswindow = _data->nswindow;
     NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
@@ -136,17 +137,28 @@
 
     x = (int)rect.origin.x;
     y = (int)rect.origin.y;
+
+    if (window == device->current_glwin) {
+        [((NSOpenGLContext *) device->current_glctx) update];
+    }
+
     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
 }
 
 - (void)windowDidResize:(NSNotification *)aNotification
 {
+    SDL_VideoDevice *device = SDL_GetVideoDevice();
     int w, h;
     NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
     w = (int)rect.size.width;
     h = (int)rect.size.height;
     if (SDL_IsShapedWindow(_data->window))
         Cocoa_ResizeWindowShape(_data->window);
+
+    if (_data->window == device->current_glwin) {
+        [((NSOpenGLContext *) device->current_glctx) update];
+    }
+
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
 }
 
@@ -683,6 +695,10 @@
     [nswindow setFrameOrigin:rect.origin];
     s_moveHack = moveHack;
 
+    if (window == _this->current_glwin) {
+        [((NSOpenGLContext *) _this->current_glctx) update];
+    }
+
     [pool release];
 }
 
@@ -690,12 +706,18 @@
 Cocoa_SetWindowSize(_THIS, SDL_Window * window)
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+    NSWindow *nswindow = windata->nswindow;
     NSSize size;
 
     size.width = window->w;
     size.height = window->h;
     [nswindow setContentSize:size];
+
+    if (window == _this->current_glwin) {
+        [((NSOpenGLContext *) _this->current_glctx) update];
+    }
+
     [pool release];
 }
 
@@ -738,6 +760,11 @@
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
 
     [nswindow zoom:nil];
+
+    if (window == _this->current_glwin) {
+        [((NSOpenGLContext *) _this->current_glctx) update];
+    }
+
     [pool release];
 }
 
@@ -856,6 +883,10 @@
 #endif
     [nswindow makeKeyAndOrderFront:nil];
 
+    if (window == _this->current_glwin) {
+        [((NSOpenGLContext *) _this->current_glctx) update];
+    }
+
     [pool release];
 }