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