summaryrefslogtreecommitdiff
path: root/subprojects/glad/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2020-10-01 04:28:13 -0400
committerAndrew Opalach <andrew@akon.city> 2020-10-01 04:28:13 -0400
commit4c200513158ad0b974cda961deffe6192830ecae (patch)
tree110c4fde4b0d47d0a273de7f3cbe98528e8e7e9e /subprojects/glad/src
parentf114f3ad193313676be1de0d9388b9062a8559ab (diff)
downloadmauri-4c200513158ad0b974cda961deffe6192830ecae.tar.gz
mauri-4c200513158ad0b974cda961deffe6192830ecae.tar.bz2
mauri-4c200513158ad0b974cda961deffe6192830ecae.zip
switch to c++, add dxt5 and dxt1 handling
Diffstat (limited to 'subprojects/glad/src')
-rw-r--r--subprojects/glad/src/gl.c166
1 files changed, 166 insertions, 0 deletions
diff --git a/subprojects/glad/src/gl.c b/subprojects/glad/src/gl.c
index 1fae27b..eb3e66a 100644
--- a/subprojects/glad/src/gl.c
+++ b/subprojects/glad/src/gl.c
@@ -890,6 +890,172 @@ int gladLoadGL( GLADloadfunc load) {
+#ifdef GLAD_GL
+
+#ifndef GLAD_LOADER_LIBRARY_C_
+#define GLAD_LOADER_LIBRARY_C_
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#if GLAD_PLATFORM_WIN32
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
+
+
+static void* glad_get_dlopen_handle(const char *lib_names[], int length) {
+ void *handle = NULL;
+ int i;
+
+ for (i = 0; i < length; ++i) {
+#if GLAD_PLATFORM_WIN32
+ #if GLAD_PLATFORM_UWP
+ size_t buffer_size = (strlen(lib_names[i]) + 1) * sizeof(WCHAR);
+ LPWSTR buffer = (LPWSTR) malloc(buffer_size);
+ if (buffer != NULL) {
+ int ret = MultiByteToWideChar(CP_ACP, 0, lib_names[i], -1, buffer, buffer_size);
+ if (ret != 0) {
+ handle = (void*) LoadPackagedLibrary(buffer, 0);
+ }
+ free((void*) buffer);
+ }
+ #else
+ handle = (void*) LoadLibraryA(lib_names[i]);
+ #endif
+#else
+ handle = dlopen(lib_names[i], RTLD_LAZY | RTLD_LOCAL);
+#endif
+ if (handle != NULL) {
+ return handle;
+ }
+ }
+
+ return NULL;
+}
+
+static void glad_close_dlopen_handle(void* handle) {
+ if (handle != NULL) {
+#if GLAD_PLATFORM_WIN32
+ FreeLibrary((HMODULE) handle);
+#else
+ dlclose(handle);
+#endif
+ }
+}
+
+static GLADapiproc glad_dlsym_handle(void* handle, const char *name) {
+ if (handle == NULL) {
+ return NULL;
+ }
+
+#if GLAD_PLATFORM_WIN32
+ return (GLADapiproc) GetProcAddress((HMODULE) handle, name);
+#else
+ return GLAD_GNUC_EXTENSION (GLADapiproc) dlsym(handle, name);
+#endif
+}
+
+#endif /* GLAD_LOADER_LIBRARY_C_ */
+
+typedef void* (GLAD_API_PTR *GLADglprocaddrfunc)(const char*);
+struct _glad_gl_userptr {
+ void *handle;
+ GLADglprocaddrfunc gl_get_proc_address_ptr;
+};
+
+static GLADapiproc glad_gl_get_proc(void *vuserptr, const char *name) {
+ struct _glad_gl_userptr userptr = *(struct _glad_gl_userptr*) vuserptr;
+ GLADapiproc result = NULL;
+
+ if(userptr.gl_get_proc_address_ptr != NULL) {
+ result = GLAD_GNUC_EXTENSION (GLADapiproc) userptr.gl_get_proc_address_ptr(name);
+ }
+ if(result == NULL) {
+ result = glad_dlsym_handle(userptr.handle, name);
+ }
+
+ return result;
+}
+
+static void* _gl_handle = NULL;
+
+static void* glad_gl_dlopen_handle(void) {
+#if GLAD_PLATFORM_APPLE
+ static const char *NAMES[] = {
+ "../Frameworks/OpenGL.framework/OpenGL",
+ "/Library/Frameworks/OpenGL.framework/OpenGL",
+ "/System/Library/Frameworks/OpenGL.framework/OpenGL",
+ "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"
+ };
+#elif GLAD_PLATFORM_WIN32
+ static const char *NAMES[] = {"opengl32.dll"};
+#else
+ static const char *NAMES[] = {
+ #if defined(__CYGWIN__)
+ "libGL-1.so",
+ #endif
+ "libGL.so.1",
+ "libGL.so"
+ };
+#endif
+
+ if (_gl_handle == NULL) {
+ _gl_handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0]));
+ }
+
+ return _gl_handle;
+}
+
+static struct _glad_gl_userptr glad_gl_build_userptr(void *handle) {
+ struct _glad_gl_userptr userptr;
+
+ userptr.handle = handle;
+#if GLAD_PLATFORM_APPLE || defined(__HAIKU__)
+ userptr.gl_get_proc_address_ptr = NULL;
+#elif GLAD_PLATFORM_WIN32
+ userptr.gl_get_proc_address_ptr =
+ (GLADglprocaddrfunc) glad_dlsym_handle(handle, "wglGetProcAddress");
+#else
+ userptr.gl_get_proc_address_ptr =
+ (GLADglprocaddrfunc) glad_dlsym_handle(handle, "glXGetProcAddressARB");
+#endif
+
+ return userptr;
+}
+
+int gladLoaderLoadGL(void) {
+ int version = 0;
+ void *handle;
+ int did_load = 0;
+ struct _glad_gl_userptr userptr;
+
+ did_load = _gl_handle == NULL;
+ handle = glad_gl_dlopen_handle();
+ if (handle) {
+ userptr = glad_gl_build_userptr(handle);
+
+ version = gladLoadGLUserPtr(glad_gl_get_proc, &userptr);
+
+ if (did_load) {
+ gladLoaderUnloadGL();
+ }
+ }
+
+ return version;
+}
+
+
+
+void gladLoaderUnloadGL(void) {
+ if (_gl_handle != NULL) {
+ glad_close_dlopen_handle(_gl_handle);
+ _gl_handle = NULL;
+ }
+}
+
+#endif /* GLAD_GL */
#ifdef __cplusplus
}