[CoreSupport] Represent the extension string(s) as an array of GLboolean - _glewGetExtensionString and _glewGetExtensionEnable

glewinfo output is identical.
TODO core context glGetStringi support.
TODO MX support.
This commit is contained in:
Nigel Stewart 2015-02-21 14:09:39 +10:00
parent a10e865e7d
commit 02ccdadb86
7 changed files with 109 additions and 52 deletions

View File

@ -195,12 +195,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) >> $@

View File

@ -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";
}

View File

@ -32,7 +32,7 @@ if (@ARGV)
parse_ext($ext);
print "#ifdef $extname\n";
print " \"$extstring\",\n";
print " \"$extname\",\n";
print "#endif\n";
}
}

View File

@ -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 "\nGLboolean " . prefix_varname($extvar) . " = GL_FALSE;\n\n";
print "#endif /* $extname */\n\n";
}
}
}

View File

@ -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";
}
}
}

View File

@ -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;
}

View File

@ -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)
GLboolean *enable = _glewGetExtensionString(name);
if (enable)
return *enable;
return GL_FALSE;
end = start + _glewStrLen(start);
return _glewSearchExtension(name, start, end);
}
/* ------------------------------------------------------------------------- */
@ -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<end; i = j + 1)
{
i = _glewNextNonSpace(i);
j = _glewNextSpace(i);
*j = 0;
/* Based on extension string(s), glewGetExtension purposes */
enable = _glewGetExtensionString(i);
if (enable)
*enable = GL_TRUE;
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
enable = _glewGetExtensionEnable(i);
if (enable)
*enable = GL_TRUE;
}
free(begin);
}
}