Allow custom getProcAddress for glad resolution.

PiperOrigin-RevId: 908587023
Change-Id: Idc4dcc5ee8d2d67f83486ca2ff4667f2b4b283eb
This commit is contained in:
Haroon Qureshi
2026-05-01 00:17:41 -07:00
committed by Copybara-Service
parent 7d54123303
commit 0399bfd058
3 changed files with 11 additions and 8 deletions
+9 -6
View File
@@ -86,7 +86,7 @@ static PFNWGLGETPROCADDRESSPROC_PRIVATE mjGladGetProcAddressPtr;
#endif #endif
static static
int mjGlad_open_gl(void) { int mjGlad_open_gl(void* get_proc_address) {
#ifndef IS_UWP #ifndef IS_UWP
mjGlad_libGL = LoadLibraryW(L"opengl32.dll"); mjGlad_libGL = LoadLibraryW(L"opengl32.dll");
if(mjGlad_libGL != NULL) { if(mjGlad_libGL != NULL) {
@@ -164,8 +164,11 @@ static int mjGlad_dl_iterate_callback(struct dl_phdr_info* info, size_t size, vo
return result; return result;
} }
static int mjGlad_open_gl(void) { static int mjGlad_open_gl(void* get_proc_address) {
mjGladGetProcAddressPtr = NULL; mjGladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)get_proc_address;
if (mjGladGetProcAddressPtr != NULL) {
return 1;
}
// We try to load a GetProcAddress symbol that's already been loaded into the process first. // We try to load a GetProcAddress symbol that's already been loaded into the process first.
// Since MuJoCo relies on user code to set up a working OpenGL environment, one of these symbols // Since MuJoCo relies on user code to set up a working OpenGL environment, one of these symbols
@@ -224,7 +227,7 @@ static int mjGlad_open_gl(void) {
return mjGladGetProcAddressPtr ? 1 : 0; return mjGladGetProcAddressPtr ? 1 : 0;
} }
#else #else
static int mjGlad_open_gl(void) { static int mjGlad_open_gl(void* get_proc_address) {
static const char *NAMES[] = { static const char *NAMES[] = {
"../Frameworks/OpenGL.framework/OpenGL", "../Frameworks/OpenGL.framework/OpenGL",
"/Library/Frameworks/OpenGL.framework/OpenGL", "/Library/Frameworks/OpenGL.framework/OpenGL",
@@ -1490,8 +1493,8 @@ static void mjGlad_find_coreGL(void) {
} }
} }
int mjGladLoadGLUnsafe(void) { int mjGladLoadGLUnsafe(void* get_proc_address) {
if (mjGlad_open_gl()) { if (mjGlad_open_gl(get_proc_address)) {
mjGLVersion.major = 0; mjGLVersion.minor = 0; mjGLVersion.major = 0; mjGLVersion.minor = 0;
glGetString = (PFNGLGETSTRINGPROC)mjGlad_get_proc("glGetString"); glGetString = (PFNGLGETSTRINGPROC)mjGlad_get_proc("glGetString");
if (glGetString == NULL) return 0; if (glGetString == NULL) return 0;
+1 -1
View File
@@ -114,7 +114,7 @@ GLAPI struct gladGLversionStruct mjGLVersion;
GLAPI int mjGladLoadGL(void); GLAPI int mjGladLoadGL(void);
GLAPI int mjGladLoadGLUnsafe(void) MJGLAD_NOEXCEPT; GLAPI int mjGladLoadGLUnsafe(void*) MJGLAD_NOEXCEPT;
typedef unsigned int GLenum; typedef unsigned int GLenum;
typedef unsigned char GLboolean; typedef unsigned char GLboolean;
+1 -1
View File
@@ -17,7 +17,7 @@
extern "C" { extern "C" {
GLAPI int mjGladLoadGL() { GLAPI int mjGladLoadGL() {
static const int glad_initialized = mjGladLoadGLUnsafe(); static const int glad_initialized = mjGladLoadGLUnsafe(nullptr);
return glad_initialized; return glad_initialized;
} }