Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cocos/platform/CCGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ class CC_DLL GLView : public Ref

#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
virtual id getCocoaWindow() = 0;
virtual id getNSGLContext() = 0; // stevetranby: added
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) */

/**
Expand Down
1 change: 1 addition & 0 deletions cocos/platform/desktop/CCGLViewImpl-desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CC_DLL GLViewImpl : public GLView

#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
id getCocoaWindow() override { return glfwGetCocoaWindow(_mainWindow); }
id getNSGLContext() override { return glfwGetNSGLContext(_mainWindow); } // stevetranby: added
#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)

protected:
Expand Down
14 changes: 12 additions & 2 deletions cocos/platform/mac/CCApplication-mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,21 @@ static long getCurrentMillSecond()

// Retain glview to avoid glview being released in the while loop
glview->retain();


unsigned int ctx_updated_count = 0;

while (!glview->windowShouldClose())
{
lastTime = getCurrentMillSecond();


// hack to fix issue #19080, black screen on macOS 10.14
// stevetranby: look into doing this outside loop to get rid of condition test per frame
if(ctx_updated_count < 2) {
ctx_updated_count++;
NSOpenGLContext* ctx = (NSOpenGLContext*)glview->getNSGLContext();
[ctx update];
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better that these codes only run on macOS 10.14 + Xcode 10.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code block be executed only in the first time of main loop, for a fixed little time, not executed every frame. and add version check will make the main loop code looks more complex , so I think it's ok without version check.

director->mainLoop();
glview->pollEvents();

Expand Down