Refactor dispatch_common's EGL context detection code.

I want to reuse this from get_core_proc_address().
macos/v1.5.9
Eric Anholt 11 years ago
parent e6d9bb971b
commit b670c84039
  1. 76
      src/dispatch_common.c

@ -424,6 +424,38 @@ epoxy_get_core_proc_address(const char *name, int core_version)
} }
} }
#if PLATFORM_HAS_EGL
static EGLenum
epoxy_egl_get_current_gl_context_api(void)
{
EGLenum save_api = eglQueryAPI();
EGLContext ctx;
if (eglBindAPI(EGL_OPENGL_API)) {
ctx = eglGetCurrentContext();
if (ctx) {
eglBindAPI(save_api);
return EGL_OPENGL_API;
}
} else {
(void)eglGetError();
}
if (eglBindAPI(EGL_OPENGL_ES_API)) {
ctx = eglGetCurrentContext();
eglBindAPI(save_api);
if (ctx) {
eglBindAPI(save_api);
return EGL_OPENGL_ES_API;
}
} else {
(void)eglGetError();
}
return EGL_NONE;
}
#endif /* PLATFORM_HAS_EGL */
/** /**
* Performs the dlsym() for the core GL 1.0 functions that we use for * Performs the dlsym() for the core GL 1.0 functions that we use for
* determining version and extension support for deciding on dlsym * determining version and extension support for deciding on dlsym
@ -453,36 +485,20 @@ epoxy_get_bootstrap_proc_address(const char *name)
#if PLATFORM_HAS_EGL #if PLATFORM_HAS_EGL
get_dlopen_handle(&api.egl_handle, "libEGL.so.1", false); get_dlopen_handle(&api.egl_handle, "libEGL.so.1", false);
if (api.egl_handle) { if (api.egl_handle) {
EGLenum save_api = eglQueryAPI(); switch (epoxy_egl_get_current_gl_context_api()) {
EGLContext ctx; case EGL_OPENGL_API:
return epoxy_gl_dlsym(name);
if (eglBindAPI(EGL_OPENGL_API)) { case EGL_OPENGL_ES_API:
ctx = eglGetCurrentContext(); /* We can't resolve the GL version, because
if (ctx) { * epoxy_glGetString() is one of the two things calling
eglBindAPI(save_api); * us. Try the GLES2 implementation first, and fall back
return epoxy_gl_dlsym(name); * to GLES1 otherwise.
} */
} else { get_dlopen_handle(&api.gles2_handle, "libGLESv2.so.2", false);
(void)eglGetError(); if (api.gles2_handle)
} return epoxy_gles2_dlsym(name);
else
if (eglBindAPI(EGL_OPENGL_ES_API)) { return epoxy_gles1_dlsym(name);
ctx = eglGetCurrentContext();
eglBindAPI(save_api);
if (ctx) {
/* 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, "libGLESv2.so.2", false);
if (api.gles2_handle)
return epoxy_gles2_dlsym(name);
else
return epoxy_gles1_dlsym(name);
}
} else {
(void)eglGetError();
} }
} }
#endif /* PLATFORM_HAS_EGL */ #endif /* PLATFORM_HAS_EGL */

Loading…
Cancel
Save