From 06620ff364aef8ff26743f197d0fa26380991094 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 15 Aug 2013 18:07:03 +0000 Subject: [PATCH] [Android] Fall back to using dlsym on ourselves to pull in OpenGL Functions when eglGetProcAddress fails. This fixes an issue on the Chromebook where I was forced to link to libGLESv2 and pull in the functions statically since eglGetProcAddress wouldn't return any GLESv3 functions. This also changes glMapBuffer to glMapBufferOES because glMapBuffer isn't actually part of the OpenGL ES 3 spec... --- .../Plugins/Plugin_VideoOGL/Src/GLFunctions.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLFunctions.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLFunctions.cpp index 2759fd82ff..e174a1e64d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLFunctions.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLFunctions.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "GLFunctions.h" #include "Log.h" +#include #ifdef USE_GLES3 PFNGLMAPBUFFERPROC glMapBuffer; PFNGLMAPBUFFERRANGEPROC glMapBufferRange; @@ -43,27 +44,35 @@ PFNGLGENQUERIESPROC glGenQueries; #endif namespace GLFunc { + void *self; void LoadFunction(const char *name, void **func) { #ifdef USE_GLES3 *func = (void*)eglGetProcAddress(name); if (*func == NULL) { - ERROR_LOG(VIDEO, "Couldn't load function %s", name); - exit(0); + // Fall back to trying dlsym + if (self) // Just in case dlopen fails + *func = dlsym(self, name); + if (*func == NULL) + { + ERROR_LOG(VIDEO, "Couldn't load function %s", name); + exit(0); + } } #endif } void Init() { + self = dlopen(NULL, RTLD_LAZY); LoadFunction("glBeginQuery", (void**)&glBeginQuery); LoadFunction("glEndQuery", (void**)&glEndQuery); LoadFunction("glGetQueryObjectuiv", (void**)&glGetQueryObjectuiv); LoadFunction("glDeleteQueries", (void**)&glDeleteQueries); LoadFunction("glGenQueries", (void**)&glGenQueries); { - LoadFunction("glMapBuffer", (void**)&glMapBuffer); + LoadFunction("glMapBufferOES", (void**)&glMapBuffer); LoadFunction("glUnmapBuffer", (void**)&glUnmapBuffer); LoadFunction("glMapBufferRange", (void**)&glMapBufferRange); LoadFunction("glBindBufferRange", (void**)&glBindBufferRange); @@ -93,5 +102,6 @@ namespace GLFunc LoadFunction("glGetUniformBlockIndex", (void**)&glGetUniformBlockIndex); LoadFunction("glUniformBlockBinding", (void**)&glUniformBlockBinding); + dlclose(self); } }