4 # This script is called thus :
6 # make_opengl [opengl_version]
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
12 # http://www.opengl.org/registry/api/gl.spec
13 # http://www.opengl.org/registry/api/gl.tm
15 # If they are not found in the current directory the script will
16 # attempt to download them from there.
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/
24 # - opengl_version is the OpenGL version emulated by the library
25 # (can be 1.0 to 1.5). The default is 1.2.
27 # This script generates the three following files :
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
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.
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).
47 # Copyright 2000 Lionel Ulmer
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.
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.
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
67 my $spec_file = "opengl32.spec";
68 my $norm_file = "opengl_norm.c";
69 my $ext_file = "opengl_ext.c";
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
79 # List of categories to put in the 'opengl_norm.c' file
81 my %cat_1_0 = ( "display-list" => 1,
83 "drawing-control" => 1,
93 "VERSION_1_0_DEPRECATED" => 1 );
94 my %cat_1_1 = ( %cat_1_0,
96 "VERSION_1_1_DEPRECATED" => 1 );
97 my %cat_1_2 = ( %cat_1_1,
99 "VERSION_1_2_DEPRECATED" => 1 );
100 my %cat_1_3 = ( %cat_1_2,
102 "VERSION_1_3_DEPRECATED" => 1 );
103 my %cat_1_4 = ( %cat_1_3,
105 "VERSION_1_4_DEPRECATED" => 1 );
106 my %cat_1_5 = ( %cat_1_4,
108 "VERSION_1_5_DEPRECATED" => 1 );
110 my %norm_categories = ();
113 # This hash table gives the conversion between OpenGL types and what
114 # is used by the TRACE printfs
117 ("GLbitfield" => "%d",
133 "GLintptrARB" => "%ld",
134 "GLsizeiptrARB" => "%ld",
136 "GLsizeiptr" => "%ld",
137 "GLhandleARB" => "%d",
139 "GLvoid" => "(void)",
140 "_GLfuncptr" => "%p",
141 "UINT64" => "%s,wine_dbgstr_longlong(%s)"
145 # This hash table gives the conversion between OpenGL types and what
146 # is used in the .spec file
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 ]);
175 # Used to convert some types
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",
189 "GLhalfNV" => "unsigned short" );
191 foreach my $org (reverse sort keys %hash) {
192 if ($type =~ /$org/) {
193 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
194 return "$before$hash{$org}$after";
201 # Used to convert some variable names
203 sub ConvertVarName($)
207 my %hash = ( "near" => "nearParam",
208 "far" => "farParam" );
210 foreach my $org (keys %hash) {
211 if ($type =~ /$org/) {
212 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
213 return "$before$hash{$org}$after";
220 # This functions generates the thunk for a given function.
222 sub GenerateThunk($$$$$)
224 my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
227 my $trace_call_arg = "";
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";
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. :-)
238 $ret = "$ret/***********************************************************************\n";
239 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
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";
252 $trace_call_arg .= $name;
254 if ($debug_conv{$type} =~ /(.*),(.*)/)
257 $trace_call_arg .= sprintf $2, $name;
261 $trace_arg .= $debug_conv{$type};
262 $trace_call_arg .= $name;
265 if ($i+1 < @{$func_ref->[2]}) {
268 $trace_call_arg .= ", ";
273 $trace_call_arg .= " ";
276 $ret .= 'void ' if (!@{$func_ref->[2]});
278 if ($func_ref->[1] ne "void") {
279 $ret = "$ret " . ConvertType($func_ref->[1]) . " ret_value;\n";
283 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
284 if ($trace_arg ne "") {
285 $ret .= ", $trace_call_arg";
290 $ret = "$ret ENTER_GL();\n";
293 if ($func_ref->[1] ne "void") {
294 $ret = $ret . "ret_value = ";
296 $ret = "$ret$prefix$func_ref->[0]( $call_arg);\n";
298 $ret = "$ret LEAVE_GL();\n";
300 if ($func_ref->[1] ne "void") {
301 $ret = "$ret return ret_value;\n"
305 # Return this string....
310 # Extract and checks the number of arguments
315 die "Usage: $name0 [version]\n";
317 my $version = $ARGV[0] || "1.2";
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;
331 die "Incorrect OpenGL version.\n";
335 # Fetch the registry files
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";
341 # Open the registry files
343 open(TYPES, "gl.tm") || die "Could not open gl.tm";
344 open(REGISTRY, "gl.spec") || die "Could not open gl.spec";
347 # First, create a mapping between the pseudo types used in the spec file
348 # and OpenGL types using the 'gl.tm' file.
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;
357 # This is to override the 'void' -> '*' bogus conversion
358 $pseudo_to_opengl{"void"} = "void";
359 $pseudo_to_opengl{"Int64EXT"} = "INT64";
360 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
363 # Then, create the list of all OpenGL functions using the 'gl.spec'
364 # file. This will create two hash-tables, one with all the function
365 # whose category matches the one listed in '@norm_categories', the other
366 # with all other functions.
368 # An element of the hash table is a reference to an array with these
375 # - reference to an array giving the list of arguments (an empty array
376 # for a 'void' function).
378 # The list of arguments is itself an array of reference to arrays. Each
379 # of these arrays represents the argument type and the argument name.
383 # void glBitmap( GLsizei width, GLsizei height,
384 # GLfloat xorig, GLfloat yorig,
385 # GLfloat xmove, GLfloat ymove,
386 # const GLubyte *bitmap );
388 # Would give something like that :
392 # [ [ "GLsizei", "width" ],
393 # [ "GLsizei", "height" ],
394 # [ "GLfloat", "xorig" ],
395 # [ "GLfloat", "yorig" ],
396 # [ "GLfloat", "xmove" ],
397 # [ "GLfloat", "ymove" ],
398 # [ "GLubyte *", "bitmap"] ] ];
400 my %norm_functions = ();
403 # This stores various extensions NOT part of the GL extension registry but still
404 # implemented by most OpenGL libraries out there...
408 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
409 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
412 [ "GLsizei", "width" ],
413 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
414 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
417 [ "GLsizei", "width" ],
418 [ "GLsizei", "height" ],
419 [ "GLint", "xDest" ],
420 [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
421 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled", "GL_KTX_buffer_region" ],
422 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
423 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
425 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
426 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
427 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
428 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
429 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
430 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
431 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
432 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
433 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
434 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
435 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
436 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
437 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
438 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
439 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
440 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
441 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
442 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
443 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
444 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
446 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
447 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
448 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
449 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
451 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
452 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
453 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
454 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
456 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
457 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
458 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
459 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
461 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
462 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
463 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
464 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
467 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
468 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
469 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
470 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
473 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
474 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
475 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
476 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
479 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
480 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
481 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
482 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
485 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
486 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
487 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
488 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
492 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
493 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
494 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
495 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
499 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
500 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
501 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
502 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
506 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
507 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
508 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
509 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
513 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
514 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
515 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
516 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
518 [ "GLenum", "type" ],
519 [ "GLsizei", "stride" ],
520 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
521 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
522 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
523 "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
528 while (my $line = <REGISTRY>) {
529 if ($line =~ /^\w*\(.*\)/) {
530 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
531 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
532 # and the argument names
533 @arg_names = split /\s*,\s*/, $args;
537 # - category (the extension the function is part of)
538 # - the argument types
539 # - the category the function belongs
545 unless (defined($line)) {
547 } elsif ($line =~ /^\s*$/) {
548 if (($category eq "") || ($ret_type eq "")) {
549 die "Missing 'category' line in function $funcname.\n";
552 } elsif ($line =~ /\t*return\t*(\w*)/) {
553 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
554 $ret_type = $pseudo_to_opengl{$ret_type};
555 unless (defined($ret_type)) {
556 die "Unsupported return type in function $funcname\n";
558 } elsif ($line =~ /^\t*category/) {
559 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
560 } elsif ($line =~ /^\t*param/) {
561 my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
563 unless (defined($name)) {
565 die "Broken spec file line $line in function $funcname\n";
568 if ($ext =~ /array/) {
571 } elsif ($ext =~ /value/) {
572 # And this a 'normal' value
576 die "Unsupported type : $line in function $funcname\n";
578 # Get the 'real' type and append a '*' in case of a pointer
579 my $type = $pseudo_to_opengl{$base_type};
580 unless (defined($type)) {
582 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
588 $arg_types{$name} = $type;
592 # Now, build the argument reference
594 for (my $i = 0; $i < @arg_names; $i++) {
595 unless (defined($arg_types{$arg_names[$i]})) {
596 print "@arg_names\n";
597 foreach (sort keys %arg_types) {
598 print "$_ => $arg_types{$_}\n";
600 die "Undefined type for $arg_names[$i] in function $funcname\n";
603 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
605 my $func_ref = [ "gl$funcname",
611 # Now, put in one or the other hash table
612 if ($norm_categories{$category}) {
613 $norm_functions{"gl$funcname"} = $func_ref;
615 $ext_functions{"gl$funcname"} = $func_ref;
621 # Clean up the input files
627 # Now, generate the output files. First, the spec file.
629 open(SPEC, ">$spec_file");
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];
638 } elsif (defined($arg_conv{$type})) {
639 print SPEC "$@$arg_conv{$type}[0] ";
641 die "No conversion for GL type $type...\n";
644 print SPEC ") wine_$func_name\n";
647 print SPEC "@ stub glGetLevelParameterfv
648 @ stub glGetLevelParameteriv
649 @ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
650 @ stdcall wglCopyContext(long long long) gdi32.wglCopyContext
651 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
652 @ stdcall wglCreateLayerContext(long long)
653 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
654 @ stdcall wglDescribeLayerPlane(long long long long ptr)
655 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
656 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
657 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
658 @ stub wglGetDefaultProcAddress
659 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
660 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
661 @ stdcall wglGetProcAddress(str)
662 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
663 @ stdcall wglRealizeLayerPalette(long long long)
664 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
665 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
666 @ stdcall wglShareLists(long long) gdi32.wglShareLists
667 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
668 @ stdcall wglSwapLayerBuffers(long long)
669 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
670 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
671 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
672 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
678 # After the spec file, the opengl_norm.c file
680 open(NORM, ">$norm_file");
682 /* Auto-generated file... Do not edit ! */
684 #include \"config.h\"
685 #include \"opengl_ext.h\"
686 #include \"wine/debug.h\"
688 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
690 foreach (sort keys %norm_functions) {
691 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
693 print NORM "\n$string" if $string;
698 # Finally, more complex, the opengl_ext.c file
700 open(EXT, ">$ext_file");
702 /* Auto-generated file... Do not edit ! */
704 #include \"config.h\"
705 #include \"opengl_ext.h\"
706 #include \"wine/debug.h\"
708 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
712 # The thunks themselves....
713 my $count = keys %ext_functions;
714 print EXT "enum extensions\n{\n";
715 foreach (sort keys %ext_functions) {
716 my $func_ref = $ext_functions{$_};
717 print EXT " EXT_$func_ref->[0],\n";
719 print EXT " NB_EXTENSIONS\n};\n\n";
720 print EXT "const int extension_registry_size = NB_EXTENSIONS;\n";
721 print EXT "void *extension_funcs[NB_EXTENSIONS];\n";
722 print EXT "\n/* The thunks themselves....*/";
723 foreach (sort keys %ext_functions) {
724 my $func_ref = $ext_functions{$_};
725 my $local_var = " " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
726 for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
727 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
728 $local_var .= "$type";
729 if ($i+1 < @{$func_ref->[2]}) {
735 $local_var .= 'void ' if (!@{$func_ref->[2]});
736 $local_var .= ") = extension_funcs[EXT_$func_ref->[0]];\n";
737 print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
740 # Then the table giving the string <-> function correspondence */
741 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
742 print EXT "const OpenGL_extension extension_registry[NB_EXTENSIONS] = {\n";
744 foreach (sort keys %ext_functions) {
745 my $func_ref = $ext_functions{$_};
746 if ($func_ref->[0] eq $func_ref->[3])
748 print EXT " { \"$func_ref->[0]\", \"$func_ref->[4]\", wine_$func_ref->[0] }";
750 if ($i != $count-1) {