Skip to content

Commit 7cf8e5e

Browse files
committed
Merge pull request #95235 from bruvzg/macos_opengl_load
[macOS] Load OpenGL.framework by path to avoid issues with non-Latin executable names.
2 parents 17f3d35 + 2bd21b5 commit 7cf8e5e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

platform/macos/gl_manager_macos_legacy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class GLManagerLegacy_MacOS {
6262

6363
Error create_context(GLWindow &win);
6464

65+
bool framework_loaded = false;
6566
bool use_vsync = false;
6667
CGLEnablePtr CGLEnable = nullptr;
6768
CGLSetParameterPtr CGLSetParameter = nullptr;

platform/macos/gl_manager_macos_legacy.mm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
3434

35+
#include <dlfcn.h>
3536
#include <stdio.h>
3637
#include <stdlib.h>
3738

@@ -156,7 +157,7 @@
156157
}
157158

158159
Error GLManagerLegacy_MacOS::initialize() {
159-
return OK;
160+
return framework_loaded ? OK : ERR_CANT_CREATE;
160161
}
161162

162163
void GLManagerLegacy_MacOS::set_use_vsync(bool p_use) {
@@ -186,12 +187,17 @@
186187
}
187188

188189
GLManagerLegacy_MacOS::GLManagerLegacy_MacOS() {
189-
CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
190-
CFBundleLoadExecutable(framework);
191-
192-
CGLEnable = (CGLEnablePtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLEnable"));
193-
CGLSetParameter = (CGLSetParameterPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLSetParameter"));
194-
CGLGetCurrentContext = (CGLGetCurrentContextPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLGetCurrentContext"));
190+
NSBundle *framework = [NSBundle bundleWithPath:@"/System/Library/Frameworks/OpenGL.framework"];
191+
if (framework) {
192+
void *library_handle = dlopen([framework.executablePath UTF8String], RTLD_NOW);
193+
if (library_handle) {
194+
CGLEnable = (CGLEnablePtr)dlsym(library_handle, "CGLEnable");
195+
CGLSetParameter = (CGLSetParameterPtr)dlsym(library_handle, "CGLSetParameter");
196+
CGLGetCurrentContext = (CGLGetCurrentContextPtr)dlsym(library_handle, "CGLGetCurrentContext");
197+
198+
framework_loaded = CGLEnable && CGLSetParameter && CGLGetCurrentContext;
199+
}
200+
}
195201
}
196202

197203
GLManagerLegacy_MacOS::~GLManagerLegacy_MacOS() {

0 commit comments

Comments
 (0)