Upgrade OpenGL thunks with latest version of OpenGL extension
[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              "ARB_multitexture" => 1 );
87
88 %norm_categories = ();
89
90 #
91 # This hash table gives the conversion between OpenGL types and what
92 # is used by the TRACE printfs
93 #
94 %debug_conv =
95     ("GLbitfield" => "%d",
96      "GLboolean" => "%d",
97      "GLbyte" => "%d",
98      "GLclampd" => "%f",
99      "GLclampf" => "%f",
100      "GLdouble" => "%f",
101      "GLenum" => "%d",
102      "GLfloat" => "%f",
103      "GLint" => "%d",
104      "GLshort" => "%d",
105      "GLsizei" => "%d",
106      "GLstring" => "%s",
107      "GLubyte" => "%d",
108      "GLuint" => "%d",
109      "GLushort" => "%d",
110      "GLhalfNV" => "%d",
111      "GLintptrARB" => "%d",
112      "GLsizeiptrARB" => "%d",
113      "GLvoid" => "(void)",
114      "_GLfuncptr" => "%p");
115
116 #
117 # This hash table gives the conversion between OpenGL types and what
118 # is used in the .spec file
119 #
120 %arg_conv =
121     ("GLbitfield" => [ "long", 4 ],
122      "GLboolean" => [ "long", 4 ],
123      "GLbyte" => [ "long", 4 ],
124      "GLclampd" => [ "double", 8 ],
125      "GLclampf" => [ "long", 4 ],
126      "GLdouble" => [ "double", 8 ],
127      "GLenum" => [ "long", 4 ],
128      "GLfloat" => [ "long", 4 ],
129      "GLint" => [ "long", 4 ],
130      "GLshort" => [ "long", 4 ],
131      "GLsizei" => [ "long", 4 ],
132      "GLstring" => [ "str", 4 ],
133      "GLubyte" => [ "long", 4 ],
134      "GLuint" => [ "long", 4 ],
135      "GLushort" => [ "long", 4 ],
136      "GLhalfNV" => [ "long", 4 ],
137      "GLintptrARB" => [ "long", 4 ],
138      "GLsizeiptrARB" => [ "long", 4 ],
139      "GLvoid" => [ "void", 4 ],
140      "_GLfuncptr" => [ "ptr", 4 ]);
141
142 #
143 # This functions generates the thunk for a given function.
144 #
145 sub GenerateThunk {
146     my ($func_ref, $comment, $prefix, $thread_safe) = @_;
147     my ($ret) = ("");
148     my ($call_arg) = ("");
149     my ($trace_arg) = ("");
150
151     # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
152     # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
153     if ($comment eq 1) {
154         $ret = $ret . "/***********************************************************************\n";
155         $ret = $ret . " *              " . $func_ref->[0] . " (OPENGL32.@)\n";
156         $ret = $ret . " */\n";
157     }
158     $ret = $ret . $func_ref->[1] . " WINAPI wine_" . $func_ref->[0] . "( ";
159     for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
160         $type = $func_ref->[2]->[$i]->[0];
161         $name = $func_ref->[2]->[$i]->[1];
162         $ret = $ret . "$type $name";
163         $call_arg = $call_arg . "$name";
164         if ($type =~ /\*/) {
165             $trace_arg = $trace_arg . "%p";
166         } else {
167             $trace_arg = $trace_arg . $debug_conv{$type};
168         }
169         if ($i != $#{@{$func_ref->[2]}}) {
170             $ret = $ret . ", ";
171             $call_arg = $call_arg . ", ";
172             $trace_arg = $trace_arg . ", ";
173         } else {
174             $ret = $ret . " ";
175             $call_arg = $call_arg . " ";
176         }
177     }
178     $ret = $ret . ") {\n";
179     if ($func_ref->[1] ne "void") {
180         $ret = $ret . "  " . $func_ref->[1] . " ret_value;\n";
181     }
182     if ($gen_traces) {
183         $ret = $ret . "  TRACE(\"(" . $trace_arg . ")\\n\"";
184         if ($trace_arg ne "") {
185             $ret = $ret . ", " . $call_arg;
186         }
187         $ret = $ret . ");\n";
188     }
189     if ($thread_safe) {
190         $ret = $ret . "  ENTER_GL();\n";
191     }
192     $ret = $ret . "  ";
193     if ($func_ref->[1] ne "void") {
194         $ret = $ret . "ret_value = ";
195     }
196     $ret = $ret . $prefix . $func_ref->[0] . "( " . $call_arg . ");\n";
197     if ($thread_safe) {
198         $ret = $ret . "  LEAVE_GL();\n";
199     }
200     if ($func_ref->[1] ne "void") {
201         $ret = $ret . "  return ret_value;\n"
202     }
203     $ret = $ret . "}\n";
204
205     # Return this string....
206     $ret;
207 }
208
209 #
210 # Extract and checks the number of arguments
211 #
212 if ($#ARGV != 1) {
213     die "Usage : make_opengl OpenGL_registry_location OpenGL_version.\n";
214 }
215 $registry_path = shift @ARGV;
216 $version       = shift @ARGV;
217 if ($version eq "1.0") {
218     %norm_categories = %cat_1_0;
219 } elsif ($version eq "1.1") {
220     %norm_categories = %cat_1_1;
221 } elsif ($version eq "1.2") {
222     %norm_categories = %cat_1_2;
223 } else {
224     die "OpenGL version incorrect. Should be one of '1.0', '1.1' or '1.2'.\n";
225 }
226
227 #
228 # Open the registry files
229 #
230 open(TYPES,    $registry_path . "/gl.tm")   || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
231 open(REGISTRY, $registry_path . "/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
232
233 #
234 # First, create a mapping between the pseudo types used in the spec file
235 # and OpenGL types using the 'gl.tm' file.
236 #
237 %pseudo_to_opengl = ();
238 while ($line = <TYPES>) {
239     if ($line !~ /\w*\#/) {
240         ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
241         $pseudo_to_opengl{$pseudo} = $opengl;
242     }
243 }
244 # This is to override the 'void' -> '*' bogus conversion
245 $pseudo_to_opengl{"void"} = "void";
246 # This is a bug in the spec file...
247 $pseudo_to_opengl{"FfdTargetSGIX"} = "GLint";
248 $pseudo_to_opengl{"FfdMaskSGIX"} = "GLint";
249 $pseudo_to_opengl{"IglooFunctionSelectSGIX"} = "GLint";
250 $pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
251
252 #
253 # Then, create the list of all OpenGL functions using the 'gl.spec'
254 # file. This will create two hash-tables, one with all the function
255 # whose category matches the one listed in '@norm_categories', the other
256 # with all other functions.
257 #
258 # An element of the hash table is a reference to an array with these
259 # elements :
260 #
261 #  - function name
262 #
263 #  - return type
264 #
265 #  - reference to an array giving the list of arguments (an empty array
266 #    for a 'void' function).
267 #
268 # The list of arguments is itself an array of reference to arrays. Each
269 # of these arrays represents the argument type and the argument name.
270 #
271 # An example :
272 #
273 # void glBitmap( GLsizei width, GLsizei height,
274 #                GLfloat xorig, GLfloat yorig,
275 #                GLfloat xmove, GLfloat ymove,
276 #                const GLubyte *bitmap );
277 #
278 # Would give something like that :
279 #
280 # [ "glBitmap",
281 #   "void",
282 #   [ [ "GLsizei", "width" ],
283 #     [ "GLsizei", "height" ],
284 #     [ "GLfloat", "xorig" ],
285 #     [ "GLfloat", "yorig" ],
286 #     [ "GLfloat", "xmove" ],
287 #     [ "GLfloat", "ymove" ],
288 #     [ "GLubyte *", "bitmap"] ] ];
289 #
290 %norm_functions = ();
291
292 #
293 # This stores various extensions NOT part of the GL extension registry but still
294 # implemented by most OpenGL libraries out there...
295 #
296 %ext_functions  =
297     ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion" ],
298       "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
299                                                                 [ "GLint", "x" ],
300                                                                 [ "GLint", "y" ],
301                                                                 [ "GLsizei", "width" ],
302                                                                 [ "GLsizei", "height" ] ], "glReadBufferRegion" ],
303       "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
304                                                                 [ "GLint", "x" ],
305                                                                 [ "GLint", "y" ],
306                                                                 [ "GLsizei", "width" ],
307                                                                 [ "GLsizei", "height" ],
308                                                                 [ "GLint", "xDest" ],
309                                                                 [ "GLint", "yDest" ] ], "glDrawBufferRegion" ],
310       "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled" ],
311       "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion" ],
312       "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
313                                                               [ "GLfloat", "s" ],
314                                                               [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS" ],
315       "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
316                                                                 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS" ],
317       "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
318                                                                       [ "GLdouble", "s" ] ],  "glMultiTexCoord1dSGIS" ],
319       "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
320                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
321       "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
322                                                                       [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
323       "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
324                                                                         [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
325       "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
326                                                                       [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
327       "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
328                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
329       "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
330                                                                       [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
331       "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
332                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
333       "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
334                                                                       [ "GLdouble", "s"],
335                                                                       [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
336       "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
337                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
338       "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
339                                                                       [ "GLfloat", "s" ],
340                                                                       [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
341       "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
342                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
343       "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
344                                                                       [ "GLint", "s" ],
345                                                                       [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
346       "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
347                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
348       "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
349                                                                       [ "GLshort", "s" ],
350                                                                       [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
351       "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
352                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
353       "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
354                                                                       [ "GLdouble", "s" ],
355                                                                       [ "GLdouble", "t" ],
356                                                                       [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
357       "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
358                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
359       "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
360                                                                       [ "GLfloat", "s" ],
361                                                                       [ "GLfloat", "t" ],
362                                                                       [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
363       "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
364                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
365       "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
366                                                                       [ "GLint", "s" ],
367                                                                       [ "GLint", "t" ],
368                                                                       [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
369       "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
370                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
371       "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
372                                                                       [ "GLshort", "s" ],
373                                                                       [ "GLshort", "t" ],
374                                                                       [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
375       "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
376                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
377       "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
378                                                                       [ "GLdouble", "s" ],
379                                                                       [ "GLdouble", "t" ],
380                                                                       [ "GLdouble", "r" ],
381                                                                       [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
382       "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
383                                                                         [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
384       "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
385                                                                       [ "GLfloat", "s" ],
386                                                                       [ "GLfloat", "t" ],
387                                                                       [ "GLfloat", "r" ],
388                                                                       [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
389       "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
390                                                                         [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
391       "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
392                                                                       [ "GLint", "s" ],
393                                                                       [ "GLint", "t" ],
394                                                                       [ "GLint", "r" ],
395                                                                       [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
396       "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
397                                                                         [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
398       "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
399                                                                       [ "GLshort", "s" ],
400                                                                       [ "GLshort", "t" ],
401                                                                       [ "GLshort", "r" ],
402                                                                       [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
403       "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
404                                                                         [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
405       "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
406                                                                                 [ "GLint", "size" ],
407                                                                                 [ "GLenum", "type" ],
408                                                                                 [ "GLsizei", "stride" ],
409                                                                                 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
410       "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
411       "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
412       "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
413                                                                     [ "GLfloat", "readfreq" ],
414                                                                     [ "GLfloat", "writefreq"],
415                                                                     [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
416       "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ]
417       );
418
419
420 while ($line = <REGISTRY>) {
421     if ($line =~ /^\w*\(.*\)/) {
422         # Get the function name (NOTE: the 'gl' prefix needs to be added later)
423         ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
424         # and the argument names
425         @arg_names = split /\s*,\s*/, $args;
426
427         # After get :
428         #  - the return type
429         #  - the argument types
430         #  - the category the function belongs
431         %arg_types = ();
432         $category = "";
433         $ret_type = "";
434         while (1) {
435             $line = <REGISTRY>;
436             unless (defined($line)) {
437                 last;
438             } elsif ($line =~ /^\s*$/) {
439                 if (($category eq "") || ($ret_type eq "")) {
440                     die "Missing 'category' line in function $funcname.\n";
441                 }
442                 last;
443             } elsif ($line =~ /\t*return\t*(\w*)/) {
444                 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
445                 $ret_type = $pseudo_to_opengl{$ret_type};
446                 unless (defined($ret_type)) {
447                     die "Unsupported return type in function $funcname\n";
448                 }
449             } elsif ($line =~ /^\t*category/) {
450                 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
451             } elsif ($line =~ /^\t*param/) {
452                 ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
453                 $ptr = 0;
454                 unless (defined($name)) {
455                     chomp $line;
456                     die "Broken spec file line $line in function $funcname\n";
457                 }
458
459                 if ($ext =~ /array/) {
460                     # This is a pointer
461                     $ptr = 1;
462                 } elsif ($ext =~ /value/) {
463                     # And this a 'normal' value
464                     $ptr = 0;
465                 } else {
466                     chomp $line;
467                     die "Unsupported type : $line in function $funcname\n";
468                 }
469                 # Get the 'real' type and append a '*' in case of a pointer
470                 $type = $pseudo_to_opengl{$base_type};
471                 unless (defined($type)) {
472                     chomp $line;
473                     die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
474                 }
475                 if ($ptr) {
476                     $type = $type . "*";
477                 }
478
479                 $arg_types{$name} = $type;
480             }
481         }
482
483         # Now, build the argument reference
484         $arg_ref = [ ];
485         for ($i = 0; $i <= $#arg_names; $i++) {
486             unless (defined($arg_types{$arg_names[$i]})) {
487                 print "@arg_names\n";
488                 foreach (sort keys %arg_types) {
489                     print "$_ => $arg_types{$_}\n";
490                 }
491                 die "Undefined type for $arg_names[$i] in function $funcname\n";
492             }
493
494             push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
495         }
496         $func_ref = [ "gl" . $funcname,
497                       $ret_type,
498                       $arg_ref,
499                       "gl" . $funcname ];
500
501         # Now, put in one or the other hash table
502         if ($norm_categories{$category}) {
503             $norm_functions{"gl" . $funcname} = $func_ref;
504         } else {
505             $ext_functions{"gl" . $funcname} = $func_ref;
506         }
507     }
508 }
509
510 #
511 # Clean up the input files
512 #
513 close(TYPES);
514 close(REGISTRY);
515
516 #
517 # Now, generate the output files. First, the spec file.
518 #
519 open(SPEC, ">" . $spec_file);
520
521 print SPEC "@  stdcall wglCreateContext(long)
522 @  stdcall wglCreateLayerContext(long long)
523 @  stdcall wglCopyContext(long long long)
524 @  stdcall wglDeleteContext(long)
525 @  stdcall wglDescribeLayerPlane(long long long long ptr)
526 @  stdcall wglGetCurrentContext()
527 @  stdcall wglGetCurrentDC()
528 @  stdcall wglGetExtensionsStringEXT()
529 @  stdcall wglGetExtensionsStringARB(long)
530 @  stdcall wglGetLayerPaletteEntries(long long long long ptr)
531 @  stdcall wglGetProcAddress(str)
532 @  stdcall wglMakeCurrent(long long)
533 @  stdcall wglRealizeLayerPalette(long long long)
534 @  stdcall wglSetLayerPaletteEntries(long long long long ptr)
535 @  stdcall wglShareLists(long long)
536 @  stdcall wglSwapLayerBuffers(long long)
537 @  stdcall wglUseFontBitmapsA(long long long long)
538 @  stdcall wglUseFontOutlinesA(long long long long long long long ptr)
539 @  stub    glGetLevelParameterfv
540 @  stub    glGetLevelParameteriv
541 @  stub    wglUseFontBitmapsW
542 @  stub    wglUseFontOutlinesW
543 @  stub    wglGetDefaultProcAddress
544 @  stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
545 @  stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
546 @  stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
547 @  stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
548 @  stdcall wglSwapBuffers(long) gdi32.SwapBuffers
549 ";
550
551 foreach (sort keys %norm_functions) {
552     $func_name = $norm_functions{$_}->[0];
553     print SPEC "@  stdcall $func_name( ";
554     for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
555         $type = $norm_functions{$_}->[2]->[$i]->[0];
556         if ($type =~ /\*/) {
557             print SPEC "ptr ";
558         } elsif (defined($arg_conv{$type})) {
559             print SPEC "$@$arg_conv{$type}[0] ";
560         } else {
561             die "No convertion for GL type $type...\n";
562         }
563     }
564     print SPEC ") wine_$func_name\n";
565 }
566 close(SPEC);
567
568 #
569 # After the spec file, the opengl_norm.c file
570 #
571 open(NORM, ">" . $norm_file);
572 print NORM "
573 /* Auto-generated file... Do not edit ! */
574
575 #include \"config.h\"
576 #include \"opengl_ext.h\"
577 #include \"wine/debug.h\"
578
579 typedef const GLubyte * GLstring;
580
581 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
582
583 ";
584 foreach (sort keys %norm_functions) {
585     $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
586
587     print NORM "$string\n";
588 }
589 close(NORM);
590
591 #
592 # Finally, more complex, the opengl_ext.c file
593 #
594 open(EXT, ">" . $ext_file);
595 print EXT "
596 /* Auto-generated file... Do not edit ! */
597
598 #include \"config.h\"
599 #include \"opengl_ext.h\"
600 #include \"wine/debug.h\"
601
602 typedef const GLubyte * GLstring;
603
604 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
605
606 typedef ptrdiff_t GLintptrARB;
607 typedef ptrdiff_t GLsizeiptrARB;
608 typedef unsigned short GLhalfNV;
609
610 ";
611
612 # First, generate the function pointers
613 foreach (sort keys %ext_functions) {
614     $func_ref = $ext_functions{$_};
615     print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
616     for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
617         $type = $func_ref->[2]->[$i]->[0];
618         print EXT "$type";
619         if ($i != $#{@{$func_ref->[2]}}) {
620             print EXT ", ";
621         } else {
622             print EXT " ";
623         }
624     }
625     print EXT ") = (void *) 0xdeadbeef;\n";
626 }
627
628 # Then, the function prototypes
629 print EXT "\n\n/* The function prototypes */\n";
630 foreach (sort keys %ext_functions) {
631     $func_ref = $ext_functions{$_};
632     print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
633     for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
634         $type = $func_ref->[2]->[$i]->[0];
635         print EXT "$type";
636         if ($i != $#{@{$func_ref->[2]}}) {
637             print EXT ", ";
638         } else {
639             print EXT " ";
640         }
641     }
642     print EXT ");\n";
643 }
644
645 # Then the table giving the string <-> function correspondance */
646 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
647 @tmp = keys %ext_functions;
648 print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
649 print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
650 $i = 0;
651 foreach (sort keys %ext_functions) {
652     $func_ref = $ext_functions{$_};
653     print EXT "  { \"" . $func_ref->[0] . "\", \"" . $func_ref->[3] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
654     if ($i != $#tmp) {
655         print EXT ",";
656     }
657     $i++;
658     print EXT "\n";
659 }
660 print EXT "};\n";
661
662 # And, finally, the thunks themselves....
663 print EXT "\n/* The thunks themselves....*/\n";
664 foreach (sort keys %ext_functions) {
665     $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
666
667     print EXT "$string\n";
668 }
669 close(EXT);