mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-29 20:27:12 +01:00
macOS: Fix the initial window background not being black since macOS 10.14.2 or so, when OpenGL is used (bug #4810). Also fixes "CGContext: invalid context 0x0" errors when an OpenGL window is created (bug #4470).
This commit is contained in:
parent
009226c61e
commit
074f6a512d
@ -1266,23 +1266,32 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
|||||||
_sdlWindow = window;
|
_sdlWindow = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is used on older macOS revisions. 10.8 and later use updateLayer. */
|
/* this is used on older macOS revisions, and newer ones which emulate old
|
||||||
|
NSOpenGLContext behaviour while still using a layer under the hood. 10.8 and
|
||||||
|
later use updateLayer, up until 10.14.2 or so, which uses drawRect without
|
||||||
|
a GraphicsContext and with a layer active instead (for OpenGL contexts). */
|
||||||
- (void)drawRect:(NSRect)dirtyRect
|
- (void)drawRect:(NSRect)dirtyRect
|
||||||
{
|
{
|
||||||
/* Force the graphics context to clear to black so we don't get a flash of
|
/* 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
|
white until the app is ready to draw. In practice on modern macOS, this
|
||||||
only gets called for window creation and other extraordinary events. */
|
only gets called for window creation and other extraordinary events. */
|
||||||
[[NSColor blackColor] setFill];
|
if ([NSGraphicsContext currentContext]) {
|
||||||
NSRectFill(dirtyRect);
|
[[NSColor blackColor] setFill];
|
||||||
|
NSRectFill(dirtyRect);
|
||||||
|
} else if (self.layer) {
|
||||||
|
self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL) wantsUpdateLayer
|
- (BOOL)wantsUpdateLayer
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) updateLayer
|
/* This is also called when a Metal layer is active. */
|
||||||
|
- (void)updateLayer
|
||||||
{
|
{
|
||||||
/* Force the graphics context to clear to black so we don't get a flash of
|
/* 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
|
white until the app is ready to draw. In practice on modern macOS, this
|
||||||
|
Loading…
Reference in New Issue
Block a user