Merge pull request #95235 from bruvzg/macos_opengl_load

[macOS] Load OpenGL.framework by path to avoid issues with non-Latin executable names.
This commit is contained in:
Rémi Verschelde 2024-08-07 12:08:07 +02:00
commit 7cf8e5ef2b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 13 additions and 6 deletions

View File

@ -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;

View File

@ -32,6 +32,7 @@
#if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
@ -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() {