From ce1df1e5dba8bd43c61caf8bd26a1bd49b653bbe Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 16 Jul 2011 11:52:09 -0700 Subject: [PATCH] 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 | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 72db0bbaa..e494d62ad 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -114,6 +114,7 @@ static __inline__ void ConvertNSRect(NSRect *r) - (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 @@ static __inline__ void ConvertNSRect(NSRect *r) 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 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window) [nswindow setFrameOrigin:rect.origin]; s_moveHack = moveHack; + if (window == _this->current_glwin) { + [((NSOpenGLContext *) _this->current_glctx) update]; + } + [pool release]; } @@ -690,12 +706,18 @@ void 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 @@ Cocoa_MaximizeWindow(_THIS, SDL_Window * window) 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 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display #endif [nswindow makeKeyAndOrderFront:nil]; + if (window == _this->current_glwin) { + [((NSOpenGLContext *) _this->current_glctx) update]; + } + [pool release]; }