wbemprox: Implement IEnumWbemClassObject::Clone.
[wine] / dlls / opengl32 / make_opengl
1 #!/usr/bin/perl -w
2 use strict;
3
4 # This script is called thus :
5 #
6 #   make_opengl [opengl_version]
7 #
8 #     - It needs the gl.spec and gl.tm files in the current directory.
9 #       These files are hosted in the OpenGL extension registry at
10 #       opengl.org:
11 #
12 #       http://www.opengl.org/registry/api/gl.spec
13 #       http://www.opengl.org/registry/api/gl.tm
14 #
15 #       If they are not found in the current directory the script will
16 #       attempt to download them from there.
17 #
18 #       The files used to be hosted and maintained by SGI. You can still find
19 #       find them in the sample implementation CVS tree which is located at
20 #       CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
21 #       You can also find them on the web at the following URL :
22 #         http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
23 #
24 #     - opengl_version is the OpenGL version emulated by the library
25 #       (can be 1.0 to 1.5). The default is 1.1.
26 #
27 # This script generates the three following files :
28 #
29 #     - opengl32.spec : the spec file giving all the exported functions
30 #       of the OpenGL32.DLL library. These functions are the one an
31 #       application can directly link to (and are all the functions
32 #       defined in the OpenGL core for the version defined by
33 #       'opengl_version').
34 #
35 #     - opengl_norm.c : this file contains the thunks for all OpenGL
36 #       functions that are defined in 'opengl32.spec'. The corresponding
37 #       functions NEED to be defined in Linux's libGL or the library
38 #       won't be able to be linked in.
39 #
40 #     - opengl_ext.c : in this file are stored thunks for ALL possible
41 #       OpenGL extensions (at least, all the extensions that are defined
42 #       in the OpenGL extension registry). Contrary to 'opengl_norm.c',
43 #       you do not need to have these extensions in your libGL to have
44 #       OpenGL work (as they are resolved at run-time using
45 #       glXGetProcAddressARB).
46 #
47 # Copyright 2000 Lionel Ulmer
48 #
49 # This library is free software; you can redistribute it and/or
50 # modify it under the terms of the GNU Lesser General Public
51 # License as published by the Free Software Foundation; either
52 # version 2.1 of the License, or (at your option) any later version.
53 #
54 # This library is distributed in the hope that it will be useful,
55 # but WITHOUT ANY WARRANTY; without even the implied warranty of
56 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
57 # Lesser General Public License for more details.
58 #
59 # You should have received a copy of the GNU Lesser General Public
60 # License along with this library; if not, write to the Free Software
61 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
62 #
63
64 #
65 # Files to generate
66 #
67 my $spec_file = "opengl32.spec";
68 my $norm_file = "opengl_norm.c";
69 my $ext_file  = "opengl_ext.c";
70
71 # Set to 0 for removing the ENTER / LEAVE GL calls
72 my $gen_thread_safe = 0;
73 # Prefix used for the local variables
74 my $ext_prefix = "func_";
75 # If set to 1, generate TRACEs for each OpenGL function
76 my $gen_traces = 1;
77
78 #
79 # List of categories to put in the 'opengl_norm.c' file
80 #
81 my %cat_1_0 = ( "display-list" => 1,
82              "drawing" => 1,
83              "drawing-control" => 1,
84              "feedback" => 1,
85              "framebuf" => 1,
86              "misc" => 1,
87              "modeling" => 1,
88              "pixel-op" => 1,
89              "pixel-rw" => 1,
90              "state-req" => 1,
91              "xform" => 1,
92              "VERSION_1_0" => 1,
93              "VERSION_1_0_DEPRECATED" => 1 );
94 my %cat_1_1 = ( %cat_1_0,
95              "VERSION_1_1" => 1,
96              "VERSION_1_1_DEPRECATED" => 1 );
97 my %cat_1_2 = ( %cat_1_1,
98              "VERSION_1_2" => 1,
99              "VERSION_1_2_DEPRECATED" => 1 );
100 my %cat_1_3 = ( %cat_1_2,
101              "VERSION_1_3" => 1,
102              "VERSION_1_3_DEPRECATED" => 1 );
103 my %cat_1_4 = ( %cat_1_3,
104              "VERSION_1_4" => 1,
105              "VERSION_1_4_DEPRECATED" => 1 );
106 my %cat_1_5 = ( %cat_1_4,
107              "VERSION_1_5" => 1,
108              "VERSION_1_5_DEPRECATED" => 1 );
109
110 my %norm_categories = ();
111
112 #
113 # This hash table gives the conversion between OpenGL types and what
114 # is used by the TRACE printfs
115 #
116 my %debug_conv =
117     ("GLbitfield" => "%d",
118      "GLboolean" => "%d",
119      "GLbyte" => "%d",
120      "GLclampd" => "%f",
121      "GLclampf" => "%f",
122      "GLdouble" => "%f",
123      "GLenum" => "%d",
124      "GLfloat" => "%f",
125      "GLint" => "%d",
126      "GLshort" => "%d",
127      "GLsizei" => "%d",
128      "GLstring" => "%s",
129      "GLubyte" => "%d",
130      "GLuint" => "%d",
131      "GLushort" => "%d",
132      "GLhalfNV" => "%d",
133      "GLintptrARB" => "%ld",
134      "GLsizeiptrARB" => "%ld",
135      "GLintptr" => "%ld",
136      "GLsizeiptr" => "%ld",
137      "GLhandleARB" => "%d",
138      "GLcharARB" => "%c",
139      "GLvoid" => "(void)",
140      "_GLfuncptr" => "%p",
141      "GLDEBUGPROCARB" => "%p",
142      "GLDEBUGPROCAMD" => "%p",
143      "GLvdpauSurfaceNV" => "%ld",
144      "INT64" => "%s,wine_dbgstr_longlong(%s)",
145      "UINT64" => "%s,wine_dbgstr_longlong(%s)"
146     );
147
148 #
149 # This hash table gives the conversion between OpenGL types and what
150 # is used in the .spec file
151 #
152 my %arg_conv =
153     ("GLbitfield" => [ "long", 4 ],
154      "GLboolean" => [ "long", 4 ],
155      "GLbyte" => [ "long", 4 ],
156      "GLclampd" => [ "double", 8 ],
157      "GLclampf" => [ "float", 4 ],
158      "GLdouble" => [ "double", 8 ],
159      "GLenum" => [ "long", 4 ],
160      "GLfloat" => [ "float", 4 ],
161      "GLint" => [ "long", 4 ],
162      "GLshort" => [ "long", 4 ],
163      "GLsizei" => [ "long", 4 ],
164      "GLstring" => [ "str", 4 ],
165      "GLubyte" => [ "long", 4 ],
166      "GLuint" => [ "long", 4 ],
167      "GLushort" => [ "long", 4 ],
168      "GLhalfNV" => [ "long", 4 ],
169      "GLintptrARB" => [ "long", 4 ],
170      "GLsizeiptrARB" => [ "long", 4 ],
171      "GLhandleARB" => [ "long", 4 ],
172      "GLcharARB" => [ "long", 4 ],
173      "GLintptr" => [ "long", 4 ],
174      "GLsizeiptr" => [ "long", 4 ],
175      "_GLfuncptr" => [ "ptr", 4 ]);
176
177 #
178 # Used to convert some types
179 #
180 sub ConvertType($)
181 {
182     my ($type) = @_;
183
184     my %hash = ( "GLstring" => "const GLubyte *",
185               "GLintptrARB" => "INT_PTR",
186               "GLsizeiptrARB" => "INT_PTR",
187               "GLintptr" => "INT_PTR",
188               "GLsizeiptr" => "INT_PTR",
189               "GLhandleARB" => "unsigned int",
190               "GLcharARB" => "char",
191               "GLchar" => "char",
192               "GLhalfNV" => "unsigned short",
193               "GLvdpauSurfaceNV" => "INT_PTR",
194               "struct _cl_context" => "void",
195               "struct _cl_event" => "void",
196               "GLDEBUGPROCARB" => "void *",
197               "GLDEBUGPROCAMD" => "void *" );
198
199     foreach my $org (reverse sort keys %hash) {
200         if ($type =~ /$org/) {
201             my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
202             return "$before$hash{$org}$after";
203         }
204     }
205     return $type;
206 }
207
208 #
209 # Used to convert some variable names
210 #
211 sub ConvertVarName($)
212 {
213     my ($type) = @_;
214
215     my %hash = ( "near" => "nearParam",
216                  "far"  => "farParam" );
217
218     foreach my $org (keys %hash) {
219         if ($type =~ /$org/) {
220             my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
221             return "$before$hash{$org}$after";
222         }
223     }
224     return $type;
225 }
226
227 #
228 # This functions generates the thunk for a given function.
229 #
230 sub GenerateThunk($$$$$)
231 {
232     my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
233     my $ret = "";
234     my $call_arg = "";
235     my $trace_call_arg = "";
236     my $trace_arg = "";
237
238     return "" if $func_ref->[0] eq "glDebugEntry";
239     return "" if $func_ref->[0] eq "glGetString";
240     return "" if $func_ref->[0] eq "glGetIntegerv";
241     return "" if $func_ref->[0] eq "glFinish";
242     return "" if $func_ref->[0] eq "glFlush";
243
244     # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
245     # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
246     if ($comment eq 1) {
247         $ret = "$ret/***********************************************************************\n";
248         $ret = "$ret *              $func_ref->[0] (OPENGL32.\@)\n";
249         $ret = "$ret */\n";
250     }
251     $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
252     for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
253         ## Quick debug code :-)
254         ## print $func_ref->[2]->[$i]->[1] . "\n";
255         my $type = $func_ref->[2]->[$i]->[0];
256         my $name = ConvertVarName($func_ref->[2]->[$i]->[1]);
257         $ret .= ConvertType($type) . " $name";
258         $call_arg .= $name;
259         if ($type =~ /\*/) {
260             $trace_arg .= "%p";
261             $trace_call_arg .= $name;
262         } elsif (defined $debug_conv{$type}) {
263             if ($debug_conv{$type} =~ /(.*),(.*)/)
264             {
265                 $trace_arg .= $1;
266                 $trace_call_arg .= sprintf $2, $name;
267             }
268             else
269             {
270                 $trace_arg .= $debug_conv{$type};
271                 $trace_call_arg .= $name;
272             }
273         }
274         else { printf "Unknown type %s\n", $type; }
275         if ($i+1 < @{$func_ref->[2]}) {
276             $ret .= ", ";
277             $call_arg .= ", ";
278             $trace_call_arg .= ", ";
279             $trace_arg .= ", ";
280         } else {
281             $ret .= " ";
282             $call_arg .= " ";
283             $trace_call_arg .= " ";
284         }
285     }
286     $ret .= 'void ' if (!@{$func_ref->[2]});
287     $ret = "$ret) {\n";
288     if ($func_ref->[1] ne "void" && $thread_safe) {
289         $ret = "$ret  " . ConvertType($func_ref->[1]) . " ret_value;\n";
290     }
291     $ret .= $local_var;
292     if ($gen_traces) {
293         $ret = "$ret  TRACE(\"($trace_arg)\\n\"";
294         if ($trace_arg ne "") {
295             $ret .= ", $trace_call_arg";
296         }
297         $ret = "$ret);\n";
298     }
299     if ($thread_safe) {
300         $ret .= "  ENTER_GL();\n";
301         $ret .= "  ";
302         if ($func_ref->[1] ne "void") {
303             $ret .= "ret_value = ";
304         }
305         $ret .= "$prefix$func_ref->[0]( $call_arg);\n";
306         $ret .= "  LEAVE_GL();\n";
307         if ($func_ref->[1] ne "void") {
308             $ret .= "  return ret_value;\n"
309         }
310     }
311     else {
312         $ret .= "  ";
313         if ($func_ref->[1] ne "void") {
314             $ret .= "return ";
315         }
316         $ret .= "$prefix$func_ref->[0]( $call_arg);\n";
317     }
318     $ret = "$ret}\n";
319
320     # Return this string....
321     return $ret;
322 }
323
324 #
325 # Extract and checks the number of arguments
326 #
327 if (@ARGV > 1) {
328     my $name0=$0;
329     $name0=~s%^.*/%%;
330     die "Usage: $name0 [version]\n";
331 }
332 my $version = $ARGV[0] || "1.1";
333 if ($version eq "1.0") {
334     %norm_categories = %cat_1_0;
335 } elsif ($version eq "1.1") {
336     %norm_categories = %cat_1_1;
337 } elsif ($version eq "1.2") {
338     %norm_categories = %cat_1_2;
339 } elsif ($version eq "1.3") {
340     %norm_categories = %cat_1_3;
341 } elsif ($version eq "1.4") {
342     %norm_categories = %cat_1_4;
343 } elsif ($version eq "1.5") {
344     %norm_categories = %cat_1_5;
345 } else {
346     die "Incorrect OpenGL version.\n";
347 }
348
349 #
350 # Fetch the registry files
351 #
352 -f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
353 -f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
354
355 #
356 # Open the registry files
357 #
358 open(TYPES,    "gl.tm")   || die "Could not open gl.tm";
359 open(REGISTRY, "gl.spec") || die "Could not open gl.spec";
360
361 #
362 # First, create a mapping between the pseudo types used in the spec file
363 # and OpenGL types using the 'gl.tm' file.
364 #
365 my %pseudo_to_opengl = ();
366 while (my $line = <TYPES>) {
367     if ($line !~ /\w*\#/) {
368         my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
369         $pseudo_to_opengl{$pseudo} = $opengl;
370     }
371 }
372 # This is to override the 'void' -> '*' bogus conversion
373 $pseudo_to_opengl{"void"} = "void";
374 $pseudo_to_opengl{"sync"} = "GLvoid*";
375 $pseudo_to_opengl{"Int64"} = "INT64";
376 $pseudo_to_opengl{"UInt64"} = "UINT64";
377 $pseudo_to_opengl{"Int64EXT"} = "INT64";
378 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
379
380 #
381 # Then, create the list of all OpenGL functions using the 'gl.spec'
382 # file. This will create two hash-tables, one with all the function
383 # whose category matches the one listed in '@norm_categories', the other
384 # with all other functions.
385 #
386 # An element of the hash table is a reference to an array with these
387 # elements :
388 #
389 #  - function name
390 #
391 #  - return type
392 #
393 #  - reference to an array giving the list of arguments (an empty array
394 #    for a 'void' function).
395 #
396 # The list of arguments is itself an array of reference to arrays. Each
397 # of these arrays represents the argument type and the argument name.
398 #
399 # An example :
400 #
401 # void glBitmap( GLsizei width, GLsizei height,
402 #                GLfloat xorig, GLfloat yorig,
403 #                GLfloat xmove, GLfloat ymove,
404 #                const GLubyte *bitmap );
405 #
406 # Would give something like that :
407 #
408 # [ "glBitmap",
409 #   "void",
410 #   [ [ "GLsizei", "width" ],
411 #     [ "GLsizei", "height" ],
412 #     [ "GLfloat", "xorig" ],
413 #     [ "GLfloat", "yorig" ],
414 #     [ "GLfloat", "xmove" ],
415 #     [ "GLfloat", "ymove" ],
416 #     [ "GLubyte *", "bitmap"] ] ];
417 #
418 my %norm_functions = ( "glDebugEntry" => [ "glDebugEntry", "GLint", [[ "GLint", "unknown1" ],
419                                                                      [ "GLint", "unknown2" ]] ] );
420
421 #
422 # This stores various extensions NOT part of the GL extension registry but still
423 # implemented by most OpenGL libraries out there...
424 #
425
426 my %ext_functions  =
427     ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
428       "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
429                                                                 [ "GLint", "x" ],
430                                                                 [ "GLint", "y" ],
431                                                                 [ "GLsizei", "width" ],
432                                                                 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
433       "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
434                                                                 [ "GLint", "x" ],
435                                                                 [ "GLint", "y" ],
436                                                                 [ "GLsizei", "width" ],
437                                                                 [ "GLsizei", "height" ],
438                                                                 [ "GLint", "xDest" ],
439                                                                 [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
440       "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled",  "GL_KTX_buffer_region" ],
441       "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
442       "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
443                                                               [ "GLfloat", "s" ],
444                                                               [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
445       "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
446                                                                 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
447       "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
448                                                                       [ "GLdouble", "s" ] ],  "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
449       "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
450                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
451       "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
452                                                                       [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
453       "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
454                                                                         [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
455       "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
456                                                                       [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
457       "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
458                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
459       "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
460                                                                       [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
461       "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
462                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
463       "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
464                                                                       [ "GLdouble", "s"],
465                                                                       [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
466       "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
467                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
468       "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
469                                                                       [ "GLfloat", "s" ],
470                                                                       [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
471       "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
472                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
473       "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
474                                                                       [ "GLint", "s" ],
475                                                                       [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
476       "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
477                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
478       "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
479                                                                       [ "GLshort", "s" ],
480                                                                       [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
481       "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
482                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
483       "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
484                                                                       [ "GLdouble", "s" ],
485                                                                       [ "GLdouble", "t" ],
486                                                                       [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
487       "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
488                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
489       "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
490                                                                       [ "GLfloat", "s" ],
491                                                                       [ "GLfloat", "t" ],
492                                                                       [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
493       "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
494                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
495       "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
496                                                                       [ "GLint", "s" ],
497                                                                       [ "GLint", "t" ],
498                                                                       [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
499       "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
500                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
501       "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
502                                                                       [ "GLshort", "s" ],
503                                                                       [ "GLshort", "t" ],
504                                                                       [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
505       "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
506                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
507       "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
508                                                                       [ "GLdouble", "s" ],
509                                                                       [ "GLdouble", "t" ],
510                                                                       [ "GLdouble", "r" ],
511                                                                       [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
512       "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
513                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
514       "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
515                                                                       [ "GLfloat", "s" ],
516                                                                       [ "GLfloat", "t" ],
517                                                                       [ "GLfloat", "r" ],
518                                                                       [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
519       "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
520                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
521       "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
522                                                                       [ "GLint", "s" ],
523                                                                       [ "GLint", "t" ],
524                                                                       [ "GLint", "r" ],
525                                                                       [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
526       "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
527                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
528       "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
529                                                                       [ "GLshort", "s" ],
530                                                                       [ "GLshort", "t" ],
531                                                                       [ "GLshort", "r" ],
532                                                                       [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
533       "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
534                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
535       "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
536                                                                                 [ "GLint", "size" ],
537                                                                                 [ "GLenum", "type" ],
538                                                                                 [ "GLsizei", "stride" ],
539                                                                                 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
540       "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
541       "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
542       "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
543       );
544
545 my @arg_names;
546 my %arg_types;
547 while (my $line = <REGISTRY>) {
548     if ($line =~ /^\w*\(.*\)/) {
549         # Get the function name (NOTE: the 'gl' prefix needs to be added later)
550         my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
551         # and the argument names
552         @arg_names = split /\s*,\s*/, $args;
553
554         # After get :
555         #  - the return type
556         #  - category (the extension the function is part of)
557         #  - the argument types
558         #  - the category the function belongs
559         %arg_types = ();
560         my $category = "";
561         my $ret_type = "";
562         while (1) {
563             $line = <REGISTRY>;
564             unless (defined($line)) {
565                 last;
566             } elsif ($line =~ /^\s*$/) {
567                 if (($category eq "") || ($ret_type eq "")) {
568                     die "Missing 'category' line in function $funcname.\n";
569                 }
570                 last;
571             } elsif ($line =~ /\t*return\t+(\w*)/) {
572                 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
573                 $ret_type = $pseudo_to_opengl{$ret_type};
574                 unless (defined($ret_type)) {
575                     die "Unsupported return type in function $funcname\n";
576                 }
577             } elsif ($line =~ /^\t*category/) {
578                 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
579             } elsif ($line =~ /^\t*param/) {
580                 my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
581                 my $ptr = 0;
582                 unless (defined($name)) {
583                     chomp $line;
584                     die "Broken spec file line $line in function $funcname\n";
585                 }
586
587                 if ($ext =~ /array/) {
588                     # This is a pointer
589                     $ptr = 1;
590                 } elsif ($ext =~ /reference/) {
591                     # This is a pointer
592                     $ptr = 1;
593                 } elsif ($ext =~ /value/) {
594                     # And this a 'normal' value
595                     $ptr = 0;
596                 } else {
597                     chomp $line;
598                     die "Unsupported type : $line in function $funcname\n";
599                 }
600                 # Get the 'real' type and append a '*' in case of a pointer
601                 my $type = $pseudo_to_opengl{$base_type};
602                 unless (defined($type)) {
603                     chomp $line;
604                     die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
605                 }
606                 if ($ptr) {
607                     $type = "$type*";
608                 }
609
610                 $arg_types{$name} = $type;
611             }
612         }
613
614         # Now, build the argument reference
615         my $arg_ref = [ ];
616         for (my $i = 0; $i < @arg_names; $i++) {
617             unless (defined($arg_types{$arg_names[$i]})) {
618                 print "@arg_names\n";
619                 foreach (sort keys %arg_types) {
620                     print "$_ => $arg_types{$_}\n";
621                 }
622                 die "Undefined type for $arg_names[$i] in function $funcname\n";
623             }
624
625             push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
626         }
627         my $func_ref = [ "gl$funcname",
628                          $ret_type,
629                          $arg_ref,
630                          "gl$funcname",
631                          "GL_$category" ];
632
633         # Now, put in one or the other hash table
634         if ($norm_categories{$category}) {
635             $norm_functions{"gl$funcname"} = $func_ref;
636         } else {
637             $ext_functions{"gl$funcname"} = $func_ref;
638         }
639     }
640 }
641
642 #
643 # Clean up the input files
644 #
645 close(TYPES);
646 close(REGISTRY);
647
648 #
649 # Now, generate the output files. First, the spec file.
650 #
651 open(SPEC, ">$spec_file");
652
653 foreach (sort keys %norm_functions) {
654     my $func_name = $norm_functions{$_}->[0];
655     print SPEC "@  stdcall $func_name( ";
656     for (my $i = 0; $i < @{$norm_functions{$_}->[2]}; $i++) {
657         my $type = $norm_functions{$_}->[2]->[$i]->[0];
658         if ($type =~ /\*/) {
659             print SPEC "ptr ";
660         } elsif (defined($arg_conv{$type})) {
661             print SPEC "$@$arg_conv{$type}[0] ";
662         } else {
663             die "No conversion for GL type $type...\n";
664         }
665     }
666     print SPEC ") wine_$func_name\n";
667 }
668
669 print SPEC "@  stdcall wglChoosePixelFormat(long ptr)
670 @  stdcall wglCopyContext(long long long)
671 @  stdcall wglCreateContext(long)
672 @  stdcall wglCreateLayerContext(long long)
673 @  stdcall wglDeleteContext(long)
674 @  stdcall wglDescribeLayerPlane(long long long long ptr)
675 @  stdcall wglDescribePixelFormat(long long long ptr)
676 @  stdcall wglGetCurrentContext()
677 @  stdcall wglGetCurrentDC()
678 @  stub    wglGetDefaultProcAddress
679 @  stdcall wglGetLayerPaletteEntries(long long long long ptr)
680 @  stdcall wglGetPixelFormat(long)
681 @  stdcall wglGetProcAddress(str)
682 @  stdcall wglMakeCurrent(long long)
683 @  stdcall wglRealizeLayerPalette(long long long)
684 @  stdcall wglSetLayerPaletteEntries(long long long long ptr)
685 @  stdcall wglSetPixelFormat(long long ptr)
686 @  stdcall wglShareLists(long long)
687 @  stdcall wglSwapBuffers(long)
688 @  stdcall wglSwapLayerBuffers(long long)
689 @  stdcall wglUseFontBitmapsA(long long long long)
690 @  stdcall wglUseFontBitmapsW(long long long long)
691 @  stdcall wglUseFontOutlinesA(long long long long long long long ptr)
692 @  stdcall wglUseFontOutlinesW(long long long long long long long ptr)
693 ";
694
695 close(SPEC);
696
697 #
698 # After the spec file, the opengl_norm.c file
699 #
700 open(NORM, ">$norm_file");
701 print NORM "
702 /* Auto-generated file... Do not edit ! */
703
704 #include \"config.h\"
705 #include \"opengl_ext.h\"
706 #include \"wine/debug.h\"
707
708 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
709 ";
710 foreach (sort keys %norm_functions) {
711     my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
712
713     print NORM "\n$string" if $string;
714 }
715 close(NORM);
716
717 #
718 # Finally, more complex, the opengl_ext.c file
719 #
720 open(EXT, ">$ext_file");
721 print EXT "
722 /* Auto-generated file... Do not edit ! */
723
724 #include \"config.h\"
725 #include \"opengl_ext.h\"
726 #include \"wine/debug.h\"
727
728 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
729
730 ";
731
732 # The thunks themselves....
733 my $count = keys %ext_functions;
734 print EXT "enum extensions\n{\n";
735 foreach (sort keys %ext_functions) {
736     my $func_ref = $ext_functions{$_};
737     print EXT "    EXT_$func_ref->[0],\n";
738 }
739 print EXT "    NB_EXTENSIONS\n};\n\n";
740 print EXT "const int extension_registry_size = NB_EXTENSIONS;\n";
741 print EXT "void *extension_funcs[NB_EXTENSIONS];\n";
742 print EXT "\n/* The thunks themselves....*/";
743 foreach (sort keys %ext_functions) {
744     my $func_ref = $ext_functions{$_};
745     my $local_var = "  " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
746     for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
747         my $type = ConvertType($func_ref->[2]->[$i]->[0]);
748         $local_var .= "$type";
749         if ($i+1 < @{$func_ref->[2]}) {
750             $local_var .= ", ";
751         } else {
752             $local_var .= " ";
753         }
754     }
755     $local_var .= 'void ' if (!@{$func_ref->[2]});
756     $local_var .= ") = extension_funcs[EXT_$func_ref->[0]];\n";
757     print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
758 }
759
760 # Then the table giving the string <-> function correspondence */
761 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
762 print EXT "const OpenGL_extension extension_registry[NB_EXTENSIONS] = {\n";
763 my $i = 0;
764 foreach (sort keys %ext_functions) {
765     my $func_ref = $ext_functions{$_};
766     if ($func_ref->[0] eq $func_ref->[3])
767     {
768         print EXT "  { \"$func_ref->[0]\", \"$func_ref->[4]\", wine_$func_ref->[0] }";
769     }
770     if ($i != $count-1) {
771         print EXT ",";
772     }
773     $i++;
774     print EXT "\n";
775 }
776 print EXT "};\n";
777
778 close(EXT);