opengl32: Make the script default to version 1.1. Remove the glGetLevelParameter...
[wine/multimedia.git] / dlls / opengl32 / make_opengl
blobb2966dc52dbfcf0f730119b25b9e658dc97a487f
1 #!/usr/bin/perl -w
2 use strict;
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
10 # opengl.org:
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
33 # 'opengl_version').
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
65 # Files to generate
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
76 my $gen_traces = 1;
79 # List of categories to put in the 'opengl_norm.c' file
81 my %cat_1_0 = ( "display-list" => 1,
82 "drawing" => 1,
83 "drawing-control" => 1,
84 "feedback" => 1,
85 "framebuf" => 1,
86 "misc" => 1,
87 "modeling" => 1,
88 "pixel-op" => 1,
89 "pixel-rw" => 1,
90 "state-req" => 1,
91 "xform" => 1,
92 "VERSION_1_0" => 1,
93 "VERSION_1_0_DEPRECATED" => 1 );
94 my %cat_1_1 = ( %cat_1_0,
95 "VERSION_1_1" => 1,
96 "VERSION_1_1_DEPRECATED" => 1 );
97 my %cat_1_2 = ( %cat_1_1,
98 "VERSION_1_2" => 1,
99 "VERSION_1_2_DEPRECATED" => 1 );
100 my %cat_1_3 = ( %cat_1_2,
101 "VERSION_1_3" => 1,
102 "VERSION_1_3_DEPRECATED" => 1 );
103 my %cat_1_4 = ( %cat_1_3,
104 "VERSION_1_4" => 1,
105 "VERSION_1_4_DEPRECATED" => 1 );
106 my %cat_1_5 = ( %cat_1_4,
107 "VERSION_1_5" => 1,
108 "VERSION_1_5_DEPRECATED" => 1 );
110 my %norm_categories = ();
113 # This hash table gives the conversion between OpenGL types and what
114 # is used by the TRACE printfs
116 my %debug_conv =
117 ("GLbitfield" => "%d",
118 "GLboolean" => "%d",
119 "GLbyte" => "%d",
120 "GLclampd" => "%f",
121 "GLclampf" => "%f",
122 "GLdouble" => "%f",
123 "GLenum" => "%d",
124 "GLfloat" => "%f",
125 "GLint" => "%d",
126 "GLshort" => "%d",
127 "GLsizei" => "%d",
128 "GLstring" => "%s",
129 "GLubyte" => "%d",
130 "GLuint" => "%d",
131 "GLushort" => "%d",
132 "GLhalfNV" => "%d",
133 "GLintptrARB" => "%ld",
134 "GLsizeiptrARB" => "%ld",
135 "GLintptr" => "%ld",
136 "GLsizeiptr" => "%ld",
137 "GLhandleARB" => "%d",
138 "GLcharARB" => "%c",
139 "GLvoid" => "(void)",
140 "_GLfuncptr" => "%p",
141 "UINT64" => "%s,wine_dbgstr_longlong(%s)"
145 # This hash table gives the conversion between OpenGL types and what
146 # is used in the .spec file
148 my %arg_conv =
149 ("GLbitfield" => [ "long", 4 ],
150 "GLboolean" => [ "long", 4 ],
151 "GLbyte" => [ "long", 4 ],
152 "GLclampd" => [ "double", 8 ],
153 "GLclampf" => [ "long", 4 ],
154 "GLdouble" => [ "double", 8 ],
155 "GLenum" => [ "long", 4 ],
156 "GLfloat" => [ "long", 4 ],
157 "GLint" => [ "long", 4 ],
158 "GLshort" => [ "long", 4 ],
159 "GLsizei" => [ "long", 4 ],
160 "GLstring" => [ "str", 4 ],
161 "GLubyte" => [ "long", 4 ],
162 "GLuint" => [ "long", 4 ],
163 "GLushort" => [ "long", 4 ],
164 "GLhalfNV" => [ "long", 4 ],
165 "GLintptrARB" => [ "long", 4 ],
166 "GLsizeiptrARB" => [ "long", 4 ],
167 "GLhandleARB" => [ "long", 4 ],
168 "GLcharARB" => [ "long", 4 ],
169 "GLintptr" => [ "long", 4 ],
170 "GLsizeiptr" => [ "long", 4 ],
171 "GLvoid" => [ "void", 4 ],
172 "_GLfuncptr" => [ "ptr", 4 ]);
175 # Used to convert some types
177 sub ConvertType($)
179 my ($type) = @_;
181 my %hash = ( "GLstring" => "const GLubyte *",
182 "GLintptrARB" => "INT_PTR",
183 "GLsizeiptrARB" => "INT_PTR",
184 "GLintptr" => "INT_PTR",
185 "GLsizeiptr" => "INT_PTR",
186 "GLhandleARB" => "unsigned int",
187 "GLcharARB" => "char",
188 "GLchar" => "char",
189 "GLhalfNV" => "unsigned short" );
191 foreach my $org (reverse sort keys %hash) {
192 if ($type =~ /$org/) {
193 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
194 return "$before$hash{$org}$after";
197 return $type;
201 # Used to convert some variable names
203 sub ConvertVarName($)
205 my ($type) = @_;
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";
216 return $type;
220 # This functions generates the thunk for a given function.
222 sub GenerateThunk($$$$$)
224 my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
225 my $ret = "";
226 my $call_arg = "";
227 my $trace_call_arg = "";
228 my $trace_arg = "";
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. :-)
237 if ($comment eq 1) {
238 $ret = "$ret/***********************************************************************\n";
239 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
240 $ret = "$ret */\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";
249 $call_arg .= $name;
250 if ($type =~ /\*/) {
251 $trace_arg .= "%p";
252 $trace_call_arg .= $name;
253 } else {
254 if ($debug_conv{$type} =~ /(.*),(.*)/)
256 $trace_arg .= $1;
257 $trace_call_arg .= sprintf $2, $name;
259 else
261 $trace_arg .= $debug_conv{$type};
262 $trace_call_arg .= $name;
265 if ($i+1 < @{$func_ref->[2]}) {
266 $ret .= ", ";
267 $call_arg .= ", ";
268 $trace_call_arg .= ", ";
269 $trace_arg .= ", ";
270 } else {
271 $ret .= " ";
272 $call_arg .= " ";
273 $trace_call_arg .= " ";
276 $ret .= 'void ' if (!@{$func_ref->[2]});
277 $ret = "$ret) {\n";
278 if ($func_ref->[1] ne "void") {
279 $ret = "$ret " . ConvertType($func_ref->[1]) . " ret_value;\n";
281 $ret .= $local_var;
282 if ($gen_traces) {
283 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
284 if ($trace_arg ne "") {
285 $ret .= ", $trace_call_arg";
287 $ret = "$ret);\n";
289 if ($thread_safe) {
290 $ret = "$ret ENTER_GL();\n";
292 $ret = "$ret ";
293 if ($func_ref->[1] ne "void") {
294 $ret = $ret . "ret_value = ";
296 $ret = "$ret$prefix$func_ref->[0]( $call_arg);\n";
297 if ($thread_safe) {
298 $ret = "$ret LEAVE_GL();\n";
300 if ($func_ref->[1] ne "void") {
301 $ret = "$ret return ret_value;\n"
303 $ret = "$ret}\n";
305 # Return this string....
306 return $ret;
310 # Extract and checks the number of arguments
312 if (@ARGV > 1) {
313 my $name0=$0;
314 $name0=~s%^.*/%%;
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;
330 } else {
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
369 # elements :
371 # - function name
373 # - return type
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.
381 # An example :
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 :
390 # [ "glBitmap",
391 # "void",
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...
407 my %ext_functions =
408 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
409 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
410 [ "GLint", "x" ],
411 [ "GLint", "y" ],
412 [ "GLsizei", "width" ],
413 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
414 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
415 [ "GLint", "x" ],
416 [ "GLint", "y" ],
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" ],
424 [ "GLfloat", "s" ],
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" ],
445 [ "GLdouble", "s"],
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" ],
450 [ "GLfloat", "s" ],
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" ],
455 [ "GLint", "s" ],
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" ],
460 [ "GLshort", "s" ],
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" ],
465 [ "GLdouble", "s" ],
466 [ "GLdouble", "t" ],
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" ],
471 [ "GLfloat", "s" ],
472 [ "GLfloat", "t" ],
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" ],
477 [ "GLint", "s" ],
478 [ "GLint", "t" ],
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" ],
483 [ "GLshort", "s" ],
484 [ "GLshort", "t" ],
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" ],
489 [ "GLdouble", "s" ],
490 [ "GLdouble", "t" ],
491 [ "GLdouble", "r" ],
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" ],
496 [ "GLfloat", "s" ],
497 [ "GLfloat", "t" ],
498 [ "GLfloat", "r" ],
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" ],
503 [ "GLint", "s" ],
504 [ "GLint", "t" ],
505 [ "GLint", "r" ],
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" ],
510 [ "GLshort", "s" ],
511 [ "GLshort", "t" ],
512 [ "GLshort", "r" ],
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" ],
517 [ "GLint", "size" ],
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" ]
526 my @arg_names;
527 my %arg_types;
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;
535 # After get :
536 # - the return type
537 # - category (the extension the function is part of)
538 # - the argument types
539 # - the category the function belongs
540 %arg_types = ();
541 my $category = "";
542 my $ret_type = "";
543 while (1) {
544 $line = <REGISTRY>;
545 unless (defined($line)) {
546 last;
547 } elsif ($line =~ /^\s*$/) {
548 if (($category eq "") || ($ret_type eq "")) {
549 die "Missing 'category' line in function $funcname.\n";
551 last;
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*) (.*)/);
562 my $ptr = 0;
563 unless (defined($name)) {
564 chomp $line;
565 die "Broken spec file line $line in function $funcname\n";
568 if ($ext =~ /array/) {
569 # This is a pointer
570 $ptr = 1;
571 } elsif ($ext =~ /value/) {
572 # And this a 'normal' value
573 $ptr = 0;
574 } else {
575 chomp $line;
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)) {
581 chomp $line;
582 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
584 if ($ptr) {
585 $type = "$type*";
588 $arg_types{$name} = $type;
592 # Now, build the argument reference
593 my $arg_ref = [ ];
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",
606 $ret_type,
607 $arg_ref,
608 "gl$funcname",
609 "GL_$category" ];
611 # Now, put in one or the other hash table
612 if ($norm_categories{$category}) {
613 $norm_functions{"gl$funcname"} = $func_ref;
614 } else {
615 $ext_functions{"gl$funcname"} = $func_ref;
621 # Clean up the input files
623 close(TYPES);
624 close(REGISTRY);
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];
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";
647 print SPEC "@ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
648 @ stdcall wglCopyContext(long long long) gdi32.wglCopyContext
649 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
650 @ stdcall wglCreateLayerContext(long long)
651 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
652 @ stdcall wglDescribeLayerPlane(long long long long ptr)
653 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
654 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
655 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
656 @ stub wglGetDefaultProcAddress
657 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
658 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
659 @ stdcall wglGetProcAddress(str)
660 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
661 @ stdcall wglRealizeLayerPalette(long long long)
662 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
663 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
664 @ stdcall wglShareLists(long long) gdi32.wglShareLists
665 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
666 @ stdcall wglSwapLayerBuffers(long long)
667 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
668 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
669 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
670 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
673 close(SPEC);
676 # After the spec file, the opengl_norm.c file
678 open(NORM, ">$norm_file");
679 print NORM "
680 /* Auto-generated file... Do not edit ! */
682 #include \"config.h\"
683 #include \"opengl_ext.h\"
684 #include \"wine/debug.h\"
686 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
688 foreach (sort keys %norm_functions) {
689 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
691 print NORM "\n$string" if $string;
693 close(NORM);
696 # Finally, more complex, the opengl_ext.c file
698 open(EXT, ">$ext_file");
699 print EXT "
700 /* Auto-generated file... Do not edit ! */
702 #include \"config.h\"
703 #include \"opengl_ext.h\"
704 #include \"wine/debug.h\"
706 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
710 # The thunks themselves....
711 my $count = keys %ext_functions;
712 print EXT "enum extensions\n{\n";
713 foreach (sort keys %ext_functions) {
714 my $func_ref = $ext_functions{$_};
715 print EXT " EXT_$func_ref->[0],\n";
717 print EXT " NB_EXTENSIONS\n};\n\n";
718 print EXT "const int extension_registry_size = NB_EXTENSIONS;\n";
719 print EXT "void *extension_funcs[NB_EXTENSIONS];\n";
720 print EXT "\n/* The thunks themselves....*/";
721 foreach (sort keys %ext_functions) {
722 my $func_ref = $ext_functions{$_};
723 my $local_var = " " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
724 for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
725 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
726 $local_var .= "$type";
727 if ($i+1 < @{$func_ref->[2]}) {
728 $local_var .= ", ";
729 } else {
730 $local_var .= " ";
733 $local_var .= 'void ' if (!@{$func_ref->[2]});
734 $local_var .= ") = extension_funcs[EXT_$func_ref->[0]];\n";
735 print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
738 # Then the table giving the string <-> function correspondence */
739 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
740 print EXT "const OpenGL_extension extension_registry[NB_EXTENSIONS] = {\n";
741 my $i = 0;
742 foreach (sort keys %ext_functions) {
743 my $func_ref = $ext_functions{$_};
744 if ($func_ref->[0] eq $func_ref->[3])
746 print EXT " { \"$func_ref->[0]\", \"$func_ref->[4]\", wine_$func_ref->[0] }";
748 if ($i != $count-1) {
749 print EXT ",";
751 $i++;
752 print EXT "\n";
754 print EXT "};\n";
756 close(EXT);