From b5a4b16799a30cb74db1916d52f2756a7a5345ed Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Mon, 30 Apr 2018 15:26:17 -0400 Subject: [PATCH] dispatch: Query the EGL context version when bootstrapping on GLES We're about to change our dlopen paths to do RTLD_NOLOAD more aggressively. The issue then is we can create an EGL GLES context without libGLES* ever being loaded. test/egl_gles2_without_glx will fail in such a world: the first gentle probe for libGLESv2 will fail, then the less-gentle probe for libGLESv1_CM will be shot down by the test, and we exit. Fortunately by the time we've gotten to this point the context exists, so we can query its version via EGL instead. Signed-off-by: Adam Jackson --- src/dispatch_common.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 1eccb3b..bf10d52 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -812,20 +812,20 @@ epoxy_get_bootstrap_proc_address(const char *name) #if PLATFORM_HAS_EGL get_dlopen_handle(&api.egl_handle, EGL_LIB, false); if (api.egl_handle) { + int version = 0; switch (epoxy_egl_get_current_gl_context_api()) { case EGL_OPENGL_API: return epoxy_gl_dlsym(name); case EGL_OPENGL_ES_API: - /* We can't resolve the GL version, because - * epoxy_glGetString() is one of the two things calling - * us. Try the GLES2 implementation first, and fall back - * to GLES1 otherwise. - */ - get_dlopen_handle(&api.gles2_handle, GLES2_LIB, false); - if (api.gles2_handle) - return epoxy_gles2_dlsym(name); - else - return epoxy_gles1_dlsym(name); + if (eglQueryContext(eglGetCurrentDisplay(), + eglGetCurrentContext(), + EGL_CONTEXT_CLIENT_VERSION, + &version)) { + if (version >= 2) + return epoxy_gles2_dlsym(name); + else + return epoxy_gles1_dlsym(name); + } } } #endif /* PLATFORM_HAS_EGL */