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