Load core function pointers before checking the extension string.

For GL versions since 3.0 the glGetString() function is deprecated or removed,
and the right way to query extensions is glGetStringi(), but that has to be
loaded first.

Also instead of searching the whole extension string n times lookup the
known extensions in a static hash table. The hash table is built with
the gperf utility.
This commit is contained in:
Matthias Bentrup 2015-02-04 15:27:59 +01:00 committed by Nigel Stewart
parent dd6e034cba
commit e935fcad83
7 changed files with 111 additions and 7 deletions

View File

@ -183,7 +183,16 @@ $(I.DEST)/glxew.h: $(EXT)/.dummy
perl -e "s/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_0;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_1;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/" -pi $@ perl -e "s/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/GLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_0;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_1;\nGLXEW_VAR_EXPORT GLboolean __GLXEW_VERSION_1_2;/" -pi $@
cat $(SRC)/glxew_tail.h >> $@ cat $(SRC)/glxew_tail.h >> $@
$(S.DEST)/glew.c: $(EXT)/.dummy $(SRC)/glew.gperf: $(EXT)/.dummy
@echo "--------------------------------------------------------------------"
@echo "Creating glew.gperf"
@echo "--------------------------------------------------------------------"
$(BIN)/make_gperf.pl $(GL_EXT_SPEC) $(WGL_EXT_SPEC) $(GLX_EXT_SPEC) > $@
$(SRC)/glew_init_hash.c: $(SRC)/glew.gperf
gperf -m 10 --output-file=$@ $(SRC)/glew.gperf
$(S.DEST)/glew.c: $(EXT)/.dummy $(SRC)/glew_init_hash.c
@echo "--------------------------------------------------------------------" @echo "--------------------------------------------------------------------"
@echo "Creating glew.c" @echo "Creating glew.c"
@echo "--------------------------------------------------------------------" @echo "--------------------------------------------------------------------"
@ -209,8 +218,10 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
echo -e "" >> $@; echo -e "" >> $@;
$(BIN)/make_init.pl GL $(GL_CORE_SPEC) >> $@ $(BIN)/make_init.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_init.pl GL $(GL_EXT_SPEC) >> $@ $(BIN)/make_init.pl GL $(GL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_hash.c | grep -v '^#line' >> $@
cat $(SRC)/glew_init_gl.c >> $@ cat $(SRC)/glew_init_gl.c >> $@
$(BIN)/make_list.pl $(GL_CORE_SPEC) | grep -v '\"GL_VERSION' >> $@ $(BIN)/make_list.pl $(GL_CORE_SPEC) >> $@
cat $(SRC)/glew_init_glext.c >> $@
$(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@ $(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n" >> $@ echo -e "\n return GLEW_OK;\n}\n" >> $@
echo -e "\n#if defined(_WIN32) && ! defined(GLEW_OSMESA)" >> $@ echo -e "\n#if defined(_WIN32) && ! defined(GLEW_OSMESA)" >> $@

41
auto/bin/make_gperf.pl Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/perl
##
## Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
## Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
##
## This program is distributed under the terms and conditions of the GNU
## General Public License Version 2 as published by the Free Software
## Foundation or, at your option, any later version.
use strict;
use warnings;
do 'bin/make.pl';
my @extlist = ();
my %extensions = ();
our $type = shift;
if (@ARGV)
{
@extlist = @ARGV;
print "%struct-type\n";
print "%compare-lengths\n";
print "%define initializer-suffix ,NULL\n";
print "%7bit\n";
print "struct initflag { const char *name; GLboolean *flag; };\n";
print "%%\n";
foreach my $ext (sort @extlist)
{
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) = parse_ext($ext);
my $extvar = $extname;
$extvar =~ s/GL(X*)_/GL$1EW_/;
my $prefix = $extvar;
$prefix =~ s/_.*//;
print $extname . ", " . $prefix . "_GET_REF(__" . $extvar . ")\n";
}
}

View File

@ -47,11 +47,6 @@ if (@ARGV)
print "#ifdef $extname\n"; print "#ifdef $extname\n";
} }
if (length($extstring) && $extstring !~ /^GL_/)
{
print " " . $extvar . " = _glewSearchExtension(\"$extstring\", extStart, extEnd);\n";
}
if (keys %$functions) if (keys %$functions)
{ {
if ($extname =~ /WGL_.*/) if ($extname =~ /WGL_.*/)

View File

@ -13,6 +13,8 @@
#include <stdlib.h> /* For malloc, free */ #include <stdlib.h> /* For malloc, free */
#include <string.h> /* For memset */ #include <string.h> /* For memset */
extern int memcmp(const void *, const void *, size_t);
#if defined(GLEW_REGAL) #if defined(GLEW_REGAL)
/* In GLEW_REGAL mode we call direcly into the linked /* In GLEW_REGAL mode we call direcly into the linked

View File

@ -0,0 +1,23 @@
/* query opengl extensions string */
extStart = glGetString(GL_EXTENSIONS);
if (extStart == 0)
extStart = (const GLubyte*)"";
extEnd = extStart + _glewStrLen(extStart);
while (extStart < extEnd)
{
GLuint len = _glewStrCLen(extStart, ' ');
struct initflag *ptr = in_word_set(extStart, len);
if (ptr != NULL && ptr->flag != NULL) {
#ifdef GLEW_MX
*(GLboolean *)((char *)ctx + (size_t)(ptr->flag)) = GL_TRUE;
#else
*ptr->flag = GL_TRUE;
#endif
}
extStart += len + 1;
}
/* initialize extensions */

View File

@ -50,4 +50,20 @@ GLenum glxewInit ()
if (extStart == 0) if (extStart == 0)
extStart = (const GLubyte *)""; extStart = (const GLubyte *)"";
extEnd = extStart + _glewStrLen(extStart); extEnd = extStart + _glewStrLen(extStart);
while (extStart < extEnd)
{
GLuint len = _glewStrCLen(extStart, ' ');
struct initflag *ptr = in_word_set(extStart, len);
if (ptr != NULL && ptr->flag != NULL) {
#ifdef GLEW_MX
*(GLboolean *)((char *)ctx + (size_t)(ptr->flag)) = GL_TRUE;
#else
*ptr->flag = GL_TRUE;
#endif
}
extStart += len + 1;
}
/* initialize extensions */ /* initialize extensions */

View File

@ -37,5 +37,21 @@ GLenum GLEWAPIENTRY wglewInit ()
else else
extStart = (const GLubyte*)_wglewGetExtensionsStringARB(wglGetCurrentDC()); extStart = (const GLubyte*)_wglewGetExtensionsStringARB(wglGetCurrentDC());
extEnd = extStart + _glewStrLen(extStart); extEnd = extStart + _glewStrLen(extStart);
while (extStart < extEnd)
{
GLuint len = _glewStrCLen(extStart, ' ');
struct initflag *ptr = in_word_set(extStart, len);
if (ptr != NULL && ptr->flag != NULL) {
#ifdef GLEW_MX
*(GLboolean *)((char *)ctx + (size_t)(ptr->flag)) = GL_TRUE;
#else
*ptr->flag = GL_TRUE;
#endif
}
extStart += len + 1;
}
/* initialize extensions */ /* initialize extensions */
crippled = _wglewGetExtensionsStringARB == NULL && _wglewGetExtensionsStringEXT == NULL; crippled = _wglewGetExtensionsStringARB == NULL && _wglewGetExtensionsStringEXT == NULL;