Skip to content

Commit

Permalink
Bugfix: Fix OpenGL not rendering in macOS Mojave
Browse files Browse the repository at this point in the history
  • Loading branch information
bearishsun committed Dec 26, 2018
1 parent 87d6ab6 commit ba0726e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
23 changes: 23 additions & 0 deletions Source/Foundation/bsfCore/Private/MacOS/BsMacOSWindow.mm
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -883,4 +900,10 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
if(m->numDropTargets == 0)
[m->window unregisterDraggedTypes];
}

void CocoaWindow::_registerGLContext(void* context)
{
NSOpenGLContext* glContext = (__bridge_transfer NSOpenGLContext* )context;
[m->view setGLContext:glContext];
}
}
3 changes: 2 additions & 1 deletion Source/Plugins/bsfGLRenderAPI/MacOS/BsMacOSContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit ba0726e

Please sign in to comment.