localspl/tests: Add test for DeletePort.
[wine] / dlls / opengl32 / make_opengl
index fb03be1..657617a 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/perl -w
+use strict;
 
 # This script is called thus :
 #
 #       CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
 #       You can find them on the web at the following URL :
 #         http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
+#       You will need gl.tm and gl.spec.
 #
 #     - opengl_version is the OpenGL version emulated by the library
-#       (can be 1.0 to 1.2).
+#       (can be 1.0 to 1.5).
 #
 # This script generates the three following files :
 #
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 #
 
 #
 # Files to generate
 #
-$spec_file = "opengl32.spec";
-$norm_file = "opengl_norm.c";
-$ext_file  = "opengl_ext.c";
+my $spec_file = "opengl32.spec";
+my $norm_file = "opengl_norm.c";
+my $ext_file  = "opengl_ext.c";
 
 # Set to 0 for removing the ENTER / LEAVE GL calls
-$gen_thread_safe = 1;
+my $gen_thread_safe = 1;
 # Prefix used for the local variables
-$ext_prefix = "func_";
+my $ext_prefix = "func_";
 # If set to 1, generate TRACEs for each OpenGL function
-$gen_traces = 1;
+my $gen_traces = 1;
 
 #
 # List of categories to put in the 'opengl_norm.c' file
 #
