Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / opengl32 / make_opengl
blobc6383006e35949a5cf2ffe072bacbaa74208dfb9
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 part of the OpenGL
10 # sample implementation CVS tree and are located in
11 # CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
12 # You can find them on the web at the following URL :
13 # http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
14 # You will need gl.tm and gl.spec.
16 # - opengl_version is the OpenGL version emulated by the library
17 # (can be 1.0 to 1.5).
19 # This script generates the three following files :
21 # - opengl32.spec : the spec file giving all the exported functions
22 # of the OpenGL32.DLL library. These functions are the one an
23 # application can directly link to (and are all the functions
24 # defined in the OpenGL core for the version defined by
25 # 'opengl_version').
27 # - opengl_norm.c : this file contains the thunks for all OpenGL
28 # functions that are defined in 'opengl32.spec'. The corresponding
29 # functions NEED to be defined in Linux's libGL or the library
30 # won't be able to be linked in.
32 # - opengl_ext.c : in this file are stored thunks for ALL possible
33 # OpenGL extensions (at least, all the extensions that are defined
34 # in the OpenGL extension registry). Contrary to 'opengl_norm.c',
35 # you do not need to have these extensions in your libGL to have
36 # OpenGL work (as they are resolved at run-time using
37 # glXGetProcAddressARB).
39 # Copyright 2000 Lionel Ulmer
41 # This library is free software; you can redistribute it and/or
42 # modify it under the terms of the GNU Lesser General Public
43 # License as published by the Free Software Foundation; either
44 # version 2.1 of the License, or (at your option) any later version.
46 # This library is distributed in the hope that it will be useful,
47 # but WITHOUT ANY WARRANTY; without even the implied warranty of
48 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
49 # Lesser General Public License for more details.
51 # You should have received a copy of the GNU Lesser General Public
52 # License along with this library; if not, write to the Free Software
53 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
57 # Files to generate
59 my $spec_file = "opengl32.spec";
60 my $norm_file = "opengl_norm.c";
61 my $ext_file = "opengl_ext.c";
63 # Set to 0 for removing the ENTER / LEAVE GL calls
64 my $gen_thread_safe = 1;
65 # Prefix used for the local variables
66 my $ext_prefix = "func_";
67 # If set to 1, generate TRACEs for each OpenGL function
68 my $gen_traces = 1;
71 # List of categories to put in the 'opengl_norm.c' file
73 my %cat_1_0 = ( "display-list" => 1,
74 "drawing" => 1,
75 "drawing-control" => 1,
76 "feedback" => 1,
77 "framebuf" => 1,
78 "misc" => 1,
79 "modeling" => 1,
80 "pixel-op" => 1,
81 "pixel-rw" => 1,
82 "state-req" => 1,
83 "xform" => 1 );
84 my %cat_1_1 = ( %cat_1_0,
85 "1_1" => 1 );
86 my %cat_1_2 = ( %cat_1_1,
87 "VERSION_1_2" => 1 );
88 my %cat_1_3 = ( %cat_1_2,
89 "VERSION_1_3" => 1 );
90 my %cat_1_4 = ( %cat_1_3,
91 "VERSION_1_4" => 1 );
92 my %cat_1_5 = ( %cat_1_4,
93 "VERSION_1_5" => 1 );
95 my %norm_categories = ();
98 # This hash table gives the conversion between OpenGL types and what
99 # is used by the TRACE printfs
101 my %debug_conv =
102 ("GLbitfield" => "%d",
103 "GLboolean" => "%d",
104 "GLbyte" => "%d",
105 "GLclampd" => "%f",
106 "GLclampf" => "%f",
107 "GLdouble" => "%f",
108 "GLenum" => "%d",
109 "GLfloat" => "%f",
110 "GLint" => "%d",
111 "GLshort" => "%d",
112 "GLsizei" => "%d",
113 "GLstring" => "%s",
114 "GLubyte" => "%d",
115 "GLuint" => "%d",
116 "GLushort" => "%d",
117 "GLhalfNV" => "%d",
118 "GLintptrARB" => "%d",
119 "GLsizeiptrARB" => "%d",
120 "GLintptr" => "%d",
121 "GLsizeiptr" => "%d",
122 "GLhandleARB" => "%d",
123 "GLcharARB" => "%c",
124 "GLvoid" => "(void)",
125 "_GLfuncptr" => "%p");
128 # This hash table gives the conversion between OpenGL types and what
129 # is used in the .spec file
131 my %arg_conv =
132 ("GLbitfield" => [ "long", 4 ],
133 "GLboolean" => [ "long", 4 ],
134 "GLbyte" => [ "long", 4 ],
135 "GLclampd" => [ "double", 8 ],
136 "GLclampf" => [ "long", 4 ],
137 "GLdouble" => [ "double", 8 ],
138 "GLenum" => [ "long", 4 ],
139 "GLfloat" => [ "long", 4 ],
140 "GLint" => [ "long", 4 ],
141 "GLshort" => [ "long", 4 ],
142 "GLsizei" => [ "long", 4 ],
143 "GLstring" => [ "str", 4 ],
144 "GLubyte" => [ "long", 4 ],
145 "GLuint" => [ "long", 4 ],
146 "GLushort" => [ "long", 4 ],
147 "GLhalfNV" => [ "long", 4 ],
148 "GLintptrARB" => [ "long", 4 ],
149 "GLsizeiptrARB" => [ "long", 4 ],
150 "GLhandleARB" => [ "long", 4 ],
151 "GLcharARB" => [ "long", 4 ],
152 "GLintptr" => [ "long", 4 ],
153 "GLsizeiptr" => [ "long", 4 ],
154 "GLvoid" => [ "void", 4 ],
155 "_GLfuncptr" => [ "ptr", 4 ]);
158 # Used to convert some types
160 sub ConvertType($)
162 my ($type) = @_;
164 my %hash = ( "GLstring" => "const GLubyte *",
165 "GLintptrARB" => "ptrdiff_t",
166 "GLsizeiptrARB" => "ptrdiff_t",
167 "GLintptr" => "ptrdiff_t",
168 "GLsizeiptr" => "ptrdiff_t",
169 "GLhandleARB" => "unsigned int",
170 "GLcharARB" => "char",
171 "GLhalfNV" => "unsigned short" );
173 foreach my $org (reverse sort keys %hash) {
174 if ($type =~ /$org/) {
175 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
176 return "$before$hash{$org}$after";
179 return $type;
183 # Used to convert some variable names
185 sub ConvertVarName($)
187 my ($type) = @_;
189 my %hash = ( "near" => "nearParam",
190 "far" => "farParam" );
192 foreach my $org (keys %hash) {
193 if ($type =~ /$org/) {
194 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
195 return "$before$hash{$org}$after";
198 return $type;
202 # This functions generates the thunk for a given function.
204 sub GenerateThunk($$$$)
206 my ($func_ref, $comment, $prefix, $thread_safe) = @_;
207 my $ret = "";
208 my $call_arg = "";
209 my $trace_arg = "";
210 my $wine_func_ref_name = "";
212 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
213 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
214 if ($comment eq 1) {
215 $ret = "$ret/***********************************************************************\n";
216 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
217 $ret = "$ret */\n";
219 $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
220 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
221 ## Quick debug code :-)
222 ## print $func_ref->[2]->[$i]->[1] . "\n";
223 my $type = $func_ref->[2]->[$i]->[0];
224 my $name = ConvertVarName($func_ref->[2]->[$i]->[1]);
225 $ret = $ret . ConvertType($type) . " $name";
226 $call_arg = "$call_arg$name";
227 if ($type =~ /\*/) {
228 $trace_arg = "$trace_arg\%p";
229 } else {
230 $trace_arg = "$trace_arg$debug_conv{$type}";
232 if ($i != $#{@{$func_ref->[2]}}) {
233 $ret = "$ret, ";
234 $call_arg = "$call_arg, ";
235 $trace_arg = "$trace_arg, ";
236 } else {
237 $ret = "$ret ";
238 $call_arg = "$call_arg ";
241 $ret = "$ret) {\n";
242 if ($func_ref->[1] ne "void") {
243 $ret = "$ret " . ConvertType($func_ref->[1]) . " ret_value;\n";
245 if ($gen_traces) {
246 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
247 if ($trace_arg ne "") {
248 $ret = "$ret, $call_arg";
250 $ret = "$ret);\n";
252 if ($thread_safe) {
253 $ret = "$ret ENTER_GL();\n";
255 $ret = "$ret ";
256 if ($func_ref->[1] ne "void") {
257 $ret = $ret . "ret_value = ";
259 $wine_func_ref_name = $func_ref->[0];
260 if ( $func_ref->[0] eq "glGetString" ) {
261 $wine_func_ref_name = "internal_glGetString";
263 $ret = "$ret$prefix$wine_func_ref_name( $call_arg);\n";
264 if ($thread_safe) {
265 $ret = "$ret LEAVE_GL();\n";
267 if ($func_ref->[1] ne "void") {
268 $ret = "$ret return ret_value;\n"
270 $ret = "$ret}\n";
272 # Return this string....
273 return $ret;
277 # Extract and checks the number of arguments
279 if (@ARGV != 2) {
280 my $name0=$0;
281 $name0=~s%^.*/%%;
282 die "Usage: $name0 OpenGL_registry_location OpenGL_version\n";
284 my $registry_path = shift @ARGV;
285 my $version = shift @ARGV;
286 if ($version eq "1.0") {
287 %norm_categories = %cat_1_0;
288 } elsif ($version eq "1.1") {
289 %norm_categories = %cat_1_1;
290 } elsif ($version eq "1.2") {
291 %norm_categories = %cat_1_2;
292 } elsif ($version eq "1.3") {
293 %norm_categories = %cat_1_3;
294 } elsif ($version eq "1.4") {
295 %norm_categories = %cat_1_4;
296 } elsif ($version eq "1.5") {
297 %norm_categories = %cat_1_5;
298 } else {
299 die "Incorrect OpenGL version.\n";
303 # Open the registry files
305 open(TYPES, "$registry_path/gl.tm") || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
306 open(REGISTRY, "$registry_path/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
309 # First, create a mapping between the pseudo types used in the spec file
310 # and OpenGL types using the 'gl.tm' file.
312 my %pseudo_to_opengl = ();
313 while (my $line = <TYPES>) {
314 if ($line !~ /\w*\#/) {
315 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
316 $pseudo_to_opengl{$pseudo} = $opengl;
319 # This is to override the 'void' -> '*' bogus conversion
320 $pseudo_to_opengl{"void"} = "void";
321 # This is a bug in the spec file...
322 $pseudo_to_opengl{"FfdTargetSGIX"} = "GLint";
323 $pseudo_to_opengl{"FfdMaskSGIX"} = "GLint";
324 $pseudo_to_opengl{"IglooFunctionSelectSGIX"} = "GLint";
325 $pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
328 # Then, create the list of all OpenGL functions using the 'gl.spec'
329 # file. This will create two hash-tables, one with all the function
330 # whose category matches the one listed in '@norm_categories', the other
331 # with all other functions.
333 # An element of the hash table is a reference to an array with these
334 # elements :
336 # - function name
338 # - return type
340 # - reference to an array giving the list of arguments (an empty array
341 # for a 'void' function).
343 # The list of arguments is itself an array of reference to arrays. Each
344 # of these arrays represents the argument type and the argument name.
346 # An example :
348 # void glBitmap( GLsizei width, GLsizei height,
349 # GLfloat xorig, GLfloat yorig,
350 # GLfloat xmove, GLfloat ymove,
351 # const GLubyte *bitmap );
353 # Would give something like that :
355 # [ "glBitmap",
356 # "void",
357 # [ [ "GLsizei", "width" ],
358 # [ "GLsizei", "height" ],
359 # [ "GLfloat", "xorig" ],
360 # [ "GLfloat", "yorig" ],
361 # [ "GLfloat", "xmove" ],
362 # [ "GLfloat", "ymove" ],
363 # [ "GLubyte *", "bitmap"] ] ];
365 my %norm_functions = ();
368 # This stores various extensions NOT part of the GL extension registry but still
369 # implemented by most OpenGL libraries out there...
372 my %ext_functions =
373 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion" ],
374 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
375 [ "GLint", "x" ],
376 [ "GLint", "y" ],
377 [ "GLsizei", "width" ],
378 [ "GLsizei", "height" ] ], "glReadBufferRegion" ],
379 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
380 [ "GLint", "x" ],
381 [ "GLint", "y" ],
382 [ "GLsizei", "width" ],
383 [ "GLsizei", "height" ],
384 [ "GLint", "xDest" ],
385 [ "GLint", "yDest" ] ], "glDrawBufferRegion" ],
386 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled" ],
387 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion" ],
388 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
389 [ "GLfloat", "s" ],
390 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS" ],
391 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
392 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS" ],
393 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
394 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS" ],
395 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
396 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
397 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
398 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
399 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
400 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
401 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
402 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
403 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
404 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
405 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
406 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
407 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
408 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
409 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
410 [ "GLdouble", "s"],
411 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
412 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
413 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
414 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
415 [ "GLfloat", "s" ],
416 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
417 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
418 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
419 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
420 [ "GLint", "s" ],
421 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
422 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
423 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
424 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
425 [ "GLshort", "s" ],
426 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
427 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
428 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
429 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
430 [ "GLdouble", "s" ],
431 [ "GLdouble", "t" ],
432 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
433 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
434 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
435 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
436 [ "GLfloat", "s" ],
437 [ "GLfloat", "t" ],
438 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
439 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
440 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
441 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
442 [ "GLint", "s" ],
443 [ "GLint", "t" ],
444 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
445 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
446 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
447 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
448 [ "GLshort", "s" ],
449 [ "GLshort", "t" ],
450 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
451 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
452 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
453 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
454 [ "GLdouble", "s" ],
455 [ "GLdouble", "t" ],
456 [ "GLdouble", "r" ],
457 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
458 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
459 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
460 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
461 [ "GLfloat", "s" ],
462 [ "GLfloat", "t" ],
463 [ "GLfloat", "r" ],
464 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
465 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
466 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
467 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
468 [ "GLint", "s" ],
469 [ "GLint", "t" ],
470 [ "GLint", "r" ],
471 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
472 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
473 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
474 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
475 [ "GLshort", "s" ],
476 [ "GLshort", "t" ],
477 [ "GLshort", "r" ],
478 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
479 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
480 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
481 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
482 [ "GLint", "size" ],
483 [ "GLenum", "type" ],
484 [ "GLsizei", "stride" ],
485 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
486 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
487 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
488 "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
489 [ "GLfloat", "readfreq" ],
490 [ "GLfloat", "writefreq"],
491 [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
492 "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ],
493 "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI" ]
496 my @arg_names;
497 my %arg_types;
498 while (my $line = <REGISTRY>) {
499 if ($line =~ /^\w*\(.*\)/) {
500 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
501 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
502 # and the argument names
503 @arg_names = split /\s*,\s*/, $args;
505 # After get :
506 # - the return type
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" ];
579 # Now, put in one or the other hash table
580 if ($norm_categories{$category}) {
581 $norm_functions{"gl$funcname"} = $func_ref;
582 } else {
583 $ext_functions{"gl$funcname"} = $func_ref;
589 # Clean up the input files
591 close(TYPES);
592 close(REGISTRY);
595 # Now, generate the output files. First, the spec file.
597 open(SPEC, ">$spec_file");
599 print SPEC "@ stdcall wglCreateContext(long)
600 @ stdcall wglCreateLayerContext(long long)
601 @ stdcall wglCopyContext(long long long)
602 @ stdcall wglDeleteContext(long)
603 @ stdcall wglDescribeLayerPlane(long long long long ptr)
604 @ stdcall wglGetCurrentContext()
605 @ stdcall wglGetCurrentDC()
606 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
607 @ stdcall wglGetProcAddress(str)
608 @ stdcall wglMakeCurrent(long long)
609 @ stdcall wglRealizeLayerPalette(long long long)
610 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
611 @ stdcall wglShareLists(long long)
612 @ stdcall wglSwapLayerBuffers(long long)
613 @ stdcall wglUseFontBitmapsA(long long long long)
614 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
615 @ stub glGetLevelParameterfv
616 @ stub glGetLevelParameteriv
617 @ stdcall wglUseFontBitmapsW(long long long long)
618 @ stub wglUseFontOutlinesW
619 @ stub wglGetDefaultProcAddress
620 @ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
621 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
622 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
623 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
624 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
627 foreach (sort keys %norm_functions) {
628 my $func_name = $norm_functions{$_}->[0];
629 print SPEC "@ stdcall $func_name( ";
630 for (my $i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
631 my $type = $norm_functions{$_}->[2]->[$i]->[0];
632 if ($type =~ /\*/) {
633 print SPEC "ptr ";
634 } elsif (defined($arg_conv{$type})) {
635 print SPEC "$@$arg_conv{$type}[0] ";
636 } else {
637 die "No convertion for GL type $type...\n";
640 print SPEC ") wine_$func_name\n";
642 close(SPEC);
645 # After the spec file, the opengl_norm.c file
647 open(NORM, ">$norm_file");
648 print NORM "
649 /* Auto-generated file... Do not edit ! */
651 #include \"config.h\"
652 #include \"opengl_ext.h\"
653 #include \"wine/debug.h\"
655 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
657 foreach (sort keys %norm_functions) {
658 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
660 print NORM "\n$string";
662 close(NORM);
665 # Finally, more complex, the opengl_ext.c file
667 open(EXT, ">$ext_file");
668 print EXT "
669 /* Auto-generated file... Do not edit ! */
671 #include \"config.h\"
672 #include \"opengl_ext.h\"
673 #include \"wine/debug.h\"
675 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
679 # First, generate the function pointers
680 foreach (sort keys %ext_functions) {
681 my $func_ref = $ext_functions{$_};
682 print EXT ConvertType($func_ref->[1]), " (*$ext_prefix$func_ref->[0])( ";
683 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
684 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
685 print EXT "$type";
686 if ($i != $#{@{$func_ref->[2]}}) {
687 print EXT ", ";
688 } else {
689 print EXT " ";
692 print EXT ") = (void *) 0xdeadbeef;\n";
695 # Then, the function prototypes
696 print EXT "\n\n/* The function prototypes */\n";
697 foreach (sort keys %ext_functions) {
698 my $func_ref = $ext_functions{$_};
699 print EXT ConvertType($func_ref->[1]), " WINAPI wine_$func_ref->[0]( ";
700 for (my $i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
701 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
702 print EXT "$type";
703 if ($i != $#{@{$func_ref->[2]}}) {
704 print EXT ", ";
705 } else {
706 print EXT " ";
709 print EXT ");\n";
712 # Then the table giving the string <-> function correspondance */
713 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
714 my @tmp = keys %ext_functions;
715 print EXT "int extension_registry_size = ", ($#tmp + 1), ";\n";
716 print EXT "OpenGL_extension extension_registry[", ($#tmp + 1), "] = {\n";
717 my $i = 0;
718 foreach (sort keys %ext_functions) {
719 my $func_ref = $ext_functions{$_};
720 print EXT " { \"$func_ref->[0]\", \"$func_ref->[3]\", (void *) wine_$func_ref->[0], (void **) (&$ext_prefix$func_ref->[0]) }";
721 if ($i != $#tmp) {
722 print EXT ",";
724 $i++;
725 print EXT "\n";
727 print EXT "};\n";
729 # And, finally, the thunks themselves....
730 print EXT "\n/* The thunks themselves....*/";
731 foreach (sort keys %ext_functions) {
732 my $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
734 print EXT "\n$string";
736 close(EXT);