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