From ba0726e3dcba141cc3c7838865afa274edad813e Mon Sep 17 00:00:00 2001 From: bearishsun Date: Wed, 26 Dec 2018 09:30:50 +0100 Subject: [PATCH] Bugfix: Fix OpenGL not rendering in macOS Mojave --- .../bsfCore/Private/MacOS/BsMacOSWindow.h | 3 +++ .../bsfCore/Private/MacOS/BsMacOSWindow.mm | 23 +++++++++++++++++++ .../bsfGLRenderAPI/MacOS/BsMacOSContext.mm | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.h b/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.h index 0a592810e..fdec2296f 100644 --- a/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.h +++ b/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.h @@ -151,6 +151,9 @@ namespace bs */ void _unregisterForDragAndDrop(); + /** Lets the window know that the provided OpenGL context will be rendering to it. */ + void _registerGLContext(void* context); + /** Returns internal private data for use by friends. */ Pimpl* _getPrivateData() const { return m; } diff --git a/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.mm b/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.mm index 777ab8e3c..b1632b0ed 100644 --- a/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.mm +++ b/Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.mm @@ -1,6 +1,7 @@ //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// #define BS_COCOA_INTERNALS 1 +#define GL_SILENCE_DEPRECATION 1 #include "Private/MacOS/BsMacOSWindow.h" #include "Private/MacOS/BsMacOSPlatform.h" #include "Private/MacOS/BsMacOSDropTarget.h" @@ -49,12 +50,14 @@ static bool keyCodeToInputCommand(uint32_t keyCode, bool shift, bs::InputCommand @interface BSView : NSView -(void)rightMouseDown:(NSEvent*) event; -(void)setBackgroundImage:(NSImage*)image; +-(void)setGLContext:(NSOpenGLContext*)context; @end @implementation BSView { NSTrackingArea* mTrackingArea; NSImageView* mImageView; + NSOpenGLContext* mGLContext; } -(id)init @@ -63,10 +66,24 @@ -(id)init mTrackingArea = nil; mImageView = nil; + mGLContext = nil; return self; } +-(void)setLayer:(CALayer*)layer +{ + [super setLayer:layer]; + + if(mGLContext) + [mGLContext update]; +} + +-(void)setGLContext:(NSOpenGLContext*)context +{ + mGLContext = context; +} + -(void)resetCursorRects { [super resetCursorRects]; @@ -883,4 +900,10 @@ - (BOOL)performDragOperation:(id )sender if(m->numDropTargets == 0) [m->window unregisterDraggedTypes]; } + + void CocoaWindow::_registerGLContext(void* context) + { + NSOpenGLContext* glContext = (__bridge_transfer NSOpenGLContext* )context; + [m->view setGLContext:glContext]; + } } diff --git a/Source/Plugins/bsfGLRenderAPI/MacOS/BsMacOSContext.mm b/Source/Plugins/bsfGLRenderAPI/MacOS/BsMacOSContext.mm index 611b60562..c366370d6 100644 --- a/Source/Plugins/bsfGLRenderAPI/MacOS/BsMacOSContext.mm +++ b/Source/Plugins/bsfGLRenderAPI/MacOS/BsMacOSContext.mm @@ -78,8 +78,9 @@ return; } - NSWindow* nsWindow = window->_getPrivateData()->window; + window->_registerGLContext((__bridge_retained void*) m->context); + NSWindow* nsWindow = window->_getPrivateData()->window; [m->context setView:[nsWindow contentView]]; [m->context makeCurrentContext]; [m->context update];