-%cat_1_0 = ( "display-list" => 1,
+my %cat_1_0 = ( "display-list" => 1,
             "drawing" => 1,
             "drawing-control" => 1,
             "feedback" => 1,
@@ -79,19 +81,24 @@ $gen_traces = 1;
             "pixel-rw" => 1,
             "state-req" => 1,
             "xform" => 1 );
-%cat_1_1 = ( %cat_1_0,
+my %cat_1_1 = ( %cat_1_0,
             "1_1" => 1 );
-%cat_1_2 = ( %cat_1_1,
-            "VERSION_1_2" => 1,
-            "ARB_multitexture" => 1 );
+my %cat_1_2 = ( %cat_1_1,
+            "VERSION_1_2" => 1 );
+my %cat_1_3 = ( %cat_1_2,
+            "VERSION_1_3" => 1 );
+my %cat_1_4 = ( %cat_1_3,
+            "VERSION_1_4" => 1 );
+my %cat_1_5 = ( %cat_1_4,
+            "VERSION_1_5" => 1 );
 
-%norm_categories = ();
+my %norm_categories = ();
 
 #
 # This hash table gives the conversion between OpenGL types and what
 # is used by the TRACE printfs
 #
-%debug_conv =
+my %debug_conv =
     ("GLbitfield" => "%d",
      "GLboolean" => "%d",
      "GLbyte" => "%d",
@@ -107,6 +114,13 @@ $gen_traces = 1;
      "GLubyte" => "%d",
      "GLuint" => "%d",
      "GLushort" => "%d",
+     "GLhalfNV" => "%d",
+     "GLintptrARB" => "%d",
+     "GLsizeiptrARB" => "%d",
+     "GLintptr" => "%d",
+     "GLsizeiptr" => "%d",
+     "GLhandleARB" => "%d",
+     "GLcharARB" => "%c",
      "GLvoid" => "(void)",
      "_GLfuncptr" => "%p");
 
@@ -114,7 +128,7 @@ $gen_traces = 1;
 # This hash table gives the conversion between OpenGL types and what
 # is used in the .spec file
 #
-%arg_conv =
+my %arg_conv =
     ("GLbitfield" => [ "long", 4 ],
      "GLboolean" => [ "long", 4 ],
      "GLbyte" => [ "long", 4 ],
@@ -130,108 +144,183 @@ $gen_traces = 1;
      "GLubyte" => [ "long", 4 ],
      "GLuint" => [ "long", 4 ],
      "GLushort" => [ "long", 4 ],
+     "GLhalfNV" => [ "long", 4 ],
+     "GLintptrARB" => [ "long", 4 ],
+     "GLsizeiptrARB" => [ "long", 4 ],
+     "GLhandleARB" => [ "long", 4 ],
+     "GLcharARB" => [ "long", 4 ],
+     "GLintptr" => [ "long", 4 ],
+     "GLsizeiptr" => [ "long", 4 ],
      "GLvoid" => [ "void", 4 ],
      "_GLfuncptr" => [ "ptr", 4 ]);
 
+#
+# Used to convert some types
+#
+sub ConvertType($)
+{
+    my ($type) = @_;
+
+    my %hash = ( "GLstring" => "const GLubyte *",
+             "GLintptrARB" => "ptrdiff_t",
+             "GLsizeiptrARB" => "ptrdiff_t",
+             "GLintptr" => "ptrdiff_t",
+             "GLsizeiptr" => "ptrdiff_t",
+             "GLhandleARB" => "unsigned int",
+             "GLcharARB" => "char",
+             "GLchar" => "char",
+             "GLhalfNV" => "unsigned short" );
+
+    foreach my $org (reverse sort keys %hash) {
+       if ($type =~ /$org/) {
+           my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
+           return "$before$hash{$org}$after";
+       }
+    }
+    return $type;
+}
+
+#
+# Used to convert some variable names
+#
+sub ConvertVarName($)
+{
+    my ($type) = @_;
+
+    my %hash = ( "near" => "nearParam",
+                 "far"  => "farParam" );
+
+    foreach my $org (keys %hash) {
+       if ($type =~ /$org/) {
+           my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
+           return "$before$hash{$org}$after";
+       }
+    }
+    return $type;
+}
+
 #
 # This functions generates the thunk for a given function.
 #
-sub GenerateThunk {
-    my ($func_ref, $comment, $prefix, $thread_safe) = @_;
-    my ($ret) = ("");
-    my ($call_arg) = ("");
-    my ($trace_arg) = ("");
+sub GenerateThunk($$$$$)
+{
+    my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
+    my $ret = "";
+    my $call_arg = "";
+    my $trace_arg = "";
+    my $wine_func_ref_name = "";
 
     # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
     # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
     if ($comment eq 1) {
-       $ret = $ret . "/***********************************************************************\n";
-       $ret = $ret . " *              " . $func_ref->[0] . " (OPENGL32.@)\n";
-       $ret = $ret . " */\n";
+       $ret = "$ret/***********************************************************************\n";
+       $ret = "$ret *              $func_ref->[0] (OPENGL32.\@)\n";
+       $ret = "$ret */\n";
     }
-    $ret = $ret . $func_ref->[1] . " WINAPI wine_" . $func_ref->[0] . "( ";
-    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
-       $type = $func_ref->[2]->[$i]->[0];
-       $name = $func_ref->[2]->[$i]->[1];
-       $ret = $ret . "$type $name";
-       $call_arg = $call_arg . "$name";
+    $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
+    for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
+       ## Quick debug code :-)
+       ## print $func_ref->[2]->[$i]->[1] . "\n";
+       my $type = $func_ref->[2]->[$i]->[0];
+       my $name = ConvertVarName($func_ref->[2]->[$i]->[1]);
+       $ret = $ret . ConvertType($type) . " $name";
+       $call_arg = "$call_arg$name";
        if ($type =~ /\*/) {
-           $trace_arg = $trace_arg . "%p";
+           $trace_arg = "$trace_arg\%p";
        } else {
-           $trace_arg = $trace_arg . $debug_conv{$type};
+           $trace_arg = "$trace_arg$debug_conv{$type}";
        }
        if ($i != $#{@{$func_ref->[2]}}) {
-           $ret = $ret . ", ";
-           $call_arg = $call_arg . ", ";
-           $trace_arg = $trace_arg . ", ";
+           $ret = "$ret, ";
+           $call_arg = "$call_arg, ";
+           $trace_arg = "$trace_arg, ";
        } else {
-           $ret = $ret . " ";
-           $call_arg = $call_arg . " ";
+           $ret = "$ret ";
+           $call_arg = "$call_arg ";
        }
     }
-    $ret = $ret . ") {\n";
+    $ret .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
+    $ret = "$ret) {\n";
     if ($func_ref->[1] ne "void") {
-       $ret = $ret . "  " . $func_ref->[1] . " ret_value;\n";
+       $ret = "$ret  " . ConvertType($func_ref->[1]) . " ret_value;\n";
     }
+    $ret .= $local_var;
     if ($gen_traces) {
-       $ret = $ret . "  TRACE(\"(" . $trace_arg . ")\\n\"";
+       $ret = "$ret  TRACE(\"($trace_arg)\\n\"";
        if ($trace_arg ne "") {
-           $ret = $ret . ", " . $call_arg;
+           $ret = "$ret, $call_arg";
        }
-       $ret = $ret . ");\n";
+       $ret = "$ret);\n";
     }
     if ($thread_safe) {
-       $ret = $ret . "  ENTER_GL();\n";
+       $ret = "$ret  ENTER_GL();\n";
     }
-    $ret = $ret . "  ";
+    $ret = "$ret  ";
     if ($func_ref->[1] ne "void") {
        $ret = $ret . "ret_value = ";
     }
-    $ret = $ret . $prefix . $func_ref->[0] . "( " . $call_arg . ");\n";
+    $wine_func_ref_name = $func_ref->[0];
+    if ( $func_ref->[0] eq "glGetString" ) {
+       $wine_func_ref_name = "internal_glGetString";
+    }
+    if ( $func_ref->[0] eq "glGetIntegerv" ) {
+       $wine_func_ref_name = "internal_glGetIntegerv";
+    }
+    $ret = "$ret$prefix$wine_func_ref_name( $call_arg);\n";
     if ($thread_safe) {
-       $ret = $ret . "  LEAVE_GL();\n";
+       $ret = "$ret  LEAVE_GL();\n";
     }
     if ($func_ref->[1] ne "void") {
-       $ret = $ret . "  return ret_value;\n"
+       $ret = "$ret  return ret_value;\n"
     }
-    $ret = $ret . "}\n";
+    $ret = "$ret}\n";
 
     # Return this string....
-    $ret;
+    return $ret;
 }
 
 #
 # Extract and checks the number of arguments
 #
-if ($#ARGV != 1) {
-    die "Usage : make_opengl OpenGL_registry_location OpenGL_version.\n";
+if (@ARGV != 2) {
+    my $name0=$0;
+    $name0=~s%^.*/%%;
+    die "Usage: $name0 OpenGL_registry_location OpenGL_version\n";
 }
-$registry_path = shift @ARGV;
-$version       = shift @ARGV;
+my $registry_path = shift @ARGV;
+my $version       = shift @ARGV;
 if ($version eq "1.0") {
     %norm_categories = %cat_1_0;
 } elsif ($version eq "1.1") {
     %norm_categories = %cat_1_1;
 } elsif ($version eq "1.2") {
     %norm_categories = %cat_1_2;
+} elsif ($version eq "1.3") {
+    %norm_categories = %cat_1_3;
+} elsif ($version eq "1.4") {
+    %norm_categories = %cat_1_4;
+} elsif ($version eq "1.5") {
+    %norm_categories = %cat_1_5;
 } else {
-    die "OpenGL version incorrect. Should be one of '1.0', '1.1' or '1.2'.\n";
+    die "Incorrect OpenGL version.\n";
 }
 
 #
 # Open the registry files
 #
-open(TYPES,    $registry_path . "/gl.tm")   || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
-open(REGISTRY, $registry_path . "/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
+open(TYPES,    "$registry_path/gl.tm")   || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
+open(REGISTRY, "$registry_path/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
 
 #
 # First, create a mapping between the pseudo types used in the spec file
 # and OpenGL types using the 'gl.tm' file.
 #
-%pseudo_to_opengl = ();
-while ($line = <TYPES>) {
-    ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
-    $pseudo_to_opengl{$pseudo} = $opengl;
+my %pseudo_to_opengl = ();
+while (my $line = <TYPES>) {
+    if ($line !~ /\w*\#/) {
+       my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
+       $pseudo_to_opengl{$pseudo} = $opengl;
+    }
 }
 # This is to override the 'void' -> '*' bogus conversion
 $pseudo_to_opengl{"void"} = "void";
@@ -279,150 +368,149 @@ $pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
 #     [ "GLfloat", "ymove" ],
 #     [ "GLubyte *", "bitmap"] ] ];
 #
-%norm_functions = ();
+my %norm_functions = ();
 
 #
 # This stores various extensions NOT part of the GL extension registry but still
 # implemented by most OpenGL libraries out there...
 #
-%ext_functions  =
-    ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion" ],
+
+my %ext_functions  =
+    ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
       "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
                                                                [ "GLint", "x" ],
                                                                [ "GLint", "y" ],
                                                                [ "GLsizei", "width" ],
-                                                               [ "GLsizei", "height" ] ], "glReadBufferRegion" ],
+                                                               [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
       "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
                                                                [ "GLint", "x" ],
                                                                [ "GLint", "y" ],
                                                                [ "GLsizei", "width" ],
                                                                [ "GLsizei", "height" ],
                                                                [ "GLint", "xDest" ],
-                                                               [ "GLint", "yDest" ] ], "glDrawBufferRegion" ],
-      "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled" ],
-      "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion" ],
+                                                               [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
+      "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled",  "GL_KTX_buffer_region" ],
+      "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
       "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
                                                              [ "GLfloat", "s" ],
-                                                             [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS" ],
+                                                             [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
       "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
-                                                               [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS" ],
+                                                               [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
-                                                                     [ "GLdouble", "s" ] ],  "glMultiTexCoord1dSGIS" ],
+                                                                     [ "GLdouble", "s" ] ],  "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
+                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
-                                                                     [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
+                                                                     [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
+                                                                       [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
-                                                                     [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
+                                                                     [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
+                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
-                                                                     [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
+                                                                     [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
+                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLdouble", "s"],
-                                                                     [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
+                                                                     [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
+                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLfloat", "s" ],
-                                                                     [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
+                                                                     [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
+                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLint", "s" ],
-                                                                     [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
+                                                                     [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
+                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLshort", "s" ],
-                                                                     [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
+                                                                     [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
+                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLdouble", "s" ],
                                                                      [ "GLdouble", "t" ],
-                                                                     [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
+                                                                     [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
+                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLfloat", "s" ],
                                                                      [ "GLfloat", "t" ],
-                                                                     [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
+                                                                     [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
+                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLint", "s" ],
                                                                      [ "GLint", "t" ],
-                                                                     [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
+                                                                     [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
+                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLshort", "s" ],
                                                                      [ "GLshort", "t" ],
-                                                                     [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
+                                                                     [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
+                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLdouble", "s" ],
                                                                      [ "GLdouble", "t" ],
                                                                      [ "GLdouble", "r" ],
-                                                                     [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
+                                                                     [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
+                                                                       [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLfloat", "s" ],
                                                                      [ "GLfloat", "t" ],
                                                                      [ "GLfloat", "r" ],
-                                                                     [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
+                                                                     [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
+                                                                       [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLint", "s" ],
                                                                      [ "GLint", "t" ],
                                                                      [ "GLint", "r" ],
-                                                                     [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
+                                                                     [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
+                                                                       [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
                                                                      [ "GLshort", "s" ],
                                                                      [ "GLshort", "t" ],
                                                                      [ "GLshort", "r" ],
-                                                                     [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
+                                                                     [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
-                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
+                                                                       [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
       "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
                                                                                [ "GLint", "size" ],
                                                                                [ "GLenum", "type" ],
                                                                                [ "GLsizei", "stride" ],
-                                                                               [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
-      "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
-      "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
-      "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
-                                                                   [ "GLfloat", "readfreq" ],
-                                                                   [ "GLfloat", "writefreq"],
-                                                                   [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
-      "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ]
+                                                                               [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
+      "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
+      "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
+      "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
       );
 
-
-while ($line = <REGISTRY>) {
+my @arg_names;
+my %arg_types;
+while (my $line = <REGISTRY>) {
     if ($line =~ /^\w*\(.*\)/) {
        # Get the function name (NOTE: the 'gl' prefix needs to be added later)
-       ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
+       my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
        # and the argument names
        @arg_names = split /\s*,\s*/, $args;
 
        # After get :
        #  - the return type
+       #  - category (the extension the function is part of)
        #  - the argument types
        #  - the category the function belongs
        %arg_types = ();
-       $category = "";
-       $ret_type = "";
+       my $category = "";
+       my $ret_type = "";
        while (1) {
            $line = <REGISTRY>;
            unless (defined($line)) {
@@ -441,8 +529,8 @@ while ($line = <REGISTRY>) {
            } elsif ($line =~ /^\t*category/) {
                ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
            } elsif ($line =~ /^\t*param/) {
-               ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
-               $ptr = 0;
+               my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
+               my $ptr = 0;
                unless (defined($name)) {
                    chomp $line;
                    die "Broken spec file line $line in function $funcname\n";
@@ -459,13 +547,13 @@ while ($line = <REGISTRY>) {
                    die "Unsupported type : $line in function $funcname\n";
                }
                # Get the 'real' type and append a '*' in case of a pointer
-               $type = $pseudo_to_opengl{$base_type};
+               my $type = $pseudo_to_opengl{$base_type};
                unless (defined($type)) {
                    chomp $line;
                    die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
                }
                if ($ptr) {
-                   $type = $type . "*";
+                   $type = "$type*";
                }
 
                $arg_types{$name} = $type;
@@ -473,8 +561,8 @@ while ($line = <REGISTRY>) {
        }
 
        # Now, build the argument reference
-       $arg_ref = [ ];
-       for ($i = 0; $i <= $#arg_names; $i++) {
+       my $arg_ref = [ ];
+       for (my $i = 0; $i <= $#arg_names; $i++) {
            unless (defined($arg_types{$arg_names[$i]})) {
                print "@arg_names\n";
                foreach (sort keys %arg_types) {
@@ -485,16 +573,17 @@ while ($line = <REGISTRY>) {
 
            push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
        }
-       $func_ref = [ "gl" . $funcname,
-                     $ret_type,
-                     $arg_ref,
-                     "gl" . $funcname ];
+       my $func_ref = [ "gl$funcname",
+                         $ret_type,
+                         $arg_ref,
+                         "gl$funcname",
+                         "GL_$category" ];
 
        # Now, put in one or the other hash table
        if ($norm_categories{$category}) {
-           $norm_functions{"gl" . $funcname} = $func_ref;
+           $norm_functions{"gl$funcname"} = $func_ref;
        } else {
-           $ext_functions{"gl" . $funcname} = $func_ref;
+           $ext_functions{"gl$funcname"} = $func_ref;
        }
     }
 }
@@ -508,7 +597,7 @@ close(REGISTRY);
 #
 # Now, generate the output files. First, the spec file.
 #
-open(SPEC, ">" . $spec_file);
+open(SPEC, ">$spec_file");
 
 print SPEC "@  stdcall wglCreateContext(long)
 @  stdcall wglCreateLayerContext(long long)
@@ -517,7 +606,6 @@ print SPEC "@  stdcall wglCreateContext(long)
 @  stdcall wglDescribeLayerPlane(long long long long ptr)
 @  stdcall wglGetCurrentContext()
 @  stdcall wglGetCurrentDC()
-@  stdcall wglGetExtensionsStringEXT()
 @  stdcall wglGetLayerPaletteEntries(long long long long ptr)
 @  stdcall wglGetProcAddress(str)
 @  stdcall wglMakeCurrent(long long)
@@ -529,7 +617,7 @@ print SPEC "@  stdcall wglCreateContext(long)
 @  stdcall wglUseFontOutlinesA(long long long long long long long ptr)
 @  stub    glGetLevelParameterfv
 @  stub    glGetLevelParameteriv
-@  stub    wglUseFontBitmapsW
+@  stdcall wglUseFontBitmapsW(long long long long)
 @  stub    wglUseFontOutlinesW
 @  stub    wglGetDefaultProcAddress
 @  stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
@@ -540,16 +628,16 @@ print SPEC "@  stdcall wglCreateContext(long)
 ";
 
 foreach (sort keys %norm_functions) {
-    $func_name = $norm_functions{$_}->[0];
+    my $func_name = $norm_functions{$_}->[0];
     print SPEC "@  stdcall $func_name( ";
-    for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
-       $type = $norm_functions{$_}->[2]->[$i]->[0];
+    for (my $i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
+       my $type = $norm_functions{$_}->[2]->[$i]->[0];
        if ($type =~ /\*/) {
            print SPEC "ptr ";
        } elsif (defined($arg_conv{$type})) {
            print SPEC "$@$arg_conv{$type}[0] ";
        } else {
-           die "No convertion for GL type $type...\n";
+           die "No conversion for GL type $type...\n";
        }
     }
     print SPEC ") wine_$func_name\n";
@@ -559,7 +647,7 @@ close(SPEC);
 #
 # After the spec file, the opengl_norm.c file
 #
-open(NORM, ">" . $norm_file);
+open(NORM, ">$norm_file");
 print NORM "
 /* Auto-generated file... Do not edit ! */
 
@@ -567,22 +655,19 @@ print NORM "
 #include \"opengl_ext.h\"
 #include \"wine/debug.h\"
 
-typedef const GLubyte * GLstring;
-
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
-
 ";
 foreach (sort keys %norm_functions) {
-    $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
+    my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
 
-    print NORM "$string\n";
+    print NORM "\n$string";
 }
 close(NORM);
 
 #
 # Finally, more complex, the opengl_ext.c file
 #
-open(EXT, ">" . $ext_file);
+open(EXT, ">$ext_file");
 print EXT "
 /* Auto-generated file... Do not edit ! */
 
@@ -590,55 +675,45 @@ print EXT "
 #include \"opengl_ext.h\"
 #include \"wine/debug.h\"
 
-typedef const GLubyte * GLstring;
-
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
 
 ";
 
-# First, generate the function pointers
+# The thunks themselves....
+my $count = keys %ext_functions;
+print EXT "const int extension_registry_size = $count;\n";
+print EXT "void *extension_funcs[$count];\n";
+print EXT "\n/* The thunks themselves....*/";
+my $pos = 0;
 foreach (sort keys %ext_functions) {
-    $func_ref = $ext_functions{$_};
-    print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
-    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
-       $type = $func_ref->[2]->[$i]->[0];
-       print EXT "$type";
+    my $func_ref = $ext_functions{$_};
+    my $local_var = "  " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
+    for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
+       my $type = ConvertType($func_ref->[2]->[$i]->[0]);
+       $local_var .= "$type";
        if ($i != $#{@{$func_ref->[2]}}) {
-           print EXT ", ";
+           $local_var .= ", ";
        } else {
-           print EXT " ";
+           $local_var .= " ";
        }
     }
-    print EXT ") = (void *) 0xdeadbeef;\n";
-}
-
-# Then, the function prototypes
-print EXT "\n\n/* The function prototypes */\n";
-foreach (sort keys %ext_functions) {
-    $func_ref = $ext_functions{$_};
-    print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
-    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
-       $type = $func_ref->[2]->[$i]->[0];
-       print EXT "$type";
-       if ($i != $#{@{$func_ref->[2]}}) {
-           print EXT ", ";
-       } else {
-           print EXT " ";
-       }
-    }
-    print EXT ");\n";
+    $local_var .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
+    $local_var .= ") = extension_funcs[$pos];\n";
+    $pos++;
+    print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
 }
 
 # Then the table giving the string <-> function correspondance */
 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
-@tmp = keys %ext_functions;
-print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
-print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
-$i = 0;
+print EXT "const OpenGL_extension extension_registry[$count] = {\n";
+my $i = 0;
 foreach (sort keys %ext_functions) {
-    $func_ref = $ext_functions{$_};
-    print EXT "  { \"" . $func_ref->[0] . "\", \"" . $func_ref->[3] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
-    if ($i != $#tmp) {
+    my $func_ref = $ext_functions{$_};
+    if ($func_ref->[0] eq $func_ref->[3])
+    {
+        print EXT "  { \"$func_ref->[0]\", \"$func_ref->[4]\", (void *) wine_$func_ref->[0] }";
+    }
+    if ($i != $count-1) {
        print EXT ",";
     }
     $i++;
@@ -646,11 +721,4 @@ foreach (sort keys %ext_functions) {
 }
 print EXT "};\n";
 
-# And, finally, the thunks themselves....
-print EXT "\n/* The thunks themselves....*/\n";
-foreach (sort keys %ext_functions) {
-    $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
-
-    print EXT "$string\n";
-}
 close(EXT);