diff --git a/auto/Makefile b/auto/Makefile index b31c569..9f7335e 100644 --- a/auto/Makefile +++ b/auto/Makefile @@ -199,12 +199,10 @@ $(S.DEST)/glew.c: $(EXT)/.dummy $(BIN)/make_def_var.pl GL $(GL_EXT_SPEC) >> $@ echo -e "\n#endif /* !GLEW_MX */\n" >> $@; echo -e "\nstatic const char * _glewExtensionLookup[] = {" >> $@; - $(BIN)/make_index.pl $(GL_EXT_SPEC) >> $@ + $(BIN)/make_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@ echo -e " NULL\n};\n" >> $@; echo -e "\n#if !defined(GLEW_MX)" >> $@; - echo -e "\nstatic GLboolean* _glewEnabled[] = {" >> $@; $(BIN)/make_enable_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@ - echo -e " NULL\n};\n" >> $@; echo -e "\n#endif /* !GLEW_MX */\n" >> $@; $(BIN)/make_initd.pl GL $(GL_CORE_SPEC) >> $@ $(BIN)/make_initd.pl GL $(GL_EXT_SPEC) >> $@ diff --git a/auto/bin/make_enable_index.pl b/auto/bin/make_enable_index.pl index 53cdf75..48c521d 100755 --- a/auto/bin/make_enable_index.pl +++ b/auto/bin/make_enable_index.pl @@ -22,6 +22,12 @@ if (@ARGV) { @extlist = @ARGV; + print "/* Detected in the extension string or strings */\n"; + print "static GLboolean _glewExtensionString[" . scalar @extlist . "];\n"; + + print "/* Detected via extension string or experimental mode */\n"; + print "static GLboolean* _glewExtensionEnabled[] = {\n";; + foreach my $ext (sort @extlist) { my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) = @@ -34,4 +40,6 @@ if (@ARGV) print " &__$extvar,\n"; print "#endif\n"; } + + print " NULL\n};\n"; } diff --git a/auto/bin/make_index.pl b/auto/bin/make_index.pl index 2d06979..45eca07 100755 --- a/auto/bin/make_index.pl +++ b/auto/bin/make_index.pl @@ -32,7 +32,7 @@ if (@ARGV) parse_ext($ext); print "#ifdef $extname\n"; - print " \"$extstring\",\n"; + print " \"$extname\",\n"; print "#endif\n"; } } diff --git a/auto/bin/make_init.pl b/auto/bin/make_init.pl index 70abc98..5e6200a 100755 --- a/auto/bin/make_init.pl +++ b/auto/bin/make_init.pl @@ -38,18 +38,17 @@ if (@ARGV) parse_ext($ext); #make_separator($extname); - print "#ifdef $extname\n\n"; my $extvar = $extname; my $extvardef = $extname; $extvar =~ s/GL(X*)_/GL$1EW_/; if (keys %$functions) { + print "#ifdef $extname\n\n"; print "static GLboolean _glewInit_$extname (" . $type . "EW_CONTEXT_ARG_DEF_INIT)\n{\n GLboolean r = GL_FALSE;\n"; output_decls($functions, \&make_pfn_def_init); print "\n return r;\n}\n\n"; + print "#endif /* $extname */\n\n"; } - #print "\nGLboolean " . prefix_varname($extvar) . " = GL_FALSE;\n\n"; - print "#endif /* $extname */\n\n"; } } diff --git a/auto/bin/make_list.pl b/auto/bin/make_list.pl index 75dc060..7cea8c8 100755 --- a/auto/bin/make_list.pl +++ b/auto/bin/make_list.pl @@ -42,15 +42,10 @@ if (@ARGV) #my $pextvar = prefix_varname($extvar); - print "#ifdef $extname\n"; - - if (length($extstring)) - { - print " " . $extvar . " = _glewSearchExtension(\"$extstring\", extStart, extEnd);\n"; - } - if (keys %$functions) { + print "#ifdef $extname\n"; + if ($extname =~ /WGL_.*/) { print " if (glewExperimental || " . $extvar . "|| crippled) " . $extvar . "= !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; @@ -59,8 +54,9 @@ if (@ARGV) { print " if (glewExperimental || " . $extvar . ") " . $extvar . " = !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; } + + print "#endif /* $extname */\n"; } - print "#endif /* $extname */\n"; } } diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index e945bcd..22da593 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -202,6 +202,7 @@ 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; @@ -210,6 +211,7 @@ 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) { @@ -263,23 +265,3 @@ 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 c438792..8606b24 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -1,14 +1,60 @@ /* ------------------------------------------------------------------------- */ +static int _glewExtensionCompare(const void *a, const void *b) +{ + return strcmp((const char *) a, *(const char**) b); +} + +static GLboolean *_glewGetExtensionString(const char *name) +{ + const char **n = (const char **) bsearch(name, _glewExtensionLookup, sizeof(_glewExtensionLookup)/sizeof(char *)-1, sizeof(char *), _glewExtensionCompare); + int i; + + if (n) + { + i = n-_glewExtensionLookup; + return _glewExtensionString+i; + } + + return NULL; +} + +static GLboolean *_glewGetExtensionEnable(const char *name) +{ + const char **n = (const char **) bsearch(name, _glewExtensionLookup, sizeof(_glewExtensionLookup)/sizeof(char *)-1, sizeof(char *), _glewExtensionCompare); + int i; + + if (n) + { + i = n-_glewExtensionLookup; + return _glewExtensionEnabled[i]; + } + + return NULL; +} + +static char *_glewNextSpace(char *i) +{ + char *j = i; + if (j) + while (*j!=' ' && *j) ++j; + return j; +} + +static char *_glewNextNonSpace(char *i) +{ + char *j = i; + if (j) + while (*j==' ') ++j; + return j; +} + GLboolean GLEWAPIENTRY glewGetExtension (const char* name) -{ - 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); +{ + GLboolean *enable = _glewGetExtensionString(name); + if (enable) + return *enable; + return GL_FALSE; } /* ------------------------------------------------------------------------- */ @@ -21,8 +67,12 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) const GLubyte* s; GLuint dot; GLint major, minor; - const GLubyte* extStart; - const GLubyte* extEnd; + char *begin; + char *end; + char *i; + char *j; + GLboolean *enable; + /* query opengl version */ s = glGetString(GL_VERSION); dot = _glewStrCLen(s, '.'); @@ -37,7 +87,6 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) if (major<0 || major>9) return GLEW_ERROR_NO_GL_VERSION; - if (major == 1 && minor == 0) { return GLEW_ERROR_GL_VERSION_10_ONLY; @@ -64,10 +113,35 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE; } - /* query opengl extensions string */ - extStart = glGetString(GL_EXTENSIONS); - if (extStart == 0) - extStart = (const GLubyte*)""; - extEnd = extStart + _glewStrLen(extStart); + memset(_glewExtensionString,0,sizeof(_glewExtensionString)); - /* initialize extensions */ + if (GLEW_VERSION_3_0) + { + /* TODO */ + } + else + { + begin = (char *) glGetString(GL_EXTENSIONS); + if (begin) + { + begin = strdup(begin); + end = begin + strlen(begin); + for (i=begin; i