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