From 041e5efc85208bf02319a7e47ad797cbd107bbca Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 21 Feb 2015 23:29:40 +1000 Subject: [PATCH] [CoreSupport] Linux/GLX touch-ups for extension string parsing and enable lookup. --- auto/src/glew_head.c | 24 ++++++++++++++++++++++-- auto/src/glew_init_gl.c | 22 +++++++++++++--------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index 22da593..80d6cc1 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -7,6 +7,8 @@ #endif #include /* For size_t */ +#include /* memset, etc */ +#include /* * Define glewGetContext and related helper macros. @@ -202,7 +204,6 @@ static GLuint _glewStrCLen (const GLubyte* s, GLubyte c) return (s[i] == '\0' || s[i] == c) ? i : 0; } -#if 0 static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n) { GLuint i=0; @@ -211,7 +212,6 @@ static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n) while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++; return i == n ? GL_TRUE : GL_FALSE; } -#endif static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb) { @@ -265,3 +265,23 @@ static GLboolean _glewStrSame3 (const GLubyte** a, GLuint* na, const GLubyte* b, } return GL_FALSE; } + +/* + * Search for name in the extensions string. Use of strstr() + * is not sufficient because extension names can be prefixes of + * other extension names. Could use strtok() but the constant + * string returned by glGetString might be in read-only memory. + */ +static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end) +{ + const GLubyte* p; + GLuint len = _glewStrLen((const GLubyte*)name); + p = start; + while (p < end) + { + GLuint n = _glewStrCLen(p, ' '); + if (len == n && _glewStrSame((const GLubyte*)name, p, n)) return GL_TRUE; + p += n+1; + } + return GL_FALSE; +} diff --git a/auto/src/glew_init_gl.c b/auto/src/glew_init_gl.c index 336f9ea..c4548ad 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -2,7 +2,7 @@ static int _glewExtensionCompare(const void *a, const void *b) { - return strcmp((const char *) a, *(const char**) b); + return strcmp((const char *) a, *(const char * const *) b); } static GLboolean *_glewGetExtensionString(const char *name) @@ -67,11 +67,6 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) const GLubyte* s; GLuint dot; GLint major, minor; - char *begin; - char *end; - char *i; - char *j; - GLboolean *enable; /* query opengl version */ s = glGetString(GL_VERSION); @@ -121,6 +116,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) GLint i; PFNGLGETSTRINGIPROC getStringi; const char *ext; + GLboolean *enable; glGetIntegerv(GL_NUM_EXTENSIONS, &n); @@ -144,10 +140,18 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) } else { - begin = (char *) glGetString(GL_EXTENSIONS); - if (begin) + const char *ext; + char *begin; + char *end; + char *i; + char *j; + GLboolean *enable; + + ext = (const char *) glGetString(GL_EXTENSIONS); + + if (ext) { - begin = strdup(begin); + begin = strdup(ext); end = begin + strlen(begin); for (i=begin; i