| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include <string.h> |
| 7 |
#include <glad/egl.h> |
| 8 |
|
| 9 |
#ifndef GLAD_IMPL_UTIL_C_ |
| 10 |
#define GLAD_IMPL_UTIL_C_ |
| 11 |
|
| 12 |
#ifdef _MSC_VER |
| 13 |
#define GLAD_IMPL_UTIL_SSCANF sscanf_s |
| 14 |
#else |
| 15 |
#define GLAD_IMPL_UTIL_SSCANF sscanf |
| 16 |
#endif |
| 17 |
|
| 18 |
#endif |
| 19 |
|
| 20 |
#ifdef __cplusplus |
| 21 |
extern "C" { |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
int GLAD_EGL_VERSION_1_0 = 0; |
| 27 |
int GLAD_EGL_VERSION_1_1 = 0; |
| 28 |
int GLAD_EGL_VERSION_1_2 = 0; |
| 29 |
int GLAD_EGL_VERSION_1_3 = 0; |
| 30 |
int GLAD_EGL_VERSION_1_4 = 0; |
| 31 |
int GLAD_EGL_VERSION_1_5 = 0; |
| 32 |
int GLAD_EGL_ANDROID_blob_cache = 0; |
| 33 |
int GLAD_EGL_EXT_platform_base = 0; |
| 34 |
int GLAD_EGL_KHR_platform_wayland = 0; |
| 35 |
int GLAD_EGL_KHR_platform_x11 = 0; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
PFNEGLBINDAPIPROC glad_eglBindAPI = NULL; |
| 40 |
PFNEGLBINDTEXIMAGEPROC glad_eglBindTexImage = NULL; |
| 41 |
PFNEGLCHOOSECONFIGPROC glad_eglChooseConfig = NULL; |
| 42 |
PFNEGLCLIENTWAITSYNCPROC glad_eglClientWaitSync = NULL; |
| 43 |
PFNEGLCOPYBUFFERSPROC glad_eglCopyBuffers = NULL; |
| 44 |
PFNEGLCREATECONTEXTPROC glad_eglCreateContext = NULL; |
| 45 |
PFNEGLCREATEIMAGEPROC glad_eglCreateImage = NULL; |
| 46 |
PFNEGLCREATEPBUFFERFROMCLIENTBUFFERPROC glad_eglCreatePbufferFromClientBuffer = NULL; |
| 47 |
PFNEGLCREATEPBUFFERSURFACEPROC glad_eglCreatePbufferSurface = NULL; |
| 48 |
PFNEGLCREATEPIXMAPSURFACEPROC glad_eglCreatePixmapSurface = NULL; |
| 49 |
PFNEGLCREATEPLATFORMPIXMAPSURFACEPROC glad_eglCreatePlatformPixmapSurface = NULL; |
| 50 |
PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC glad_eglCreatePlatformPixmapSurfaceEXT = NULL; |
| 51 |
PFNEGLCREATEPLATFORMWINDOWSURFACEPROC glad_eglCreatePlatformWindowSurface = NULL; |
| 52 |
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC glad_eglCreatePlatformWindowSurfaceEXT = NULL; |
| 53 |
PFNEGLCREATESYNCPROC glad_eglCreateSync = NULL; |
| 54 |
PFNEGLCREATEWINDOWSURFACEPROC glad_eglCreateWindowSurface = NULL; |
| 55 |
PFNEGLDESTROYCONTEXTPROC glad_eglDestroyContext = NULL; |
| 56 |
PFNEGLDESTROYIMAGEPROC glad_eglDestroyImage = NULL; |
| 57 |
PFNEGLDESTROYSURFACEPROC glad_eglDestroySurface = NULL; |
| 58 |
PFNEGLDESTROYSYNCPROC glad_eglDestroySync = NULL; |
| 59 |
PFNEGLGETCONFIGATTRIBPROC glad_eglGetConfigAttrib = NULL; |
| 60 |
PFNEGLGETCONFIGSPROC glad_eglGetConfigs = NULL; |
| 61 |
PFNEGLGETCURRENTCONTEXTPROC glad_eglGetCurrentContext = NULL; |
| 62 |
PFNEGLGETCURRENTDISPLAYPROC glad_eglGetCurrentDisplay = NULL; |
| 63 |
PFNEGLGETCURRENTSURFACEPROC glad_eglGetCurrentSurface = NULL; |
| 64 |
PFNEGLGETDISPLAYPROC glad_eglGetDisplay = NULL; |
| 65 |
PFNEGLGETERRORPROC glad_eglGetError = NULL; |
| 66 |
PFNEGLGETPLATFORMDISPLAYPROC glad_eglGetPlatformDisplay = NULL; |
| 67 |
PFNEGLGETPLATFORMDISPLAYEXTPROC glad_eglGetPlatformDisplayEXT = NULL; |
| 68 |
PFNEGLGETPROCADDRESSPROC glad_eglGetProcAddress = NULL; |
| 69 |
PFNEGLGETSYNCATTRIBPROC glad_eglGetSyncAttrib = NULL; |
| 70 |
PFNEGLINITIALIZEPROC glad_eglInitialize = NULL; |
| 71 |
PFNEGLMAKECURRENTPROC glad_eglMakeCurrent = NULL; |
| 72 |
PFNEGLQUERYAPIPROC glad_eglQueryAPI = NULL; |
| 73 |
PFNEGLQUERYCONTEXTPROC glad_eglQueryContext = NULL; |
| 74 |
PFNEGLQUERYSTRINGPROC glad_eglQueryString = NULL; |
| 75 |
PFNEGLQUERYSURFACEPROC glad_eglQuerySurface = NULL; |
| 76 |
PFNEGLRELEASETEXIMAGEPROC glad_eglReleaseTexImage = NULL; |
| 77 |
PFNEGLRELEASETHREADPROC glad_eglReleaseThread = NULL; |
| 78 |
PFNEGLSETBLOBCACHEFUNCSANDROIDPROC glad_eglSetBlobCacheFuncsANDROID = NULL; |
| 79 |
PFNEGLSURFACEATTRIBPROC glad_eglSurfaceAttrib = NULL; |
| 80 |
PFNEGLSWAPBUFFERSPROC glad_eglSwapBuffers = NULL; |
| 81 |
PFNEGLSWAPINTERVALPROC glad_eglSwapInterval = NULL; |
| 82 |
PFNEGLTERMINATEPROC glad_eglTerminate = NULL; |
| 83 |
PFNEGLWAITCLIENTPROC glad_eglWaitClient = NULL; |
| 84 |
PFNEGLWAITGLPROC glad_eglWaitGL = NULL; |
| 85 |
PFNEGLWAITNATIVEPROC glad_eglWaitNative = NULL; |
| 86 |
PFNEGLWAITSYNCPROC glad_eglWaitSync = NULL; |
| 87 |
|
| 88 |
|
| 89 |
static void glad_egl_load_EGL_VERSION_1_0( GLADuserptrloadfunc load, void* userptr) { |
| 90 |
if(!GLAD_EGL_VERSION_1_0) return; |
| 91 |
glad_eglChooseConfig = (PFNEGLCHOOSECONFIGPROC) load(userptr, "eglChooseConfig"); |
| 92 |
glad_eglCopyBuffers = (PFNEGLCOPYBUFFERSPROC) load(userptr, "eglCopyBuffers"); |
| 93 |
glad_eglCreateContext = (PFNEGLCREATECONTEXTPROC) load(userptr, "eglCreateContext"); |
| 94 |
glad_eglCreatePbufferSurface = (PFNEGLCREATEPBUFFERSURFACEPROC) load(userptr, "eglCreatePbufferSurface"); |
| 95 |
glad_eglCreatePixmapSurface = (PFNEGLCREATEPIXMAPSURFACEPROC) load(userptr, "eglCreatePixmapSurface"); |
| 96 |
glad_eglCreateWindowSurface = (PFNEGLCREATEWINDOWSURFACEPROC) load(userptr, "eglCreateWindowSurface"); |
| 97 |
glad_eglDestroyContext = (PFNEGLDESTROYCONTEXTPROC) load(userptr, "eglDestroyContext"); |
| 98 |
glad_eglDestroySurface = (PFNEGLDESTROYSURFACEPROC) load(userptr, "eglDestroySurface"); |
| 99 |
glad_eglGetConfigAttrib = (PFNEGLGETCONFIGATTRIBPROC) load(userptr, "eglGetConfigAttrib"); |
| 100 |
glad_eglGetConfigs = (PFNEGLGETCONFIGSPROC) load(userptr, "eglGetConfigs"); |
| 101 |
glad_eglGetCurrentDisplay = (PFNEGLGETCURRENTDISPLAYPROC) load(userptr, "eglGetCurrentDisplay"); |
| 102 |
glad_eglGetCurrentSurface = (PFNEGLGETCURRENTSURFACEPROC) load(userptr, "eglGetCurrentSurface"); |
| 103 |
glad_eglGetDisplay = (PFNEGLGETDISPLAYPROC) load(userptr, "eglGetDisplay"); |
| 104 |
glad_eglGetError = (PFNEGLGETERRORPROC) load(userptr, "eglGetError"); |
| 105 |
glad_eglGetProcAddress = (PFNEGLGETPROCADDRESSPROC) load(userptr, "eglGetProcAddress"); |
| 106 |
glad_eglInitialize = (PFNEGLINITIALIZEPROC) load(userptr, "eglInitialize"); |
| 107 |
glad_eglMakeCurrent = (PFNEGLMAKECURRENTPROC) load(userptr, "eglMakeCurrent"); |
| 108 |
glad_eglQueryContext = (PFNEGLQUERYCONTEXTPROC) load(userptr, "eglQueryContext"); |
| 109 |
glad_eglQueryString = (PFNEGLQUERYSTRINGPROC) load(userptr, "eglQueryString"); |
| 110 |
glad_eglQuerySurface = (PFNEGLQUERYSURFACEPROC) load(userptr, "eglQuerySurface"); |
| 111 |
glad_eglSwapBuffers = (PFNEGLSWAPBUFFERSPROC) load(userptr, "eglSwapBuffers"); |
| 112 |
glad_eglTerminate = (PFNEGLTERMINATEPROC) load(userptr, "eglTerminate"); |
| 113 |
glad_eglWaitGL = (PFNEGLWAITGLPROC) load(userptr, "eglWaitGL"); |
| 114 |
glad_eglWaitNative = (PFNEGLWAITNATIVEPROC) load(userptr, "eglWaitNative"); |
| 115 |
} |
| 116 |
static void glad_egl_load_EGL_VERSION_1_1( GLADuserptrloadfunc load, void* userptr) { |
| 117 |
if(!GLAD_EGL_VERSION_1_1) return; |
| 118 |
glad_eglBindTexImage = (PFNEGLBINDTEXIMAGEPROC) load(userptr, "eglBindTexImage"); |
| 119 |
glad_eglReleaseTexImage = (PFNEGLRELEASETEXIMAGEPROC) load(userptr, "eglReleaseTexImage"); |
| 120 |
glad_eglSurfaceAttrib = (PFNEGLSURFACEATTRIBPROC) load(userptr, "eglSurfaceAttrib"); |
| 121 |
glad_eglSwapInterval = (PFNEGLSWAPINTERVALPROC) load(userptr, "eglSwapInterval"); |
| 122 |
} |
| 123 |
static void glad_egl_load_EGL_VERSION_1_2( GLADuserptrloadfunc load, void* userptr) { |
| 124 |
if(!GLAD_EGL_VERSION_1_2) return; |
| 125 |
glad_eglBindAPI = (PFNEGLBINDAPIPROC) load(userptr, "eglBindAPI"); |
| 126 |
glad_eglCreatePbufferFromClientBuffer = (PFNEGLCREATEPBUFFERFROMCLIENTBUFFERPROC) load(userptr, "eglCreatePbufferFromClientBuffer"); |
| 127 |
glad_eglQueryAPI = (PFNEGLQUERYAPIPROC) load(userptr, "eglQueryAPI"); |
| 128 |
glad_eglReleaseThread = (PFNEGLRELEASETHREADPROC) load(userptr, "eglReleaseThread"); |
| 129 |
glad_eglWaitClient = (PFNEGLWAITCLIENTPROC) load(userptr, "eglWaitClient"); |
| 130 |
} |
| 131 |
static void glad_egl_load_EGL_VERSION_1_4( GLADuserptrloadfunc load, void* userptr) { |
| 132 |
if(!GLAD_EGL_VERSION_1_4) return; |
| 133 |
glad_eglGetCurrentContext = (PFNEGLGETCURRENTCONTEXTPROC) load(userptr, "eglGetCurrentContext"); |
| 134 |
} |
| 135 |
static void glad_egl_load_EGL_VERSION_1_5( GLADuserptrloadfunc load, void* userptr) { |
| 136 |
if(!GLAD_EGL_VERSION_1_5) return; |
| 137 |
glad_eglClientWaitSync = (PFNEGLCLIENTWAITSYNCPROC) load(userptr, "eglClientWaitSync"); |
| 138 |
glad_eglCreateImage = (PFNEGLCREATEIMAGEPROC) load(userptr, "eglCreateImage"); |
| 139 |
glad_eglCreatePlatformPixmapSurface = (PFNEGLCREATEPLATFORMPIXMAPSURFACEPROC) load(userptr, "eglCreatePlatformPixmapSurface"); |
| 140 |
glad_eglCreatePlatformWindowSurface = (PFNEGLCREATEPLATFORMWINDOWSURFACEPROC) load(userptr, "eglCreatePlatformWindowSurface"); |
| 141 |
glad_eglCreateSync = (PFNEGLCREATESYNCPROC) load(userptr, "eglCreateSync"); |
| 142 |
glad_eglDestroyImage = (PFNEGLDESTROYIMAGEPROC) load(userptr, "eglDestroyImage"); |
| 143 |
glad_eglDestroySync = (PFNEGLDESTROYSYNCPROC) load(userptr, "eglDestroySync"); |
| 144 |
glad_eglGetPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYPROC) load(userptr, "eglGetPlatformDisplay"); |
| 145 |
glad_eglGetSyncAttrib = (PFNEGLGETSYNCATTRIBPROC) load(userptr, "eglGetSyncAttrib"); |
| 146 |
glad_eglWaitSync = (PFNEGLWAITSYNCPROC) load(userptr, "eglWaitSync"); |
| 147 |
} |
| 148 |
static void glad_egl_load_EGL_ANDROID_blob_cache( GLADuserptrloadfunc load, void* userptr) { |
| 149 |
if(!GLAD_EGL_ANDROID_blob_cache) return; |
| 150 |
glad_eglSetBlobCacheFuncsANDROID = (PFNEGLSETBLOBCACHEFUNCSANDROIDPROC) load(userptr, "eglSetBlobCacheFuncsANDROID"); |
| 151 |
} |
| 152 |
static void glad_egl_load_EGL_EXT_platform_base( GLADuserptrloadfunc load, void* userptr) { |
| 153 |
if(!GLAD_EGL_EXT_platform_base) return; |
| 154 |
glad_eglCreatePlatformPixmapSurfaceEXT = (PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) load(userptr, "eglCreatePlatformPixmapSurfaceEXT"); |
| 155 |
glad_eglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) load(userptr, "eglCreatePlatformWindowSurfaceEXT"); |
| 156 |
glad_eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC) load(userptr, "eglGetPlatformDisplayEXT"); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
static int glad_egl_get_extensions(EGLDisplay display, const char **extensions) { |
| 162 |
*extensions = eglQueryString(display, EGL_EXTENSIONS); |
| 163 |
|
| 164 |
return extensions != NULL; |
| 165 |
} |
| 166 |
|
| 167 |
static int glad_egl_has_extension(const char *extensions, const char *ext) { |
| 168 |
const char *loc; |
| 169 |
const char *terminator; |
| 170 |
if(extensions == NULL) { |
| 171 |
return 0; |
| 172 |
} |
| 173 |
while(1) { |
| 174 |
loc = strstr(extensions, ext); |
| 175 |
if(loc == NULL) { |
| 176 |
return 0; |
| 177 |
} |
| 178 |
terminator = loc + strlen(ext); |
| 179 |
if((loc == extensions || *(loc - 1) == ' ') && |
| 180 |
(*terminator == ' ' || *terminator == '\0')) { |
| 181 |
return 1; |
| 182 |
} |
| 183 |
extensions = terminator; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
static GLADapiproc glad_egl_get_proc_from_userptr(void *userptr, const char *name) { |
| 188 |
return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name); |
| 189 |
} |
| 190 |
|
| 191 |
static int glad_egl_find_extensions_egl(EGLDisplay display) { |
| 192 |
const char *extensions; |
| 193 |
if (!glad_egl_get_extensions(display, &extensions)) return 0; |
| 194 |
|
| 195 |
GLAD_EGL_ANDROID_blob_cache = glad_egl_has_extension(extensions, "EGL_ANDROID_blob_cache"); |
| 196 |
GLAD_EGL_EXT_platform_base = glad_egl_has_extension(extensions, "EGL_EXT_platform_base"); |
| 197 |
GLAD_EGL_KHR_platform_wayland = glad_egl_has_extension(extensions, "EGL_KHR_platform_wayland"); |
| 198 |
GLAD_EGL_KHR_platform_x11 = glad_egl_has_extension(extensions, "EGL_KHR_platform_x11"); |
| 199 |
|
| 200 |
return 1; |
| 201 |
} |
| 202 |
|
| 203 |
static int glad_egl_find_core_egl(EGLDisplay display) { |
| 204 |
int major, minor; |
| 205 |
const char *version; |
| 206 |
|
| 207 |
if (display == NULL) { |
| 208 |
display = EGL_NO_DISPLAY; |
| 209 |
} |
| 210 |
if (display == EGL_NO_DISPLAY) { |
| 211 |
display = eglGetCurrentDisplay(); |
| 212 |
} |
| 213 |
#ifdef EGL_VERSION_1_4 |
| 214 |
if (display == EGL_NO_DISPLAY) { |
| 215 |
display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 216 |
} |
| 217 |
#endif |
| 218 |
#ifndef EGL_VERSION_1_5 |
| 219 |
if (display == EGL_NO_DISPLAY) { |
| 220 |
return 0; |
| 221 |
} |
| 222 |
#endif |
| 223 |
|
| 224 |
version = eglQueryString(display, EGL_VERSION); |
| 225 |
(void) eglGetError(); |
| 226 |
|
| 227 |
if (version == NULL) { |
| 228 |
major = 1; |
| 229 |
minor = 0; |
| 230 |
} else { |
| 231 |
GLAD_IMPL_UTIL_SSCANF(version, "%d.%d", &major, &minor); |
| 232 |
} |
| 233 |
|
| 234 |
GLAD_EGL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1; |
| 235 |
GLAD_EGL_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1; |
| 236 |
GLAD_EGL_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1; |
| 237 |
GLAD_EGL_VERSION_1_3 = (major == 1 && minor >= 3) || major > 1; |
| 238 |
GLAD_EGL_VERSION_1_4 = (major == 1 && minor >= 4) || major > 1; |
| 239 |
GLAD_EGL_VERSION_1_5 = (major == 1 && minor >= 5) || major > 1; |
| 240 |
|
| 241 |
return GLAD_MAKE_VERSION(major, minor); |
| 242 |
} |
| 243 |
|
| 244 |
int gladLoadEGLUserPtr(EGLDisplay display, GLADuserptrloadfunc load, void* userptr) { |
| 245 |
int version; |
| 246 |
eglGetDisplay = (PFNEGLGETDISPLAYPROC) load(userptr, "eglGetDisplay"); |
| 247 |
eglGetCurrentDisplay = (PFNEGLGETCURRENTDISPLAYPROC) load(userptr, "eglGetCurrentDisplay"); |
| 248 |
eglQueryString = (PFNEGLQUERYSTRINGPROC) load(userptr, "eglQueryString"); |
| 249 |
eglGetError = (PFNEGLGETERRORPROC) load(userptr, "eglGetError"); |
| 250 |
if (eglGetDisplay == NULL || eglGetCurrentDisplay == NULL || eglQueryString == NULL || eglGetError == NULL) return 0; |
| 251 |
|
| 252 |
version = glad_egl_find_core_egl(display); |
| 253 |
if (!version) return 0; |
| 254 |
glad_egl_load_EGL_VERSION_1_0(load, userptr); |
| 255 |
glad_egl_load_EGL_VERSION_1_1(load, userptr); |
| 256 |
glad_egl_load_EGL_VERSION_1_2(load, userptr); |
| 257 |
glad_egl_load_EGL_VERSION_1_4(load, userptr); |
| 258 |
glad_egl_load_EGL_VERSION_1_5(load, userptr); |
| 259 |
|
| 260 |
if (!glad_egl_find_extensions_egl(display)) return 0; |
| 261 |
glad_egl_load_EGL_ANDROID_blob_cache(load, userptr); |
| 262 |
glad_egl_load_EGL_EXT_platform_base(load, userptr); |
| 263 |
|
| 264 |
|
| 265 |
return version; |
| 266 |
} |
| 267 |
|
| 268 |
int gladLoadEGL(EGLDisplay display, GLADloadfunc load) { |
| 269 |
return gladLoadEGLUserPtr(display, glad_egl_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load); |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
#ifdef GLAD_EGL |
| 275 |
|
| 276 |
#ifndef GLAD_LOADER_LIBRARY_C_ |
| 277 |
#define GLAD_LOADER_LIBRARY_C_ |
| 278 |
|
| 279 |
#include <stddef.h> |
| 280 |
#include <stdlib.h> |
| 281 |
|
| 282 |
#if GLAD_PLATFORM_WIN32 |
| 283 |
#include <windows.h> |
| 284 |
#else |
| 285 |
#include <dlfcn.h> |
| 286 |
#endif |
| 287 |
|
| 288 |
|
| 289 |
static void* glad_get_dlopen_handle(const char *lib_names[], int length) { |
| 290 |
void *handle = NULL; |
| 291 |
int i; |
| 292 |
|
| 293 |
for (i = 0; i < length; ++i) { |
| 294 |
#if GLAD_PLATFORM_WIN32 |
| 295 |
#if GLAD_PLATFORM_UWP |
| 296 |
size_t buffer_size = (strlen(lib_names[i]) + 1) * sizeof(WCHAR); |
| 297 |
LPWSTR buffer = (LPWSTR) malloc(buffer_size); |
| 298 |
if (buffer != NULL) { |
| 299 |
int ret = MultiByteToWideChar(CP_ACP, 0, lib_names[i], -1, buffer, buffer_size); |
| 300 |
if (ret != 0) { |
| 301 |
handle = (void*) LoadPackagedLibrary(buffer, 0); |
| 302 |
} |
| 303 |
free((void*) buffer); |
| 304 |
} |
| 305 |
#else |
| 306 |
handle = (void*) LoadLibraryA(lib_names[i]); |
| 307 |
#endif |
| 308 |
#else |
| 309 |
handle = dlopen(lib_names[i], RTLD_LAZY | RTLD_LOCAL); |
| 310 |
#endif |
| 311 |
if (handle != NULL) { |
| 312 |
return handle; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
return NULL; |
| 317 |
} |
| 318 |
|
| 319 |
static void glad_close_dlopen_handle(void* handle) { |
| 320 |
if (handle != NULL) { |
| 321 |
#if GLAD_PLATFORM_WIN32 |
| 322 |
FreeLibrary((HMODULE) handle); |
| 323 |
#else |
| 324 |
dlclose(handle); |
| 325 |
#endif |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
static GLADapiproc glad_dlsym_handle(void* handle, const char *name) { |
| 330 |
if (handle == NULL) { |
| 331 |
return NULL; |
| 332 |
} |
| 333 |
|
| 334 |
#if GLAD_PLATFORM_WIN32 |
| 335 |
return (GLADapiproc) GetProcAddress((HMODULE) handle, name); |
| 336 |
#else |
| 337 |
return GLAD_GNUC_EXTENSION (GLADapiproc) dlsym(handle, name); |
| 338 |
#endif |
| 339 |
} |
| 340 |
|
| 341 |
#endif |
| 342 |
|
| 343 |
struct _glad_egl_userptr { |
| 344 |
void *handle; |
| 345 |
PFNEGLGETPROCADDRESSPROC get_proc_address_ptr; |
| 346 |
}; |
| 347 |
|
| 348 |
static GLADapiproc glad_egl_get_proc(void *vuserptr, const char* name) { |
| 349 |
struct _glad_egl_userptr userptr = *(struct _glad_egl_userptr*) vuserptr; |
| 350 |
GLADapiproc result = NULL; |
| 351 |
|
| 352 |
result = glad_dlsym_handle(userptr.handle, name); |
| 353 |
if (result == NULL) { |
| 354 |
result = GLAD_GNUC_EXTENSION (GLADapiproc) userptr.get_proc_address_ptr(name); |
| 355 |
} |
| 356 |
|
| 357 |
return result; |
| 358 |
} |
| 359 |
|
| 360 |
static void* _egl_handle = NULL; |
| 361 |
|
| 362 |
static void* glad_egl_dlopen_handle(void) { |
| 363 |
#if GLAD_PLATFORM_APPLE |
| 364 |
static const char *NAMES[] = {"libEGL.dylib"}; |
| 365 |
#elif GLAD_PLATFORM_WIN32 |
| 366 |
static const char *NAMES[] = {"libEGL.dll", "EGL.dll"}; |
| 367 |
#else |
| 368 |
static const char *NAMES[] = {"libEGL.so.1", "libEGL.so"}; |
| 369 |
#endif |
| 370 |
|
| 371 |
if (_egl_handle == NULL) { |
| 372 |
_egl_handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0])); |
| 373 |
} |
| 374 |
|
| 375 |
return _egl_handle; |
| 376 |
} |
| 377 |
|
| 378 |
static struct _glad_egl_userptr glad_egl_build_userptr(void *handle) { |
| 379 |
struct _glad_egl_userptr userptr; |
| 380 |
userptr.handle = handle; |
| 381 |
userptr.get_proc_address_ptr = (PFNEGLGETPROCADDRESSPROC) glad_dlsym_handle(handle, "eglGetProcAddress"); |
| 382 |
return userptr; |
| 383 |
} |
| 384 |
|
| 385 |
int gladLoaderLoadEGL(EGLDisplay display) { |
| 386 |
int version = 0; |
| 387 |
void *handle = NULL; |
| 388 |
int did_load = 0; |
| 389 |
struct _glad_egl_userptr userptr; |
| 390 |
|
| 391 |
did_load = _egl_handle == NULL; |
| 392 |
handle = glad_egl_dlopen_handle(); |
| 393 |
if (handle != NULL) { |
| 394 |
userptr = glad_egl_build_userptr(handle); |
| 395 |
|
| 396 |
if (userptr.get_proc_address_ptr != NULL) { |
| 397 |
version = gladLoadEGLUserPtr(display, glad_egl_get_proc, &userptr); |
| 398 |
} |
| 399 |
|
| 400 |
if (!version && did_load) { |
| 401 |
gladLoaderUnloadEGL(); |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
return version; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
void gladLoaderUnloadEGL() { |
| 410 |
if (_egl_handle != NULL) { |
| 411 |
glad_close_dlopen_handle(_egl_handle); |
| 412 |
_egl_handle = NULL; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
#endif |
| 417 |
|
| 418 |
#ifdef __cplusplus |
| 419 |
} |
| 420 |
#endif |