From 2bd21b588e8f0a200e31f370d80275f9a565a3a5 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:57:27 +0300 Subject: [PATCH] [macOS] Load OpenGL.framework by path to avoid issues with non-Latin executable names. --- platform/macos/gl_manager_macos_legacy.h | 1 + platform/macos/gl_manager_macos_legacy.mm | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/platform/macos/gl_manager_macos_legacy.h b/platform/macos/gl_manager_macos_legacy.h index af9be8f5ba2..383c5c3306c 100644 --- a/platform/macos/gl_manager_macos_legacy.h +++ b/platform/macos/gl_manager_macos_legacy.h @@ -62,6 +62,7 @@ class GLManagerLegacy_MacOS { Error create_context(GLWindow &win); + bool framework_loaded = false; bool use_vsync = false; CGLEnablePtr CGLEnable = nullptr; CGLSetParameterPtr CGLSetParameter = nullptr; diff --git a/platform/macos/gl_manager_macos_legacy.mm b/platform/macos/gl_manager_macos_legacy.mm index 6ce3831d9c4..a0d037144e2 100644 --- a/platform/macos/gl_manager_macos_legacy.mm +++ b/platform/macos/gl_manager_macos_legacy.mm @@ -32,6 +32,7 @@ #if defined(MACOS_ENABLED) && defined(GLES3_ENABLED) +#include #include #include @@ -156,7 +157,7 @@ void GLManagerLegacy_MacOS::window_set_per_pixel_transparency_enabled(DisplaySer } Error GLManagerLegacy_MacOS::initialize() { - return OK; + return framework_loaded ? OK : ERR_CANT_CREATE; } void GLManagerLegacy_MacOS::set_use_vsync(bool p_use) { @@ -186,12 +187,17 @@ NSOpenGLContext *GLManagerLegacy_MacOS::get_context(DisplayServer::WindowID p_wi } GLManagerLegacy_MacOS::GLManagerLegacy_MacOS() { - CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); - CFBundleLoadExecutable(framework); + NSBundle *framework = [NSBundle bundleWithPath:@"/System/Library/Frameworks/OpenGL.framework"]; + if (framework) { + void *library_handle = dlopen([framework.executablePath UTF8String], RTLD_NOW); + if (library_handle) { + CGLEnable = (CGLEnablePtr)dlsym(library_handle, "CGLEnable"); + CGLSetParameter = (CGLSetParameterPtr)dlsym(library_handle, "CGLSetParameter"); + CGLGetCurrentContext = (CGLGetCurrentContextPtr)dlsym(library_handle, "CGLGetCurrentContext"); - CGLEnable = (CGLEnablePtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLEnable")); - CGLSetParameter = (CGLSetParameterPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLSetParameter")); - CGLGetCurrentContext = (CGLGetCurrentContextPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLGetCurrentContext")); + framework_loaded = CGLEnable && CGLSetParameter && CGLGetCurrentContext; + } + } } GLManagerLegacy_MacOS::~GLManagerLegacy_MacOS() {