Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Fix OpenGL flickering. #56059

Merged
merged 1 commit into from
Dec 21, 2021
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 platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class OS_OSX : public OS_Unix {
int key_event_pos;

bool force_quit;
bool is_resizing = false;
// rasterizer seems to no longer be given to visual server, its using GLES3 directly?
//Rasterizer *rasterizer;
VisualServer *visual_server;
Expand Down
18 changes: 11 additions & 7 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ - (void)windowDidChangeBackingProperties:(NSNotification *)notification {
}
}

- (void)windowWillStartLiveResize:(NSNotification *)notification {
OS_OSX::singleton->is_resizing = true;
}

- (void)windowDidEndLiveResize:(NSNotification *)notification {
OS_OSX::singleton->is_resizing = false;
}

- (void)windowDidResize:(NSNotification *)notification {
[OS_OSX::singleton->context update];

Expand Down Expand Up @@ -1676,11 +1684,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
CGLSetParameter((CGLContextObj)[context CGLContextObj], kCGLCPSurfaceBackingSize, &dim[0]);
CGLEnable((CGLContextObj)[context CGLContextObj], kCGLCESurfaceBackingSize);

if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
CGLError err = CGLEnable((CGLContextObj)[context CGLContextObj], kCGLCEMPEngine); // Enable multithreading.
ERR_FAIL_COND_V(err != kCGLNoError, ERR_UNAVAILABLE);
}

set_use_vsync(p_desired.use_vsync);

if (!is_no_window_mode_enabled()) {
Expand Down Expand Up @@ -2440,7 +2443,7 @@ virtual void log_error(const char *p_function, const char *p_file, int p_line, c

void OS_OSX::set_offscreen_gl_current(bool p_current) {
if (p_current) {
[context makeCurrentContext];
[context_offscreen makeCurrentContext];
} else {
[NSOpenGLContext clearCurrentContext];
}
Expand Down Expand Up @@ -3309,8 +3312,9 @@ void _update_keyboard_layouts() {

void OS_OSX::pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopActivity p_activiy, void *p_context) {
// Prevent main loop from sleeping and redraw window during resize / modal popups.
// Do not redraw when rendering is done from the separate thread, it will conflict with the OpenGL context updates triggered by window view resize.

if (get_singleton()->get_main_loop()) {
if (get_singleton()->get_main_loop() && (get_singleton()->get_render_thread_mode() != RENDER_SEPARATE_THREAD || !OS_OSX::singleton->is_resizing)) {
Main::force_redraw();
if (!Main::is_iterating()) { // Avoid cyclic loop.
Main::iteration();
Expand Down