mirror of
https://github.com/Perlmint/glew-cmake.git
synced 2024-11-11 09:33:49 +00:00
[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:
parent
1da7dd6e0a
commit
731b1e6602
@ -199,12 +199,10 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
|
|||||||
$(BIN)/make_def_var.pl GL $(GL_EXT_SPEC) >> $@
|
$(BIN)/make_def_var.pl GL $(GL_EXT_SPEC) >> $@
|
||||||
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
|
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
|
||||||
echo -e "\nstatic const char * _glewExtensionLookup[] = {" >> $@;
|
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 " NULL\n};\n" >> $@;
|
||||||
echo -e "\n#if !defined(GLEW_MX)" >> $@;
|
echo -e "\n#if !defined(GLEW_MX)" >> $@;
|
||||||
echo -e "\nstatic GLboolean* _glewEnabled[] = {" >> $@;
|
|
||||||
$(BIN)/make_enable_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@
|
$(BIN)/make_enable_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@
|
||||||
echo -e " NULL\n};\n" >> $@;
|
|
||||||
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
|
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
|
||||||
$(BIN)/make_initd.pl GL $(GL_CORE_SPEC) >> $@
|
$(BIN)/make_initd.pl GL $(GL_CORE_SPEC) >> $@
|
||||||
$(BIN)/make_initd.pl GL $(GL_EXT_SPEC) >> $@
|
$(BIN)/make_initd.pl GL $(GL_EXT_SPEC) >> $@
|
||||||
|
@ -22,6 +22,12 @@ if (@ARGV)
|
|||||||
{
|
{
|
||||||
@extlist = @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)
|
foreach my $ext (sort @extlist)
|
||||||
{
|
{
|
||||||
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) =
|
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) =
|
||||||
@ -34,4 +40,6 @@ if (@ARGV)
|
|||||||
print " &__$extvar,\n";
|
print " &__$extvar,\n";
|
||||||
print "#endif\n";
|
print "#endif\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print " NULL\n};\n";
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ if (@ARGV)
|
|||||||
parse_ext($ext);
|
parse_ext($ext);
|
||||||
|
|
||||||
print "#ifdef $extname\n";
|
print "#ifdef $extname\n";
|
||||||
print " \"$extstring\",\n";
|
print " \"$extname\",\n";
|
||||||
print "#endif\n";
|
print "#endif\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,15 +42,10 @@ if (@ARGV)
|
|||||||
|
|
||||||
#my $pextvar = prefix_varname($extvar);
|
#my $pextvar = prefix_varname($extvar);
|
||||||
|
|
||||||
print "#ifdef $extname\n";
|
|
||||||
|
|
||||||
if (length($extstring))
|
|
||||||
{
|
|
||||||
print " " . $extvar . " = _glewSearchExtension(\"$extstring\", extStart, extEnd);\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keys %$functions)
|
if (keys %$functions)
|
||||||
{
|
{
|
||||||
|
print "#ifdef $extname\n";
|
||||||
|
|
||||||
if ($extname =~ /WGL_.*/)
|
if ($extname =~ /WGL_.*/)
|
||||||
{
|
{
|
||||||
print " if (glewExperimental || " . $extvar . "|| crippled) " . $extvar . "= !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n";
|
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 " if (glewExperimental || " . $extvar . ") " . $extvar . " = !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print "#endif /* $extname */\n";
|
||||||
}
|
}
|
||||||
print "#endif /* $extname */\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,7 @@ static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
|
|||||||
return (s[i] == '\0' || s[i] == c) ? i : 0;
|
return (s[i] == '\0' || s[i] == c) ? i : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
|
static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
|
||||||
{
|
{
|
||||||
GLuint i=0;
|
GLuint i=0;
|
||||||
@ -215,6 +216,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++;
|
while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++;
|
||||||
return i == n ? GL_TRUE : GL_FALSE;
|
return i == n ? GL_TRUE : GL_FALSE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
||||||
{
|
{
|
||||||
@ -268,23 +270,3 @@ static GLboolean _glewStrSame3 (const GLubyte** a, GLuint* na, const GLubyte* b,
|
|||||||
}
|
}
|
||||||
return GL_FALSE;
|
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;
|
|
||||||
}
|
|
||||||
|
@ -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)
|
GLboolean GLEWAPIENTRY glewGetExtension (const char* name)
|
||||||
{
|
{
|
||||||
const GLubyte* start;
|
GLboolean *enable = _glewGetExtensionString(name);
|
||||||
const GLubyte* end;
|
if (enable)
|
||||||
start = (const GLubyte*)glGetString(GL_EXTENSIONS);
|
return *enable;
|
||||||
if (start == 0)
|
return GL_FALSE;
|
||||||
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;
|
const GLubyte* s;
|
||||||
GLuint dot;
|
GLuint dot;
|
||||||
GLint major, minor;
|
GLint major, minor;
|
||||||
const GLubyte* extStart;
|
char *begin;
|
||||||
const GLubyte* extEnd;
|
char *end;
|
||||||
|
char *i;
|
||||||
|
char *j;
|
||||||
|
GLboolean *enable;
|
||||||
|
|
||||||
/* query opengl version */
|
/* query opengl version */
|
||||||
s = glGetString(GL_VERSION);
|
s = glGetString(GL_VERSION);
|
||||||
dot = _glewStrCLen(s, '.');
|
dot = _glewStrCLen(s, '.');
|
||||||
@ -37,7 +87,6 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
|
|||||||
if (major<0 || major>9)
|
if (major<0 || major>9)
|
||||||
return GLEW_ERROR_NO_GL_VERSION;
|
return GLEW_ERROR_NO_GL_VERSION;
|
||||||
|
|
||||||
|
|
||||||
if (major == 1 && minor == 0)
|
if (major == 1 && minor == 0)
|
||||||
{
|
{
|
||||||
return GLEW_ERROR_GL_VERSION_10_ONLY;
|
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;
|
GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* query opengl extensions string */
|
memset(_glewExtensionString,0,sizeof(_glewExtensionString));
|
||||||
extStart = glGetString(GL_EXTENSIONS);
|
|
||||||
if (extStart == 0)
|
|
||||||
extStart = (const GLubyte*)"";
|
|
||||||
extEnd = extStart + _glewStrLen(extStart);
|
|
||||||
|
|
||||||
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user