Skip to content

Commit

Permalink
cocoa: Fix OpenGL rendering on macOS 10.14 ("Mojave").
Browse files Browse the repository at this point in the history
Fixes Bugzilla #4272.
  • Loading branch information
icculus committed Oct 18, 2018
1 parent eac3fd2 commit f677377
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -632,8 +632,6 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
_data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
SDL_ToggleModState(KMOD_CAPS, newflags != 0);

ScheduleContextUpdates(_data);
}

- (void)windowDidResignKey:(NSNotification *)aNotification
Expand Down Expand Up @@ -1145,14 +1143,18 @@ - (void)rightMouseDown:(NSEvent *)theEvent;
- (BOOL)mouseDownCanMoveWindow;
- (void)drawRect:(NSRect)dirtyRect;
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
- (BOOL)wantsUpdateLayer;
- (void)updateLayer;
@end

@implementation SDLView

- (void)setSDLWindow:(SDL_Window*)window
{
_sdlWindow = window;
}

/* this is used on older macOS revisions. 10.8 and later use updateLayer. */
- (void)drawRect:(NSRect)dirtyRect
{
/* Force the graphics context to clear to black so we don't get a flash of
Expand All @@ -1163,6 +1165,21 @@ - (void)drawRect:(NSRect)dirtyRect
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}

-(BOOL) wantsUpdateLayer
{
return YES;
}

-(void) updateLayer
{
/* Force the graphics context to clear to black so we don't get a flash of
white until the app is ready to draw. In practice on modern macOS, this
only gets called for window creation and other extraordinary events. */
self.layer.backgroundColor = NSColor.blackColor.CGColor;
ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}

- (void)rightMouseDown:(NSEvent *)theEvent
{
[[self nextResponder] rightMouseDown:theEvent];
Expand Down Expand Up @@ -1345,6 +1362,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
[contentView setWantsBestResolutionOpenGLSurface:YES];
}
}

#if SDL_VIDEO_OPENGL_ES2
#if SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) &&
Expand Down

0 comments on commit f677377

Please sign in to comment.