From 4c5472555a3a418c06fd5e6a18240862eebce047 Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Wed, 27 Jan 2016 22:15:49 +1000 Subject: [PATCH] For EGL purpose avoid using linked glGetString, load it via eglGetProcAddress instead. --- auto/src/glew_init_egl.c | 2 +- auto/src/glew_init_gl.c | 17 ++++++++++++++--- auto/src/glewinfo_tail.c | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/auto/src/glew_init_egl.c b/auto/src/glew_init_egl.c index 26bd4ae..784285f 100644 --- a/auto/src/glew_init_egl.c +++ b/auto/src/glew_init_egl.c @@ -5,7 +5,7 @@ GLboolean eglewGetExtension (const char* name) const GLubyte* start; const GLubyte* end; - start = (const GLubyte*) eglQueryString(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_EXTENSIONS); + start = (const GLubyte*) eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS); if (0 == start) return GL_FALSE; end = start + _glewStrLen(start); return _glewSearchExtension(name, start, end); diff --git a/auto/src/glew_init_gl.c b/auto/src/glew_init_gl.c index 6fd86ce..38bb7c1 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -71,14 +71,22 @@ GLboolean GLEWAPIENTRY glewGetExtension (const char* name) /* ------------------------------------------------------------------------- */ +typedef const GLubyte* (GLAPIENTRY * PFNGLGETSTRINGPROC) (GLenum name); +typedef void (GLAPIENTRY * PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); + static GLenum GLEWAPIENTRY glewContextInit () { + PFNGLGETSTRINGPROC getString; const GLubyte* s; GLuint dot; GLint major, minor; /* query opengl version */ - s = glGetString(GL_VERSION); + getString = (PFNGLGETSTRINGPROC) glewGetProcAddress((const GLubyte*)"glGetString"); + if (!getString) + return GLEW_ERROR_NO_GL_VERSION; + + s = getString(GL_VERSION); dot = _glewStrCLen(s, '.'); if (dot == 0) return GLEW_ERROR_NO_GL_VERSION; @@ -123,11 +131,14 @@ static GLenum GLEWAPIENTRY glewContextInit () { GLint n = 0; GLint i; + PFNGLGETINTEGERVPROC getIntegerv; PFNGLGETSTRINGIPROC getStringi; const char *ext; GLboolean *enable; - glGetIntegerv(GL_NUM_EXTENSIONS, &n); + getIntegerv = (PFNGLGETINTEGERVPROC) glewGetProcAddress((const GLubyte*)"glGetIntegerv"); + if (getIntegerv) + getIntegerv(GL_NUM_EXTENSIONS, &n); /* glGetStringi is OpenGL 3.0 */ getStringi = (PFNGLGETSTRINGIPROC) glewGetProcAddress((const GLubyte*)"glGetStringi"); @@ -156,7 +167,7 @@ static GLenum GLEWAPIENTRY glewContextInit () char ext[128]; GLboolean *enable; - extensions = (const char *) glGetString(GL_EXTENSIONS); + extensions = (const char *) getString(GL_EXTENSIONS); if (extensions) { diff --git a/auto/src/glewinfo_tail.c b/auto/src/glewinfo_tail.c index ec895f8..1975286 100644 --- a/auto/src/glewinfo_tail.c +++ b/auto/src/glewinfo_tail.c @@ -23,6 +23,11 @@ int main (int argc, char** argv) 0 /* flags */ }; +#if defined(GLEW_EGL) + typedef const GLubyte* (GLAPIENTRY * PFNGLGETSTRINGPROC) (GLenum name); + PFNGLGETSTRINGPROC getString; +#endif + if (glewParseArgs(argc-1, argv+1, ¶ms)) { fprintf(stderr, "Usage: glewinfo " @@ -55,6 +60,17 @@ int main (int argc, char** argv) glewDestroyContext(); return 1; } + +#if defined(GLEW_EGL) + getString = (PFNGLGETSTRINGPROC) eglGetProcAddress("glGetString"); + if (!getString) + { + fprintf(stderr, "Error: eglGetProcAddress failed to fetch glGetString\n"); + glewDestroyContext(); + return 1; + } +#endif + #if defined(_WIN32) #if defined(_MSC_VER) && (_MSC_VER >= 1400) if (fopen_s(&f, "glewinfo.txt", "w") != 0) @@ -78,9 +94,15 @@ int main (int argc, char** argv) fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n", params.display == NULL ? getenv("DISPLAY") : params.display, params.visual); #endif +#if defined(GLEW_EGL) + fprintf(f, "Running on a %s from %s\n", + getString(GL_RENDERER), getString(GL_VENDOR)); + fprintf(f, "OpenGL version %s is supported\n", getString(GL_VERSION)); +#else fprintf(f, "Running on a %s from %s\n", glGetString(GL_RENDERER), glGetString(GL_VENDOR)); fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION)); +#endif glewInfo(); #if defined(GLEW_OSMESA) #elif defined(GLEW_EGL)