From 79d10022616555eed4c1e792990ff4e1e38bc011 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 12 Dec 2019 19:03:21 +0200 Subject: [PATCH] Restore parts of #33783 and #32809 missing after rebase. --- .travis.yml | 2 +- platform/osx/context_gl_osx.h | 4 --- platform/osx/context_gl_osx.mm | 58 ++++------------------------------ platform/osx/os_osx.mm | 14 +++----- 4 files changed, 13 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52c804f5a20..a03ee2a0aaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,7 @@ matrix: - name: macOS editor (debug, Clang) stage: build - env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra werror=yes" + env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra" # werror=yes os: osx compiler: clang diff --git a/platform/osx/context_gl_osx.h b/platform/osx/context_gl_osx.h index 831a813fe9c..6fb6b532758 100644 --- a/platform/osx/context_gl_osx.h +++ b/platform/osx/context_gl_osx.h @@ -51,10 +51,6 @@ class ContextGL_OSX { NSOpenGLContext *context; public: - bool waiting_for_vsync; - NSCondition *vsync_condition; - CVDisplayLinkRef displayLink; - void release_current(); void make_current(); diff --git a/platform/osx/context_gl_osx.mm b/platform/osx/context_gl_osx.mm index 425c9b0ac40..013c34ff2e3 100644 --- a/platform/osx/context_gl_osx.mm +++ b/platform/osx/context_gl_osx.mm @@ -32,21 +32,6 @@ #if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) -// DisplayLinkCallback is called from our DisplayLink OS thread informing us right before -// a screen update is required. We can use it to work around the broken vsync. -static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) { - ContextGL_OSX *gl_ctx = (ContextGL_OSX *)displayLinkContext; - - // Set flag so we know we can output our next frame and signal our conditional lock - // if we're not doing vsync this will be ignored - [gl_ctx->vsync_condition lock]; - gl_ctx->waiting_for_vsync = false; - [gl_ctx->vsync_condition signal]; - [gl_ctx->vsync_condition unlock]; - - return kCVReturnSuccess; -} - void ContextGL_OSX::release_current() { [NSOpenGLContext clearCurrentContext]; @@ -79,31 +64,17 @@ int ContextGL_OSX::get_window_height() { void ContextGL_OSX::swap_buffers() { - if (use_vsync) { - // Wait until our DisplayLink callback unsets our flag... - [vsync_condition lock]; - while (waiting_for_vsync) - [vsync_condition wait]; - - // Make sure we wait again next frame around - waiting_for_vsync = true; - - [vsync_condition unlock]; - } - [context flushBuffer]; } void ContextGL_OSX::set_use_vsync(bool p_use) { - // CGLCPSwapInterval broke in OSX 10.14 and it seems Apple is not interested in fixing - // it as OpenGL is now deprecated and Metal solves this differently. - // Following SDLs example we're working around this using DisplayLink - // When vsync is enabled we set a flag "waiting_for_vsync" to true. - // This flag is set to false when DisplayLink informs us our display is about to refresh. - ///TODO Maybe pause/unpause display link? - use_vsync = p_use; - waiting_for_vsync = p_use; + CGLContextObj ctx = CGLGetCurrentContext(); + if (ctx) { + GLint swapInterval = p_use ? 1 : 0; + CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval); + use_vsync = p_use; + } } bool ContextGL_OSX::is_using_vsync() const { @@ -186,15 +157,6 @@ Error ContextGL_OSX::initialize() { [context makeCurrentContext]; - // setup our display link, this will inform us when a refresh is needed - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - CVDisplayLinkSetOutputCallback(displayLink, &DisplayLinkCallback, this); - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, context.CGLContextObj, pixelFormat.CGLPixelFormatObj); - CVDisplayLinkStart(displayLink); - - // initialise a conditional lock object - vsync_condition = [[NSCondition alloc] init]; - return OK; } @@ -205,12 +167,6 @@ ContextGL_OSX::ContextGL_OSX(id p_view, bool p_opengl_3_context) { use_vsync = false; } -ContextGL_OSX::~ContextGL_OSX() { - - if (displayLink) { - CVDisplayLinkRelease(displayLink); - } - [vsync_condition release]; -} +ContextGL_OSX::~ContextGL_OSX() {} #endif diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 9cda9fcf296..915a6bf2fd5 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1524,7 +1524,11 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a #endif [window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; } else { - [window_view setWantsBestResolutionOpenGLSurface:NO]; +#if defined(OPENGL_ENABLED) + if (video_driver_index == VIDEO_DRIVER_GLES2) { + [window_view setWantsBestResolutionOpenGLSurface:NO]; + } +#endif } [window_object setContentView:window_view]; @@ -2957,14 +2961,6 @@ Error OS_OSX::move_to_trash(const String &p_path) { } void OS_OSX::_set_use_vsync(bool p_enable) { - // FIXME: Commented out during rebase of vulkan branch on master. - /* - CGLContextObj ctx = CGLGetCurrentContext(); - if (ctx) { - GLint swapInterval = p_enable ? 1 : 0; - CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval); - } - */ #if defined(OPENGL_ENABLED) if (video_driver_index == VIDEO_DRIVER_GLES2) { if (context_gles2)