-
Notifications
You must be signed in to change notification settings - Fork 490
Description
Related to #458
As that Issue observes, eglQueryString(display, EGL_VERSION) will return NULL if egl has not yet been initialized (this is always the case on my local system - Arch Linux with both proprietary drivers for a NVIDIA RTX2070 and software MESA drivers)
static int glad_egl_find_core_egl(EGLDisplay display) {
...
version = eglQueryString(display, EGL_VERSION);
(void) eglGetError();
if (version == NULL) {
major = 1;
minor = 0;
}
...So only the core EGL 1.0 entry points are loaded by Glad. This requires the client code to call gladLoaderLoadEGL twice - as follows:
auto egl_version = gladLoaderLoadEGL(NULL); // loads only the core 1.0 entry points
auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
auto egl_major = EGLint();
auto egl_minor = EGLint();
eglInitialize(egl_display, &egl_major, &egl_minor)
egl_version = gladLoaderLoadEGL(egl_display); // loads more entrypoints but depends on how many EGL devices are availableHowever, this still may not be sufficient because the egl_display may not be the correct one on a system with multiple EGL displays (eg Wayland, X11, Surfaceless etc), so we end up needing to initialize EGL twice, and call gladLoaderEGL three times -
auto egl_version = gladLoaderLoadEGL(NULL); // loads only the core 1.0 entry points
auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
auto egl_major = EGLint();
auto egl_minor = EGLint();
eglInitialize(egl_display, &egl_major, &egl_minor)
egl_version = gladLoaderLoadEGL(egl_display); // need this for eglGetPlatformDisplay which is the function we actually want
eglTerminate(egl_display)
auto real_egl_display = eglGetPlatformDisplay(...);
eglInitialize(real_egl_display, &egl_major, &egl_minor);
egl_version = gladLoaderLoadEGL(real_egl_display); // need to call this again as we may have different extensions available on the new deviceI wonder if glad_egl_find_core_egl can be improved to make sure we're actually loading the entrypoints for the correct device up front? - I know it's possible to test extensions without having a display object available