From 1b38b41837379649cc5f86b167b470be368c2a1d Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Wed, 30 Mar 2011 11:38:25 -0500 Subject: [PATCH] Patch ID: 3260500 - Query extension string only once --- auto/bin/make_list.pl | 2 +- auto/src/glew_head.c | 20 ++++++++++++++++++++ auto/src/glew_init_gl.c | 35 ++++++++++++++++------------------- auto/src/glew_init_glx.c | 29 +++++++++++++++-------------- auto/src/glew_init_wgl.c | 33 +++++++++++++++++++-------------- 5 files changed, 71 insertions(+), 48 deletions(-) diff --git a/auto/bin/make_list.pl b/auto/bin/make_list.pl index ceaa479..5571ea9 100755 --- a/auto/bin/make_list.pl +++ b/auto/bin/make_list.pl @@ -46,7 +46,7 @@ if (@ARGV) if (length($extstring)) { - print " CONST_CAST(" . $extvar . ") = " . $extpre . "GetExtension(\"$extstring\");\n"; + print " CONST_CAST(" . $extvar . ") = _glewSearchExtension(\"$extstring\", start, end);\n"; } if (keys %$functions) diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index df16210..c6c50a7 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -217,3 +217,23 @@ static GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuin } 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 33bd85e..0779939 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -1,26 +1,14 @@ /* ------------------------------------------------------------------------- */ -/* - * 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. - */ GLboolean glewGetExtension (const char* name) { - GLubyte* p; - GLubyte* end; - GLuint len = _glewStrLen((const GLubyte*)name); - p = (GLubyte*)glGetString(GL_EXTENSIONS); - if (0 == p) return GL_FALSE; - end = p + _glewStrLen(p); - 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; + const GLubyte* start; + const GLubyte* end; + start = (const GLubyte*)glGetString(GL_EXTENSIONS); + if (start == 0) + return GL_FALSE; + end = start + _glewStrLen(start); + return _glewSearchExtension(name, start, end); } /* ------------------------------------------------------------------------- */ @@ -33,6 +21,8 @@ GLenum glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) const GLubyte* s; GLuint dot; GLint major, minor; + const GLubyte* start; + const GLubyte* end; /* query opengl version */ s = glGetString(GL_VERSION); dot = _glewStrCLen(s, '.'); @@ -69,4 +59,11 @@ GLenum glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) CONST_CAST(GLEW_VERSION_1_2) = GLEW_VERSION_1_2_1 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE; CONST_CAST(GLEW_VERSION_1_1) = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE; } + + /* query opengl extensions string */ + start = glGetString(GL_EXTENSIONS); + if (start == 0) + start = (const GLubyte*)""; + end = start + _glewStrLen(start); + /* initialize extensions */ diff --git a/auto/src/glew_init_glx.c b/auto/src/glew_init_glx.c index c66e24c..37bbee1 100644 --- a/auto/src/glew_init_glx.c +++ b/auto/src/glew_init_glx.c @@ -2,27 +2,21 @@ GLboolean glxewGetExtension (const char* name) { - GLubyte* p; - GLubyte* end; - GLuint len; + const GLubyte* start; + const GLubyte* end; if (glXGetCurrentDisplay == NULL) return GL_FALSE; - len = _glewStrLen((const GLubyte*)name); - p = (GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); - if (0 == p) return GL_FALSE; - end = p + _glewStrLen(p); - 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; + start = (const GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); + if (0 == start) return GL_FALSE; + end = start + _glewStrLen(start); + return _glewSearchExtension(name, start, end); } GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST) { int major, minor; + const GLubyte* start; + const GLubyte* end; /* initialize core GLX 1.2 */ if (_glewInit_GLX_VERSION_1_2(GLEW_CONTEXT_ARG_VAR_INIT)) return GLEW_ERROR_GLX_VERSION_11_ONLY; /* initialize flags */ @@ -49,4 +43,11 @@ GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST) break; } } + /* query GLX extension string */ + start = 0; + if (glXGetCurrentDisplay != NULL) + start = (const GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); + if (start == 0) + start = (const GLubyte *)""; + end = start + _glewStrLen(start); /* initialize extensions */ diff --git a/auto/src/glew_init_wgl.c b/auto/src/glew_init_wgl.c index e66de42..c37e084 100644 --- a/auto/src/glew_init_wgl.c +++ b/auto/src/glew_init_wgl.c @@ -5,32 +5,37 @@ static PFNWGLGETEXTENSIONSSTRINGEXTPROC _wglewGetExtensionsStringEXT = NULL; GLboolean wglewGetExtension (const char* name) { - GLubyte* p; - GLubyte* end; - GLuint len = _glewStrLen((const GLubyte*)name); + const GLubyte* start; + const GLubyte* end; if (_wglewGetExtensionsStringARB == NULL) if (_wglewGetExtensionsStringEXT == NULL) return GL_FALSE; else - p = (GLubyte*)_wglewGetExtensionsStringEXT(); + start = (const GLubyte*)_wglewGetExtensionsStringEXT(); else - p = (GLubyte*)_wglewGetExtensionsStringARB(wglGetCurrentDC()); - if (0 == p) return GL_FALSE; - end = p + _glewStrLen(p); - 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; + start = (const GLubyte*)_wglewGetExtensionsStringARB(wglGetCurrentDC()); + if (start == 0) + return GL_FALSE; + end = start + _glewStrLen(start); + return _glewSearchExtension(name, start, end); } GLenum wglewContextInit (WGLEW_CONTEXT_ARG_DEF_LIST) { GLboolean crippled; + const GLubyte* start; + const GLubyte* end; /* find wgl extension string query functions */ _wglewGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)glewGetProcAddress((const GLubyte*)"wglGetExtensionsStringARB"); _wglewGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)glewGetProcAddress((const GLubyte*)"wglGetExtensionsStringEXT"); + /* query wgl extension string */ + if (_wglewGetExtensionsStringARB == NULL) + if (_wglewGetExtensionsStringEXT == NULL) + start = (const GLubyte*)""; + else + start = (const GLubyte*)_wglewGetExtensionsStringEXT(); + else + start = (const GLubyte*)_wglewGetExtensionsStringARB(wglGetCurrentDC()); + end = start + _glewStrLen(start); /* initialize extensions */ crippled = _wglewGetExtensionsStringARB == NULL && _wglewGetExtensionsStringEXT == NULL;