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