Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Cocoa: Update the current GL context when its window moves or resizes.
Browse files Browse the repository at this point in the history
According to the NSOpenGLContext docs, you need to do this, and we were
 previously masking the need in the SDL_GL_MakeCurrent() implementation.
  • Loading branch information
icculus committed Jul 16, 2011
1 parent 0c68fac commit 7d3f096
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -114,6 +114,7 @@ - (void)windowDidExpose:(NSNotification *)aNotification
- (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]];
Expand All @@ -136,17 +137,28 @@ - (void)windowDidMove:(NSNotification *)aNotification

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);
}

Expand Down Expand Up @@ -683,19 +695,29 @@ - (void)rightMouseDown:(NSEvent *)theEvent
[nswindow setFrameOrigin:rect.origin];
s_moveHack = moveHack;

if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}

[pool release];
}

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];
}

Expand Down Expand Up @@ -738,6 +760,11 @@ - (void)rightMouseDown:(NSEvent *)theEvent
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;

[nswindow zoom:nil];

if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}

[pool release];
}

Expand Down Expand Up @@ -856,6 +883,10 @@ - (void)rightMouseDown:(NSEvent *)theEvent
#endif
[nswindow makeKeyAndOrderFront:nil];

if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
}

[pool release];
}

Expand Down

0 comments on commit 7d3f096

Please sign in to comment.