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.
This commit is contained in:
Ryan C. Gordon 2011-07-16 11:52:09 -07:00
parent 34edc62460
commit 0b3c783570

View file

@ -114,6 +114,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
- (void)windowDidMove:(NSNotification *)aNotification - (void)windowDidMove:(NSNotification *)aNotification
{ {
int x, y; int x, y;
SDL_VideoDevice *device = SDL_GetVideoDevice();
SDL_Window *window = _data->window; SDL_Window *window = _data->window;
NSWindow *nswindow = _data->nswindow; NSWindow *nswindow = _data->nswindow;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
@ -136,17 +137,28 @@ static __inline__ void ConvertNSRect(NSRect *r)
x = (int)rect.origin.x; x = (int)rect.origin.x;
y = (int)rect.origin.y; y = (int)rect.origin.y;
if (window == device->current_glwin) {
[((NSOpenGLContext *) device->current_glctx) update];
}
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
} }
- (void)windowDidResize:(NSNotification *)aNotification - (void)windowDidResize:(NSNotification *)aNotification
{ {
SDL_VideoDevice *device = SDL_GetVideoDevice();
int w, h; int w, h;
NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]]; NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
w = (int)rect.size.width; w = (int)rect.size.width;
h = (int)rect.size.height; h = (int)rect.size.height;
if (SDL_IsShapedWindow(_data->window)) if (SDL_IsShapedWindow(_data->window))
Cocoa_ResizeWindowShape(_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); SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
} }
@ -683,6 +695,10 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
[nswindow setFrameOrigin:rect.origin]; [nswindow setFrameOrigin:rect.origin];
s_moveHack = moveHack; s_moveHack = moveHack;
if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}
[pool release]; [pool release];
} }
@ -690,12 +706,18 @@ void
Cocoa_SetWindowSize(_THIS, SDL_Window * window) Cocoa_SetWindowSize(_THIS, SDL_Window * window)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 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; NSSize size;
size.width = window->w; size.width = window->w;
size.height = window->h; size.height = window->h;
[nswindow setContentSize:size]; [nswindow setContentSize:size];
if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}
[pool release]; [pool release];
} }
@ -738,6 +760,11 @@ Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
[nswindow zoom:nil]; [nswindow zoom:nil];
if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}
[pool release]; [pool release];
} }
@ -856,6 +883,10 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
#endif #endif
[nswindow makeKeyAndOrderFront:nil]; [nswindow makeKeyAndOrderFront:nil];
if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}
[pool release]; [pool release];
} }