Don't repeatedly dlopen OpenGL library when retrieving address for OpenGL functions

This commit is contained in:
UnknownShadow200 2020-06-12 22:34:01 +10:00
parent 76f25b78b0
commit cde14930d7
3 changed files with 12 additions and 14 deletions

View File

@ -1477,17 +1477,6 @@ cc_result DynamicLib_Get(void* lib, const char* name, void** symbol) {
return *symbol == NULL; return *symbol == NULL;
} }
void* DynamicLib_GetFrom(const char* filename, const char* name) {
void* lib;
String path;
path = String_FromReadonly(filename);
lib = DynamicLib_Load2(&path);
if (!lib) return NULL;
return DynamicLib_Get2(lib, name);
}
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------* *--------------------------------------------------------Platform---------------------------------------------------------*

View File

@ -86,7 +86,6 @@ CC_API void* DynamicLib_Load2(const String* path);
/* Attempts to get the address of the symbol in the given dynamic library. */ /* Attempts to get the address of the symbol in the given dynamic library. */
/* NOTE: Do NOT use this to load OpenGL functions, use GLContext_GetAddress. */ /* NOTE: Do NOT use this to load OpenGL functions, use GLContext_GetAddress. */
CC_API void* DynamicLib_Get2(void* lib, const char* name); CC_API void* DynamicLib_Get2(void* lib, const char* name);
void* DynamicLib_GetFrom(const char* filename, const char* name); /* OBSOLETE */
/* Outputs more detailed information about errors with the DynamicLib functions. */ /* Outputs more detailed information about errors with the DynamicLib functions. */
/* NOTE: You MUST call this immediately after DynamicLib_Load2/DynamicLib_Get2 returns NULL. */ /* NOTE: You MUST call this immediately after DynamicLib_Load2/DynamicLib_Get2 returns NULL. */
CC_API cc_bool DynamicLib_DescribeError(String* dst); CC_API cc_bool DynamicLib_DescribeError(String* dst);

View File

@ -4356,7 +4356,12 @@ void GLContext_Free(void) {
} }
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
void* addr = DynamicLib_GetFrom("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", function); static const String glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
static void* lib;
void* addr;
if (!lib) lib = DynamicLib_Load2(&glPath);
addr = DynamicLib_Get2(lib, function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr; return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }
@ -4433,7 +4438,12 @@ void GLContext_Free(void) {
} }
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
void* addr = DynamicLib_GetFrom("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", function); static const String glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
static void* lib;
void* addr;
if (!lib) lib = DynamicLib_Load2(&glPath);
addr = DynamicLib_Get2(lib, function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr; return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }