[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...

This commit is contained in:
Ryan Houdek 2013-08-15 18:07:03 +00:00
parent 863fb9f95b
commit 06620ff364

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "GLFunctions.h" #include "GLFunctions.h"
#include "Log.h" #include "Log.h"
#include <dlfcn.h>
#ifdef USE_GLES3 #ifdef USE_GLES3
PFNGLMAPBUFFERPROC glMapBuffer; PFNGLMAPBUFFERPROC glMapBuffer;
PFNGLMAPBUFFERRANGEPROC glMapBufferRange; PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
@ -43,27 +44,35 @@ PFNGLGENQUERIESPROC glGenQueries;
#endif #endif
namespace GLFunc namespace GLFunc
{ {
void *self;
void LoadFunction(const char *name, void **func) void LoadFunction(const char *name, void **func)
{ {
#ifdef USE_GLES3 #ifdef USE_GLES3
*func = (void*)eglGetProcAddress(name); *func = (void*)eglGetProcAddress(name);
if (*func == NULL) if (*func == NULL)
{ {
ERROR_LOG(VIDEO, "Couldn't load function %s", name); // Fall back to trying dlsym
exit(0); 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 #endif
} }
void Init() void Init()
{ {
self = dlopen(NULL, RTLD_LAZY);
LoadFunction("glBeginQuery", (void**)&glBeginQuery); LoadFunction("glBeginQuery", (void**)&glBeginQuery);
LoadFunction("glEndQuery", (void**)&glEndQuery); LoadFunction("glEndQuery", (void**)&glEndQuery);
LoadFunction("glGetQueryObjectuiv", (void**)&glGetQueryObjectuiv); LoadFunction("glGetQueryObjectuiv", (void**)&glGetQueryObjectuiv);
LoadFunction("glDeleteQueries", (void**)&glDeleteQueries); LoadFunction("glDeleteQueries", (void**)&glDeleteQueries);
LoadFunction("glGenQueries", (void**)&glGenQueries); LoadFunction("glGenQueries", (void**)&glGenQueries);
{ {
LoadFunction("glMapBuffer", (void**)&glMapBuffer); LoadFunction("glMapBufferOES", (void**)&glMapBuffer);
LoadFunction("glUnmapBuffer", (void**)&glUnmapBuffer); LoadFunction("glUnmapBuffer", (void**)&glUnmapBuffer);
LoadFunction("glMapBufferRange", (void**)&glMapBufferRange); LoadFunction("glMapBufferRange", (void**)&glMapBufferRange);
LoadFunction("glBindBufferRange", (void**)&glBindBufferRange); LoadFunction("glBindBufferRange", (void**)&glBindBufferRange);
@ -93,5 +102,6 @@ namespace GLFunc
LoadFunction("glGetUniformBlockIndex", (void**)&glGetUniformBlockIndex); LoadFunction("glGetUniformBlockIndex", (void**)&glGetUniformBlockIndex);
LoadFunction("glUniformBlockBinding", (void**)&glUniformBlockBinding); LoadFunction("glUniformBlockBinding", (void**)&glUniformBlockBinding);
dlclose(self);
} }
} }