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.1.
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.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;
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{"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";
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.
371 # An element of the hash table is a reference to an array with these
378 # - reference to an array giving the list of arguments (an empty array
379 # for a 'void' function).
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.
386 # void glBitmap( GLsizei width, GLsizei height,
387 # GLfloat xorig, GLfloat yorig,
388 # GLfloat xmove, GLfloat ymove,
389 # const GLubyte *bitmap );
391 # Would give something like that :
395 # [ [ "GLsizei", "width" ],
396 # [ "GLsizei", "height" ],
397 # [ "GLfloat", "xorig" ],
398 # [ "GLfloat", "yorig" ],
399 # [ "GLfloat", "xmove" ],
400 # [ "GLfloat", "ymove" ],
401 # [ "GLubyte *", "bitmap"] ] ];
403 my %norm_functions = ();
406 # This stores various extensions NOT part of the GL extension registry but still
407 # implemented by most OpenGL libraries out there...
411 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
412 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
415 [ "GLsizei", "width" ],
416 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
417 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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" ]
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;
540 # - category (the extension the function is part of)
541 # - the argument types
542 # - the category the function belongs
548 unless (defined($line)) {
550 } elsif ($line =~ /^\s*$/) {
551 if (($category eq "") || ($ret_type eq "")) {
552 die "Missing 'category' line in function $funcname.\n";
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";
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*) (.*)/);
566 unless (defined($name)) {
568 die "Broken spec file line $line in function $funcname\n";
571 if ($ext =~ /array/) {
574 } elsif ($ext =~ /reference/) {
577 } elsif ($ext =~ /value/) {
578 # And this a 'normal' value
582 die "Unsupported type : $line in function $funcname\n";
584 # Get the 'real' type and append a '*' in case of a pointer
585 my $type = $pseudo_to_opengl{$base_type};
586 unless (defined($type)) {
588 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
594 $arg_types{$name} = $type;
598 # Now, build the argument reference
600 for (my $i = 0; $i < @arg_names; $i++) {
601 unless (defined($arg_types{$arg_names[$i]})) {
602 print "@arg_names\n";
603 foreach (sort keys %arg_types) {
604 print "$_ => $arg_types{$_}\n";
606 die "Undefined type for $arg_names[$i] in function $funcname\n";
609 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
611 my $func_ref = [ "gl$funcname",
617 # Now, put in one or the other hash table
618 if ($norm_categories{$category}) {
619 $norm_functions{"gl$funcname"} = $func_ref;
621 $ext_functions{"gl$funcname"} = $func_ref;
627 # Clean up the input files
633 # Now, generate the output files. First, the spec file.
635 open(SPEC, ">$spec_file");
637 foreach (sort keys %norm_functions) {
638 my $func_name = $norm_functions{$_}->[0];
639 print SPEC "@ stdcall $func_name( ";
640 for (my $i = 0; $i < @{$norm_functions{$_}->[2]}; $i++) {
641 my $type = $norm_functions{$_}->[2]->[$i]->[0];
644 } elsif (defined($arg_conv{$type})) {
645 print SPEC "$@$arg_conv{$type}[0] ";
647 die "No conversion for GL type $type...\n";
650 print SPEC ") wine_$func_name\n";
653 print SPEC "@ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
654 @ stdcall wglCopyContext(long long long) gdi32.wglCopyContext
655 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
656 @ stdcall wglCreateLayerContext(long long)
657 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
658 @ stdcall wglDescribeLayerPlane(long long long long ptr)
659 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
660 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
661 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
662 @ stub wglGetDefaultProcAddress
663 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
664 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
665 @ stdcall wglGetProcAddress(str)
666 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
667 @ stdcall wglRealizeLayerPalette(long long long)
668 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
669 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
670 @ stdcall wglShareLists(long long) gdi32.wglShareLists
671 @ stdcall wglSwapBuffers(long)
672 @ stdcall wglSwapLayerBuffers(long long)
673 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
674 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
675 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
676 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
682 # After the spec file, the opengl_norm.c file
684 open(NORM, ">$norm_file");
686 /* Auto-generated file... Do not edit ! */
688 #include \"config.h\"
689 #include \"opengl_ext.h\"
690 #include \"wine/debug.h\"
692 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
694 foreach (sort keys %norm_functions) {
695 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
697 print NORM "\n$string" if $string;
702 # Finally, more complex, the opengl_ext.c file
704 open(EXT, ">$ext_file");
706 /* Auto-generated file... Do not edit ! */
708 #include \"config.h\"
709 #include \"opengl_ext.h\"
710 #include \"wine/debug.h\"
712 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
716 # The thunks themselves....
717 my $count = keys %ext_functions;
718 print EXT "enum extensions\n{\n";
719 foreach (sort keys %ext_functions) {
720 my $func_ref = $ext_functions{$_};
721 print EXT " EXT_$func_ref->[0],\n";
723 print EXT " NB_EXTENSIONS\n};\n\n";
724 print EXT "const int extension_registry_size = NB_EXTENSIONS;\n";
725 print EXT "void *extension_funcs[NB_EXTENSIONS];\n";
726 print EXT "\n/* The thunks themselves....*/";
727 foreach (sort keys %ext_functions) {
728 my $func_ref = $ext_functions{$_};
729 my $local_var = " " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
730 for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
731 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
732 $local_var .= "$type";
733 if ($i+1 < @{$func_ref->[2]}) {
739 $local_var .= 'void ' if (!@{$func_ref->[2]});
740 $local_var .= ") = extension_funcs[EXT_$func_ref->[0]];\n";
741 print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
744 # Then the table giving the string <-> function correspondence */
745 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
746 print EXT "const OpenGL_extension extension_registry[NB_EXTENSIONS] = {\n";
748 foreach (sort keys %ext_functions) {
749 my $func_ref = $ext_functions{$_};
750 if ($func_ref->[0] eq $func_ref->[3])
752 print EXT " { \"$func_ref->[0]\", \"$func_ref->[4]\", wine_$func_ref->[0] }";
754 if ($i != $count-1) {