shell32: Fix the Chinese translations.
[wine.git] / dlls / opengl32 / make_opengl
blob2fb447b16b093c8bd8dfaad0c88ae1a7dd7f91ab
1 #!/usr/bin/perl -w
2 use strict;
4 # This script is called thus :
6 # make_opengl path_to_spec_file opengl_version
8 # - path_to_spec_file is the path to the directory where the OpenGL
9 # spec files are located. These files are 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
29 # 'opengl_version').
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
61 # Files to generate
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
72 my $gen_traces = 1;
75 # List of categories to put in the 'opengl_norm.c' file
77 my %cat_1_0 = ( "display-list" => 1,
78 "drawing" => 1,
79 "drawing-control" => 1,
80 "feedback" => 1,
81 "framebuf" => 1,
82 "misc" => 1,
83 "modeling" => 1,
84 "pixel-op" => 1,
85 "pixel-rw" => 1,
86 "state-req" => 1,
87 "xform" => 1 );
88 my %cat_1_1 = ( %cat_1_0,
89 "1_1" => 1 );
90 my %cat_1_2 = ( %cat_1_1,
91 "VERSION_1_2" => 1 );
92 my %cat_1_3 = ( %cat_1_2,
93 "VERSION_1_3" => 1 );
94 my %cat_1_4 = ( %cat_1_3,
95 "VERSION_1_4" => 1 );
96 my %cat_1_5 = ( %cat_1_4,
97 "VERSION_1_5" => 1 );
99 my %norm_categories = ();
102 # This hash table gives the conversion between OpenGL types and what
103 # is used by the TRACE printfs
105 my %debug_conv =
106 ("GLbitfield" => "%d",
107 "GLboolean" => "%d",
108 "GLbyte" => "%d",
109 "GLclampd" => "%f",
110 "GLclampf" => "%f",
111 "GLdouble" => "%f",
112 "GLenum" => "%d",
113 "GLfloat" => "%f",
114 "GLint" => "%d",
115 "GLshort" => "%d",
116 "GLsizei" => "%d",
117 "GLstring" => "%s",
118 "GLubyte" => "%d",
119 "GLuint" => "%d",
120 "GLushort" => "%d",
121 "GLhalfNV" => "%d",
122 "GLintptrARB" => "%d",
123 "GLsizeiptrARB" => "%d",
124 "GLintptr" => "%d",
125 "GLsizeiptr" => "%d",
126 "GLhandleARB" => "%d",
127 "GLcharARB" => "%c",
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
135 my %arg_conv =
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
164 sub ConvertType($)
166 my ($type) = @_;
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",
175 "GLchar" => "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";
184 return $type;
188 # Used to convert some variable names
190 sub ConvertVarName($)
192 my ($type) = @_;
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";
203 return $type;
207 # This functions generates the thunk for a given function.
209 sub GenerateThunk($$$$$)
211 my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
212 my $ret = "";
213 my $call_arg = "";
214 my $trace_arg = "";
216 return "" if $func_ref->[0] eq "glGetString";
217 return "" if $func_ref->[0] eq "glGetIntegerv";
218 return "" if $func_ref->[0] eq "glFinish";
219 return "" if $func_ref->[0] eq "glFlush";
221 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
222 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
223 if ($comment eq 1) {
224 $ret = "$ret/***********************************************************************\n";
225 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
226 $ret = "$ret */\n";
228 $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
229 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
230 ## Quick debug code :-)
231 ## print $func_ref->[2]->[$i]->[1] . "\n";
232 my $type = $func_ref->[2]->[$i]->[0];
233 my $name = ConvertVarName($func_ref->[2]->[$i]->[1]);
234 $ret = $ret . ConvertType($type) . " $name";
235 $call_arg = "$call_arg$name";
236 if ($type =~ /\*/) {
237 $trace_arg = "$trace_arg\%p";
238 } else {
239 $trace_arg = "$trace_arg$debug_conv{$type}";
241 if ($i != $#{@{$func_ref->[2]}}) {
242 $ret = "$ret, ";
243 $call_arg = "$call_arg, ";
244 $trace_arg = "$trace_arg, ";
245 } else {
246 $ret = "$ret ";
247 $call_arg = "$call_arg ";
250 $ret .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
251 $ret = "$ret) {\n";
252 if ($func_ref->[1] ne "void") {
253 $ret = "$ret " . ConvertType($func_ref->[1]) . " ret_value;\n";
255 $ret .= $local_var;
256 if ($gen_traces) {
257 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
258 if ($trace_arg ne "") {
259 $ret = "$ret, $call_arg";
261 $ret = "$ret);\n";
263 if ($thread_safe) {
264 $ret = "$ret ENTER_GL();\n";
266 $ret = "$ret ";
267 if ($func_ref->[1] ne "void") {
268 $ret = $ret . "ret_value = ";
270 $ret = "$ret$prefix$func_ref->[0]( $call_arg);\n";
271 if ($thread_safe) {
272 $ret = "$ret LEAVE_GL();\n";
274 if ($func_ref->[1] ne "void") {
275 $ret = "$ret return ret_value;\n"
277 $ret = "$ret}\n";
279 # Return this string....
280 return $ret;
284 # Extract and checks the number of arguments
286 if (@ARGV != 2) {
287 my $name0=$0;
288 $name0=~s%^.*/%%;
289 die "Usage: $name0 OpenGL_registry_location OpenGL_version\n";
291 my $registry_path = shift @ARGV;
292 my $version = shift @ARGV;
293 if ($version eq "1.0") {
294 %norm_categories = %cat_1_0;
295 } elsif ($version eq "1.1") {
296 %norm_categories = %cat_1_1;
297 } elsif ($version eq "1.2") {
298 %norm_categories = %cat_1_2;
299 } elsif ($version eq "1.3") {
300 %norm_categories = %cat_1_3;
301 } elsif ($version eq "1.4") {
302 %norm_categories = %cat_1_4;
303 } elsif ($version eq "1.5") {
304 %norm_categories = %cat_1_5;
305 } else {
306 die "Incorrect OpenGL version.\n";
310 # Open the registry files
312 open(TYPES, "$registry_path/gl.tm") || die "Could not open 'gl.tm'. Please check your path in the registry files.\n";
313 open(REGISTRY, "$registry_path/gl.spec") || die "Could not open 'gl.spec'. Please check your path in the registry files.\n";
316 # First, create a mapping between the pseudo types used in the spec file
317 # and OpenGL types using the 'gl.tm' file.
319 my %pseudo_to_opengl = ();
320 while (my $line = <TYPES>) {
321 if ($line !~ /\w*\#/) {
322 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
323 $pseudo_to_opengl{$pseudo} = $opengl;
326 # This is to override the 'void' -> '*' bogus conversion
327 $pseudo_to_opengl{"void"} = "void";
328 $pseudo_to_opengl{"Int64EXT"} = "INT64";
329 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
332 # Then, create the list of all OpenGL functions using the 'gl.spec'
333 # file. This will create two hash-tables, one with all the function
334 # whose category matches the one listed in '@norm_categories', the other
335 # with all other functions.
337 # An element of the hash table is a reference to an array with these
338 # elements :
340 # - function name
342 # - return type
344 # - reference to an array giving the list of arguments (an empty array
345 # for a 'void' function).
347 # The list of arguments is itself an array of reference to arrays. Each
348 # of these arrays represents the argument type and the argument name.
350 # An example :
352 # void glBitmap( GLsizei width, GLsizei height,
353 # GLfloat xorig, GLfloat yorig,
354 # GLfloat xmove, GLfloat ymove,
355 # const GLubyte *bitmap );
357 # Would give something like that :
359 # [ "glBitmap",
360 # "void",
361 # [ [ "GLsizei", "width" ],
362 # [ "GLsizei", "height" ],
363 # [ "GLfloat", "xorig" ],
364 # [ "GLfloat", "yorig" ],
365 # [ "GLfloat", "xmove" ],
366 # [ "GLfloat", "ymove" ],
367 # [ "GLubyte *", "bitmap"] ] ];
369 my %norm_functions = ();
372 # This stores various extensions NOT part of the GL extension registry but still
373 # implemented by most OpenGL libraries out there...
376 my %ext_functions =
377 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
378 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
379 [ "GLint", "x" ],
380 [ "GLint", "y" ],
381 [ "GLsizei", "width" ],
382 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
383 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
384 [ "GLint", "x" ],
385 [ "GLint", "y" ],
386 [ "GLsizei", "width" ],
387 [ "GLsizei", "height" ],
388 [ "GLint", "xDest" ],
389 [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
390 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled", "GL_KTX_buffer_region" ],
391 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
392 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
393 [ "GLfloat", "s" ],
394 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
395 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
396 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
397 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
398 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
399 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
400 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
401 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
402 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
403 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
404 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
405 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
406 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
407 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
408 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
409 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
410 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
411 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
412 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
413 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
414 [ "GLdouble", "s"],
415 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
416 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
417 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
418 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
419 [ "GLfloat", "s" ],
420 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
421 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
422 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
423 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
424 [ "GLint", "s" ],
425 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
426 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
427 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
428 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
429 [ "GLshort", "s" ],
430 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
431 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
432 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
433 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
434 [ "GLdouble", "s" ],
435 [ "GLdouble", "t" ],
436 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
437 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
438 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
439 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
440 [ "GLfloat", "s" ],
441 [ "GLfloat", "t" ],
442 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
443 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
444 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
445 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
446 [ "GLint", "s" ],
447 [ "GLint", "t" ],
448 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
449 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
450 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
451 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
452 [ "GLshort", "s" ],
453 [ "GLshort", "t" ],
454 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
455 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
456 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
457 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
458 [ "GLdouble", "s" ],
459 [ "GLdouble", "t" ],
460 [ "GLdouble", "r" ],
461 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
462 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
463 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
464 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
465 [ "GLfloat", "s" ],
466 [ "GLfloat", "t" ],
467 [ "GLfloat", "r" ],
468 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
469 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
470 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
471 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
472 [ "GLint", "s" ],
473 [ "GLint", "t" ],
474 [ "GLint", "r" ],
475 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
476 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
477 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
478 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
479 [ "GLshort", "s" ],
480 [ "GLshort", "t" ],
481 [ "GLshort", "r" ],
482 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
483 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
484 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
485 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
486 [ "GLint", "size" ],
487 [ "GLenum", "type" ],
488 [ "GLsizei", "stride" ],
489 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
490 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
491 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
492 "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
495 my @arg_names;
496 my %arg_types;
497 while (my $line = <REGISTRY>) {
498 if ($line =~ /^\w*\(.*\)/) {
499 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
500 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
501 # and the argument names
502 @arg_names = split /\s*,\s*/, $args;
504 # After get :
505 # - the return type
506 # - category (the extension the function is part of)
507 # - the argument types
508 # - the category the function belongs
509 %arg_types = ();
510 my $category = "";
511 my $ret_type = "";
512 while (1) {
513 $line = <REGISTRY>;
514 unless (defined($line)) {
515 last;
516 } elsif ($line =~ /^\s*$/) {
517 if (($category eq "") || ($ret_type eq "")) {
518 die "Missing 'category' line in function $funcname.\n";
520 last;
521 } elsif ($line =~ /\t*return\t*(\w*)/) {
522 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
523 $ret_type = $pseudo_to_opengl{$ret_type};
524 unless (defined($ret_type)) {
525 die "Unsupported return type in function $funcname\n";
527 } elsif ($line =~ /^\t*category/) {
528 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
529 } elsif ($line =~ /^\t*param/) {
530 my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
531 my $ptr = 0;
532 unless (defined($name)) {
533 chomp $line;
534 die "Broken spec file line $line in function $funcname\n";
537 if ($ext =~ /array/) {
538 # This is a pointer
539 $ptr = 1;
540 } elsif ($ext =~ /value/) {
541 # And this a 'normal' value
542 $ptr = 0;
543 } else {
544 chomp $line;
545 die "Unsupported type : $line in function $funcname\n";
547 # Get the 'real' type and append a '*' in case of a pointer
548 my $type = $pseudo_to_opengl{$base_type};
549 unless (defined($type)) {
550 chomp $line;
551 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
553 if ($ptr) {
554 $type = "$type*";
557 $arg_types{$name} = $type;
561 # Now, build the argument reference
562 my $arg_ref = [ ];
563 for (my $i = 0; $i <= $#arg_names; $i++) {
564 unless (defined($arg_types{$arg_names[$i]})) {
565 print "@arg_names\n";
566 foreach (sort keys %arg_types) {
567 print "$_ => $arg_types{$_}\n";
569 die "Undefined type for $arg_names[$i] in function $funcname\n";
572 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
574 my $func_ref = [ "gl$funcname",
575 $ret_type,
576 $arg_ref,
577 "gl$funcname",
578 "GL_$category" ];
580 # Now, put in one or the other hash table
581 if ($norm_categories{$category}) {
582 $norm_functions{"gl$funcname"} = $func_ref;
583 } else {
584 $ext_functions{"gl$funcname"} = $func_ref;
590 # Clean up the input files
592 close(TYPES);
593 close(REGISTRY);
596 # Now, generate the output files. First, the spec file.
598 open(SPEC, ">$spec_file");
600 foreach (sort keys %norm_functions) {
601 my $func_name = $norm_functions{$_}->[0];
602 print SPEC "@ stdcall $func_name( ";
603 for (my $i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
604 my $type = $norm_functions{$_}->[2]->[$i]->[0];
605 if ($type =~ /\*/) {
606 print SPEC "ptr ";
607 } elsif (defined($arg_conv{$type})) {
608 print SPEC "$@$arg_conv{$type}[0] ";
609 } else {
610 die "No conversion for GL type $type...\n";
613 print SPEC ") wine_$func_name\n";
616 print SPEC "@ stub glGetLevelParameterfv
617 @ stub glGetLevelParameteriv
618 @ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
619 @ stdcall wglCopyContext(long long long) gdi32.wglCopyContext
620 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
621 @ stdcall wglCreateLayerContext(long long)
622 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
623 @ stdcall wglDescribeLayerPlane(long long long long ptr)
624 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
625 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
626 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
627 @ stub wglGetDefaultProcAddress
628 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
629 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
630 @ stdcall wglGetProcAddress(str)
631 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
632 @ stdcall wglRealizeLayerPalette(long long long)
633 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
634 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
635 @ stdcall wglShareLists(long long) gdi32.wglShareLists
636 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
637 @ stdcall wglSwapLayerBuffers(long long)
638 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
639 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
640 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
641 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
644 close(SPEC);
647 # After the spec file, the opengl_norm.c file
649 open(NORM, ">$norm_file");
650 print NORM "
651 /* Auto-generated file... Do not edit ! */
653 #include \"config.h\"
654 #include \"opengl_ext.h\"
655 #include \"wine/debug.h\"
657 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
659 foreach (sort keys %norm_functions) {
660 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
662 print NORM "\n$string" if $string;
664 close(NORM);
667 # Finally, more complex, the opengl_ext.c file
669 open(EXT, ">$ext_file");
670 print EXT "
671 /* Auto-generated file... Do not edit ! */
673 #include \"config.h\"
674 #include \"opengl_ext.h\"
675 #include \"wine/debug.h\"
677 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
681 # The thunks themselves....
682 my $count = keys %ext_functions;
683 print EXT "const int extension_registry_size = $count;\n";
684 print EXT "void *extension_funcs[$count];\n";
685 print EXT "\n/* The thunks themselves....*/";
686 my $pos = 0;
687 foreach (sort keys %ext_functions) {
688 my $func_ref = $ext_functions{$_};
689 my $local_var = " " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
690 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
691 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
692 $local_var .= "$type";
693 if ($i != $#{@{$func_ref->[2]}}) {
694 $local_var .= ", ";
695 } else {
696 $local_var .= " ";
699 $local_var .= 'void ' if ($#{@{$func_ref->[2]}} < 0);
700 $local_var .= ") = extension_funcs[$pos];\n";
701 $pos++;
702 print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
705 # Then the table giving the string <-> function correspondence */
706 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
707 print EXT "const OpenGL_extension extension_registry[$count] = {\n";
708 my $i = 0;
709 foreach (sort keys %ext_functions) {
710 my $func_ref = $ext_functions{$_};
711 if ($func_ref->[0] eq $func_ref->[3])
713 print EXT " { \"$func_ref->[0]\", \"$func_ref->[4]\", (void *) wine_$func_ref->[0] }";
715 if ($i != $count-1) {
716 print EXT ",";
718 $i++;
719 print EXT "\n";
721 print EXT "};\n";
723 close(EXT);