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