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 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
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/
20 # - opengl_version is the OpenGL version emulated by the library
21 # (can be 1.0 to 1.5).
23 # This script generates the three following files :
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
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.
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).
43 # Copyright 2000 Lionel Ulmer
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.
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.
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
63 my $spec_file = "opengl32.spec";
64 my $norm_file = "opengl_norm.c";
65 my $ext_file = "opengl_ext.c";
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
75 # List of categories to put in the 'opengl_norm.c' file
77 my %cat_1_0 = ( "display-list" => 1,
79 "drawing-control" => 1,
88 my %cat_1_1 = ( %cat_1_0,
90 my %cat_1_2 = ( %cat_1_1,
92 my %cat_1_3 = ( %cat_1_2,
94 my %cat_1_4 = ( %cat_1_3,
96 my %cat_1_5 = ( %cat_1_4,
99 my %norm_categories = ();
102 # This hash table gives the conversion between OpenGL types and what
103 # is used by the TRACE printfs
106 ("GLbitfield" => "%d",
122 "GLintptrARB" => "%d",
123 "GLsizeiptrARB" => "%d",
125 "GLsizeiptr" => "%d",
126 "GLhandleARB" => "%d",
128 "GLvoid" => "(void)",
129 "_GLfuncptr" => "%p");
132 # This hash table gives the conversion between OpenGL types and what
133 # is used in the .spec file
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 ]);
162 # Used to convert some types
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",
176 "GLhalfNV" => "unsigned short" );
178 foreach my $org (reverse sort keys %hash) {
179 if ($type =~ /$org/) {
180 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
181 return "$before$hash{$org}$after";
188 # Used to convert some variable names
190 sub ConvertVarName
($)
194 my %hash = ( "near" => "nearParam",
195 "far" => "farParam" );
197 foreach my $org (keys %hash) {
198 if ($type =~ /$org/) {
199 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
200 return "$before$hash{$org}$after";
207 # This functions generates the thunk for a given function.
209 sub GenerateThunk
($$$$$)
211 my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
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 return "" if $func_ref->[0] eq "glFinish";
224 return "" if $func_ref->[0] eq "glFlush";
226 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
227 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
229 $ret = "$ret/***********************************************************************\n";
230 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
233 $ret = $ret . ConvertType
($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
234 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
235 ## Quick debug code :-)
236 ## print $func_ref->[2]->[$i]->[1] . "\n";
237 my $type = $func_ref->[2]->[$i]->[0];
238 my $name = ConvertVarName
($func_ref->[2]->[$i]->[1]);
239 $ret = $ret . ConvertType
($type) . " $name";
240 $call_arg = "$call_arg$name";
242 $trace_arg = "$trace_arg\%p";
244 $trace_arg = "$trace_arg$debug_conv{$type}";
246 if ($i != $#{@{$func_ref->[2]}}) {
248 $call_arg = "$call_arg, ";
249 $trace_arg = "$trace_arg, ";
252 $call_arg = "$call_arg ";
255 $ret .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
257 if ($func_ref->[1] ne "void") {
258 $ret = "$ret " . ConvertType
($func_ref->[1]) . " ret_value;\n";
262 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
263 if ($trace_arg ne "") {
264 $ret = "$ret, $call_arg";
269 $ret = "$ret ENTER_GL();\n";
272 if ($func_ref->[1] ne "void") {
273 $ret = $ret . "ret_value = ";
275 $ret = "$ret$prefix$func_ref->[0]( $call_arg);\n";
277 $ret = "$ret LEAVE_GL();\n";
279 if ($func_ref->[1] ne "void") {
280 $ret = "$ret return ret_value;\n"
284 # Return this string....
289 # Extract and checks the number of arguments
294 die "Usage: $name0 OpenGL_registry_location OpenGL_version\n";
296 my $registry_path = shift @ARGV;
297 my $version = shift @ARGV;
298 if ($version eq "1.0") {
299 %norm_categories = %cat_1_0;
300 } elsif ($version eq "1.1") {
301 %norm_categories = %cat_1_1;
302 } elsif ($version eq "1.2") {
303 %norm_categories = %cat_1_2;
304 } elsif ($version eq "1.3") {
305 %norm_categories = %cat_1_3;
306 } elsif ($version eq "1.4") {
307 %norm_categories = %cat_1_4;
308 } elsif ($version eq "1.5") {
309 %norm_categories = %cat_1_5;
311 die "Incorrect OpenGL version.\n";
315 # Open the registry files
317 open(TYPES
, "$registry_path/gl.tm") || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
318 open(REGISTRY
, "$registry_path/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
321 # First, create a mapping between the pseudo types used in the spec file
322 # and OpenGL types using the 'gl.tm' file.
324 my %pseudo_to_opengl = ();
325 while (my $line = <TYPES
>) {
326 if ($line !~ /\w*\#/) {
327 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
328 $pseudo_to_opengl{$pseudo} = $opengl;
331 # This is to override the 'void' -> '*' bogus conversion
332 $pseudo_to_opengl{"void"} = "void";
333 $pseudo_to_opengl{"Int64EXT"} = "INT64";
334 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
337 # Then, create the list of all OpenGL functions using the 'gl.spec'
338 # file. This will create two hash-tables, one with all the function
339 # whose category matches the one listed in '@norm_categories', the other
340 # with all other functions.
342 # An element of the hash table is a reference to an array with these
349 # - reference to an array giving the list of arguments (an empty array
350 # for a 'void' function).
352 # The list of arguments is itself an array of reference to arrays. Each
353 # of these arrays represents the argument type and the argument name.
357 # void glBitmap( GLsizei width, GLsizei height,
358 # GLfloat xorig, GLfloat yorig,
359 # GLfloat xmove, GLfloat ymove,
360 # const GLubyte *bitmap );
362 # Would give something like that :
366 # [ [ "GLsizei", "width" ],
367 # [ "GLsizei", "height" ],
368 # [ "GLfloat", "xorig" ],
369 # [ "GLfloat", "yorig" ],
370 # [ "GLfloat", "xmove" ],
371 # [ "GLfloat", "ymove" ],
372 # [ "GLubyte *", "bitmap"] ] ];
374 my %norm_functions = ();
377 # This stores various extensions NOT part of the GL extension registry but still
378 # implemented by most OpenGL libraries out there...
382 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
383 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
386 [ "GLsizei", "width" ],
387 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
388 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
391 [ "GLsizei", "width" ],
392 [ "GLsizei", "height" ],
393 [ "GLint", "xDest" ],
394 [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
395 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled", "GL_KTX_buffer_region" ],
396 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
397 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
399 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
400 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
401 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
402 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
403 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
404 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
405 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
406 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
407 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
408 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
409 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
410 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
411 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
412 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
413 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
414 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
415 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
416 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
417 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
418 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
420 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
421 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
422 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
423 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
425 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
426 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
427 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
428 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
430 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
431 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
432 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
433 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
435 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
436 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
437 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
438 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
441 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
442 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
443 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
444 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
447 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
448 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
449 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
450 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
453 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
454 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
455 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
456 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
459 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
460 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
461 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
462 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
466 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
467 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
468 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
469 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
473 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
474 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
475 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
476 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
480 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
481 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
482 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
483 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
487 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
488 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
489 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
490 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
492 [ "GLenum", "type" ],
493 [ "GLsizei", "stride" ],
494 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
495 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
496 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
497 "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
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;
511 # - category (the extension the function is part of)
512 # - the argument types
513 # - the category the function belongs
519 unless (defined($line)) {
521 } elsif ($line =~ /^\s*$/) {
522 if (($category eq "") || ($ret_type eq "")) {
523 die "Missing 'category' line in function $funcname.\n";
526 } elsif ($line =~ /\t*return\t*(\w*)/) {
527 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
528 $ret_type = $pseudo_to_opengl{$ret_type};
529 unless (defined($ret_type)) {
530 die "Unsupported return type in function $funcname\n";
532 } elsif ($line =~ /^\t*category/) {
533 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
534 } elsif ($line =~ /^\t*param/) {
535 my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
537 unless (defined($name)) {
539 die "Broken spec file line $line in function $funcname\n";
542 if ($ext =~ /array/) {
545 } elsif ($ext =~ /value/) {
546 # And this a 'normal' value
550 die "Unsupported type : $line in function $funcname\n";
552 # Get the 'real' type and append a '*' in case of a pointer
553 my $type = $pseudo_to_opengl{$base_type};
554 unless (defined($type)) {
556 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
562 $arg_types{$name} = $type;
566 # Now, build the argument reference
568 for (my $i = 0; $i <= $#arg_names; $i++) {
569 unless (defined($arg_types{$arg_names[$i]})) {
570 print "@arg_names\n";
571 foreach (sort keys %arg_types) {
572 print "$_ => $arg_types{$_}\n";
574 die "Undefined type for $arg_names[$i] in function $funcname\n";
577 push @
$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
579 my $func_ref = [ "gl$funcname",
585 # Now, put in one or the other hash table
586 if ($norm_categories{$category}) {
587 $norm_functions{"gl$funcname"} = $func_ref;
589 $ext_functions{"gl$funcname"} = $func_ref;
595 # Clean up the input files
601 # Now, generate the output files. First, the spec file.
603 open(SPEC
, ">$spec_file");
605 foreach (sort keys %norm_functions) {
606 my $func_name = $norm_functions{$_}->[0];
607 print SPEC
"@ stdcall $func_name( ";
608 for (my $i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
609 my $type = $norm_functions{$_}->[2]->[$i]->[0];
612 } elsif (defined($arg_conv{$type})) {
613 print SPEC
"$@$arg_conv{$type}[0] ";
615 die "No conversion for GL type $type...\n";
618 print SPEC
") wine_$func_name\n";
621 print SPEC
"@ stub glGetLevelParameterfv
622 @ stub glGetLevelParameteriv
623 @ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
624 @ stdcall wglCopyContext(long long long)
625 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
626 @ stdcall wglCreateLayerContext(long long)
627 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
628 @ stdcall wglDescribeLayerPlane(long long long long ptr)
629 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
630 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
631 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
632 @ stub wglGetDefaultProcAddress
633 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
634 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
635 @ stdcall wglGetProcAddress(str)
636 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
637 @ stdcall wglRealizeLayerPalette(long long long)
638 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
639 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
640 @ stdcall wglShareLists(long long) gdi32.wglShareLists
641 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
642 @ stdcall wglSwapLayerBuffers(long long)
643 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
644 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
645 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
646 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
652 # After the spec file, the opengl_norm.c file
654 open(NORM
, ">$norm_file");
656 /* Auto-generated file... Do not edit ! */
658 #include \"config.h\"
659 #include \"opengl_ext.h\"
660 #include \"wine/debug.h\"
662 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
664 foreach (sort keys %norm_functions) {
665 my $string = GenerateThunk
($norm_functions{$_}, 1, "", $gen_thread_safe, "");
667 print NORM
"\n$string" if $string;
672 # Finally, more complex, the opengl_ext.c file
674 open(EXT
, ">$ext_file");
676 /* Auto-generated file... Do not edit ! */
678 #include \"config.h\"
679 #include \"opengl_ext.h\"
680 #include \"wine/debug.h\"
682 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
686 # The thunks themselves....
687 my $count = keys %ext_functions;
688 print EXT
"const int extension_registry_size = $count;\n";
689 print EXT
"void *extension_funcs[$count];\n";
690 print EXT
"\n/* The thunks themselves....*/";
692 foreach (sort keys %ext_functions) {
693 my $func_ref = $ext_functions{$_};
694 my $local_var = " " . ConvertType
($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
695 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
696 my $type = ConvertType
($func_ref->[2]->[$i]->[0]);
697 $local_var .= "$type";
698 if ($i != $#{@{$func_ref->[2]}}) {
704 $local_var .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
705 $local_var .= ") = extension_funcs[$pos];\n";
707 print EXT
"\nstatic ", GenerateThunk
($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
710 # Then the table giving the string <-> function correspondance */
711 print EXT
"\n\n/* The table giving the correspondance between names and functions */\n";
712 print EXT
"const OpenGL_extension extension_registry[$count] = {\n";
714 foreach (sort keys %ext_functions) {
715 my $func_ref = $ext_functions{$_};
716 if ($func_ref->[0] eq $func_ref->[3])
718 print EXT
" { \"$func_ref->[0]\", \"$func_ref->[4]\", (void *) wine_$func_ref->[0] }";
720 if ($i != $count-1) {