Beginning of infrastructure to support WGL extensions.
[wine/multimedia.git] / dlls / opengl32 / make_opengl
blobf4b916598f64ae84b1e466b840830e544b4118d4
1 #!/usr/bin/perl -w
3 # This script is called thus :
5 # make_opengl path_to_spec_file opengl_version
7 # - path_to_spec_file is the path to the directory where the OpenGL
8 # spec files are located. These files are part of the OpenGL
9 # sample implementation CVS tree and are located in
10 # CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
11 # You can find them on the web at the following URL :
12 # http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
14 # - opengl_version is the OpenGL version emulated by the library
15 # (can be 1.0 to 1.2).
17 # This script generates the three following files :
19 # - opengl32.spec : the spec file giving all the exported functions
20 # of the OpenGL32.DLL library. These functions are the one an
21 # application can directly link to (and are all the functions
22 # defined in the OpenGL core for the version defined by
23 # 'opengl_version').
25 # - opengl_norm.c : this file contains the thunks for all OpenGL
26 # functions that are defined in 'opengl32.spec'. The corresponding
27 # functions NEED to be defined in Linux's libGL or the library
28 # won't be able to be linked in.
30 # - opengl_ext.c : in this file are stored thunks for ALL possible
31 # OpenGL extensions (at least, all the extensions that are defined
32 # in the OpenGL extension registry). Contrary to 'opengl_norm.c',
33 # you do not need to have these extensions in your libGL to have
34 # OpenGL work (as they are resolved at run-time using
35 # glXGetProcAddressARB).
37 # Copyright 2000 Lionel Ulmer
39 # This library is free software; you can redistribute it and/or
40 # modify it under the terms of the GNU Lesser General Public
41 # License as published by the Free Software Foundation; either
42 # version 2.1 of the License, or (at your option) any later version.
44 # This library is distributed in the hope that it will be useful,
45 # but WITHOUT ANY WARRANTY; without even the implied warranty of
46 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 # Lesser General Public License for more details.
49 # You should have received a copy of the GNU Lesser General Public
50 # License along with this library; if not, write to the Free Software
51 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
55 # Files to generate
57 $spec_file = "opengl32.spec";
58 $norm_file = "opengl_norm.c";
59 $ext_file = "opengl_ext.c";
61 # Set to 0 for removing the ENTER / LEAVE GL calls
62 $gen_thread_safe = 1;
63 # Prefix used for the local variables
64 $ext_prefix = "func_";
65 # If set to 1, generate TRACEs for each OpenGL function
66 $gen_traces = 1;
69 # List of categories to put in the 'opengl_norm.c' file
71 %cat_1_0 = ( "display-list" => 1,
72 "drawing" => 1,
73 "drawing-control" => 1,
74 "feedback" => 1,
75 "framebuf" => 1,
76 "misc" => 1,
77 "modeling" => 1,
78 "pixel-op" => 1,
79 "pixel-rw" => 1,
80 "state-req" => 1,
81 "xform" => 1 );
82 %cat_1_1 = ( %cat_1_0,
83 "1_1" => 1 );
84 %cat_1_2 = ( %cat_1_1,
85 "VERSION_1_2" => 1 );
87 %norm_categories = ();
90 # This hash table gives the conversion between OpenGL types and what
91 # is used by the TRACE printfs
93 %debug_conv =
94 ("GLbitfield" => "%d",
95 "GLboolean" => "%d",
96 "GLbyte" => "%d",
97 "GLclampd" => "%f",
98 "GLclampf" => "%f",
99 "GLdouble" => "%f",
100 "GLenum" => "%d",
101 "GLfloat" => "%f",
102 "GLint" => "%d",
103 "GLshort" => "%d",
104 "GLsizei" => "%d",
105 "GLstring" => "%s",
106 "GLubyte" => "%d",
107 "GLuint" => "%d",
108 "GLushort" => "%d",
109 "GLhalfNV" => "%d",
110 "GLintptrARB" => "%d",
111 "GLsizeiptrARB" => "%d",
112 "GLvoid" => "(void)",
113 "_GLfuncptr" => "%p");
116 # This hash table gives the conversion between OpenGL types and what
117 # is used in the .spec file
119 %arg_conv =
120 ("GLbitfield" => [ "long", 4 ],
121 "GLboolean" => [ "long", 4 ],
122 "GLbyte" => [ "long", 4 ],
123 "GLclampd" => [ "double", 8 ],
124 "GLclampf" => [ "long", 4 ],
125 "GLdouble" => [ "double", 8 ],
126 "GLenum" => [ "long", 4 ],
127 "GLfloat" => [ "long", 4 ],
128 "GLint" => [ "long", 4 ],
129 "GLshort" => [ "long", 4 ],
130 "GLsizei" => [ "long", 4 ],
131 "GLstring" => [ "str", 4 ],
132 "GLubyte" => [ "long", 4 ],
133 "GLuint" => [ "long", 4 ],
134 "GLushort" => [ "long", 4 ],
135 "GLhalfNV" => [ "long", 4 ],
136 "GLintptrARB" => [ "long", 4 ],
137 "GLsizeiptrARB" => [ "long", 4 ],
138 "GLvoid" => [ "void", 4 ],
139 "_GLfuncptr" => [ "ptr", 4 ]);
142 # Used to convert some types
144 sub ConvertType {
145 my ($type) = @_;
147 %hash = ( "GLstring" => "const GLubyte *",
148 "GLintptrARB" => "ptrdiff_t",
149 "GLsizeiptrARB" => "ptrdiff_t",
150 "GLhalfNV" => "unsigned short" );
152 foreach $org (keys %hash) {
153 if ($type =~ /$org/) {
154 ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
155 return "$before$hash{$org}$after";
158 return $type;
162 # This functions generates the thunk for a given function.
164 sub GenerateThunk {
165 my ($func_ref, $comment, $prefix, $thread_safe) = @_;
166 my ($ret) = ("");
167 my ($call_arg) = ("");
168 my ($trace_arg) = ("");
170 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
171 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
172 if ($comment eq 1) {
173 $ret = $ret . "/***********************************************************************\n";
174 $ret = $ret . " * " . $func_ref->[0] . " (OPENGL32.@)\n";
175 $ret = $ret . " */\n";
177 $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_" . $func_ref->[0] . "( ";
178 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
179 $type = $func_ref->[2]->[$i]->[0];
180 $name = $func_ref->[2]->[$i]->[1];
181 $ret = $ret . ConvertType($type) . " $name";
182 $call_arg = $call_arg . "$name";
183 if ($type =~ /\*/) {
184 $trace_arg = $trace_arg . "%p";
185 } else {
186 $trace_arg = $trace_arg . $debug_conv{$type};
188 if ($i != $#{@{$func_ref->[2]}}) {
189 $ret = $ret . ", ";
190 $call_arg = $call_arg . ", ";
191 $trace_arg = $trace_arg . ", ";
192 } else {
193 $ret = $ret . " ";
194 $call_arg = $call_arg . " ";
197 $ret = $ret . ") {\n";
198 if ($func_ref->[1] ne "void") {
199 $ret = $ret . " " . ConvertType($func_ref->[1]) . " ret_value;\n";
201 if ($gen_traces) {
202 $ret = $ret . " TRACE(\"(" . $trace_arg . ")\\n\"";
203 if ($trace_arg ne "") {
204 $ret = $ret . ", " . $call_arg;
206 $ret = $ret . ");\n";
208 if ($thread_safe) {
209 $ret = $ret . " ENTER_GL();\n";
211 $ret = $ret . " ";
212 if ($func_ref->[1] ne "void") {
213 $ret = $ret . "ret_value = ";
215 $ret = $ret . $prefix . $func_ref->[0] . "( " . $call_arg . ");\n";
216 if ($thread_safe) {
217 $ret = $ret . " LEAVE_GL();\n";
219 if ($func_ref->[1] ne "void") {
220 $ret = $ret . " return ret_value;\n"
222 $ret = $ret . "}\n";
224 # Return this string....
225 $ret;
229 # Extract and checks the number of arguments
231 if ($#ARGV != 1) {
232 die "Usage : make_opengl OpenGL_registry_location OpenGL_version.\n";
234 $registry_path = shift @ARGV;
235 $version = shift @ARGV;
236 if ($version eq "1.0") {
237 %norm_categories = %cat_1_0;
238 } elsif ($version eq "1.1") {
239 %norm_categories = %cat_1_1;
240 } elsif ($version eq "1.2") {
241 %norm_categories = %cat_1_2;
242 } else {
243 die "OpenGL version incorrect. Should be one of '1.0', '1.1' or '1.2'.\n";
247 # Open the registry files
249 open(TYPES, $registry_path . "/gl.tm") || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
250 open(REGISTRY, $registry_path . "/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
253 # First, create a mapping between the pseudo types used in the spec file
254 # and OpenGL types using the 'gl.tm' file.
256 %pseudo_to_opengl = ();
257 while ($line = <TYPES>) {
258 if ($line !~ /\w*\#/) {
259 ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
260 $pseudo_to_opengl{$pseudo} = $opengl;
263 # This is to override the 'void' -> '*' bogus conversion
264 $pseudo_to_opengl{"void"} = "void";
265 # This is a bug in the spec file...
266 $pseudo_to_opengl{"FfdTargetSGIX"} = "GLint";
267 $pseudo_to_opengl{"FfdMaskSGIX"} = "GLint";
268 $pseudo_to_opengl{"IglooFunctionSelectSGIX"} = "GLint";
269 $pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
272 # Then, create the list of all OpenGL functions using the 'gl.spec'
273 # file. This will create two hash-tables, one with all the function
274 # whose category matches the one listed in '@norm_categories', the other
275 # with all other functions.
277 # An element of the hash table is a reference to an array with these
278 # elements :
280 # - function name
282 # - return type
284 # - reference to an array giving the list of arguments (an empty array
285 # for a 'void' function).
287 # The list of arguments is itself an array of reference to arrays. Each
288 # of these arrays represents the argument type and the argument name.
290 # An example :
292 # void glBitmap( GLsizei width, GLsizei height,
293 # GLfloat xorig, GLfloat yorig,
294 # GLfloat xmove, GLfloat ymove,
295 # const GLubyte *bitmap );
297 # Would give something like that :
299 # [ "glBitmap",
300 # "void",
301 # [ [ "GLsizei", "width" ],
302 # [ "GLsizei", "height" ],
303 # [ "GLfloat", "xorig" ],
304 # [ "GLfloat", "yorig" ],
305 # [ "GLfloat", "xmove" ],
306 # [ "GLfloat", "ymove" ],
307 # [ "GLubyte *", "bitmap"] ] ];
309 %norm_functions = ();
312 # This stores various extensions NOT part of the GL extension registry but still
313 # implemented by most OpenGL libraries out there...
315 %ext_functions =
316 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion" ],
317 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
318 [ "GLint", "x" ],
319 [ "GLint", "y" ],
320 [ "GLsizei", "width" ],
321 [ "GLsizei", "height" ] ], "glReadBufferRegion" ],
322 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
323 [ "GLint", "x" ],
324 [ "GLint", "y" ],
325 [ "GLsizei", "width" ],
326 [ "GLsizei", "height" ],
327 [ "GLint", "xDest" ],
328 [ "GLint", "yDest" ] ], "glDrawBufferRegion" ],
329 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled" ],
330 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion" ],
331 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
332 [ "GLfloat", "s" ],
333 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS" ],
334 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
335 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS" ],
336 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
337 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS" ],
338 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
339 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
340 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
341 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
342 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
343 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
344 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
345 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
346 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
347 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
348 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
349 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
350 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
351 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
352 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
353 [ "GLdouble", "s"],
354 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
355 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
356 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
357 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
358 [ "GLfloat", "s" ],
359 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
360 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
361 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
362 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
363 [ "GLint", "s" ],
364 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
365 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
366 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
367 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
368 [ "GLshort", "s" ],
369 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
370 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
371 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
372 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
373 [ "GLdouble", "s" ],
374 [ "GLdouble", "t" ],
375 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
376 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
377 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
378 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
379 [ "GLfloat", "s" ],
380 [ "GLfloat", "t" ],
381 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
382 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
383 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
384 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
385 [ "GLint", "s" ],
386 [ "GLint", "t" ],
387 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
388 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
389 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
390 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
391 [ "GLshort", "s" ],
392 [ "GLshort", "t" ],
393 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
394 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
395 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
396 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
397 [ "GLdouble", "s" ],
398 [ "GLdouble", "t" ],
399 [ "GLdouble", "r" ],
400 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
401 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
402 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
403 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
404 [ "GLfloat", "s" ],
405 [ "GLfloat", "t" ],
406 [ "GLfloat", "r" ],
407 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
408 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
409 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
410 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
411 [ "GLint", "s" ],
412 [ "GLint", "t" ],
413 [ "GLint", "r" ],
414 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
415 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
416 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
417 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
418 [ "GLshort", "s" ],
419 [ "GLshort", "t" ],
420 [ "GLshort", "r" ],
421 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
422 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
423 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
424 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
425 [ "GLint", "size" ],
426 [ "GLenum", "type" ],
427 [ "GLsizei", "stride" ],
428 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
429 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
430 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
431 "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
432 [ "GLfloat", "readfreq" ],
433 [ "GLfloat", "writefreq"],
434 [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
435 "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ]
439 while ($line = <REGISTRY>) {
440 if ($line =~ /^\w*\(.*\)/) {
441 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
442 ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
443 # and the argument names
444 @arg_names = split /\s*,\s*/, $args;
446 # After get :
447 # - the return type
448 # - the argument types
449 # - the category the function belongs
450 %arg_types = ();
451 $category = "";
452 $ret_type = "";
453 while (1) {
454 $line = <REGISTRY>;
455 unless (defined($line)) {
456 last;
457 } elsif ($line =~ /^\s*$/) {
458 if (($category eq "") || ($ret_type eq "")) {
459 die "Missing 'category' line in function $funcname.\n";
461 last;
462 } elsif ($line =~ /\t*return\t*(\w*)/) {
463 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
464 $ret_type = $pseudo_to_opengl{$ret_type};
465 unless (defined($ret_type)) {
466 die "Unsupported return type in function $funcname\n";
468 } elsif ($line =~ /^\t*category/) {
469 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
470 } elsif ($line =~ /^\t*param/) {
471 ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
472 $ptr = 0;
473 unless (defined($name)) {
474 chomp $line;
475 die "Broken spec file line $line in function $funcname\n";
478 if ($ext =~ /array/) {
479 # This is a pointer
480 $ptr = 1;
481 } elsif ($ext =~ /value/) {
482 # And this a 'normal' value
483 $ptr = 0;
484 } else {
485 chomp $line;
486 die "Unsupported type : $line in function $funcname\n";
488 # Get the 'real' type and append a '*' in case of a pointer
489 $type = $pseudo_to_opengl{$base_type};
490 unless (defined($type)) {
491 chomp $line;
492 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
494 if ($ptr) {
495 $type = $type . "*";
498 $arg_types{$name} = $type;
502 # Now, build the argument reference
503 $arg_ref = [ ];
504 for ($i = 0; $i <= $#arg_names; $i++) {
505 unless (defined($arg_types{$arg_names[$i]})) {
506 print "@arg_names\n";
507 foreach (sort keys %arg_types) {
508 print "$_ => $arg_types{$_}\n";
510 die "Undefined type for $arg_names[$i] in function $funcname\n";
513 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
515 $func_ref = [ "gl" . $funcname,
516 $ret_type,
517 $arg_ref,
518 "gl" . $funcname ];
520 # Now, put in one or the other hash table
521 if ($norm_categories{$category}) {
522 $norm_functions{"gl" . $funcname} = $func_ref;
523 } else {
524 $ext_functions{"gl" . $funcname} = $func_ref;
530 # Clean up the input files
532 close(TYPES);
533 close(REGISTRY);
536 # Now, generate the output files. First, the spec file.
538 open(SPEC, ">" . $spec_file);
540 print SPEC "@ stdcall wglCreateContext(long)
541 @ stdcall wglCreateLayerContext(long long)
542 @ stdcall wglCopyContext(long long long)
543 @ stdcall wglDeleteContext(long)
544 @ stdcall wglDescribeLayerPlane(long long long long ptr)
545 @ stdcall wglGetCurrentContext()
546 @ stdcall wglGetCurrentDC()
547 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
548 @ stdcall wglGetProcAddress(str)
549 @ stdcall wglMakeCurrent(long long)
550 @ stdcall wglRealizeLayerPalette(long long long)
551 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
552 @ stdcall wglShareLists(long long)
553 @ stdcall wglSwapLayerBuffers(long long)
554 @ stdcall wglUseFontBitmapsA(long long long long)
555 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
556 @ stub glGetLevelParameterfv
557 @ stub glGetLevelParameteriv
558 @ stdcall wglUseFontBitmapsW(long long long long)
559 @ stub wglUseFontOutlinesW
560 @ stub wglGetDefaultProcAddress
561 @ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
562 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
563 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
564 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
565 @ stdcall wglSwapBuffers(long) gdi32.SwapBuffers
568 foreach (sort keys %norm_functions) {
569 $func_name = $norm_functions{$_}->[0];
570 print SPEC "@ stdcall $func_name( ";
571 for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
572 $type = $norm_functions{$_}->[2]->[$i]->[0];
573 if ($type =~ /\*/) {
574 print SPEC "ptr ";
575 } elsif (defined($arg_conv{$type})) {
576 print SPEC "$@$arg_conv{$type}[0] ";
577 } else {
578 die "No convertion for GL type $type...\n";
581 print SPEC ") wine_$func_name\n";
583 close(SPEC);
586 # After the spec file, the opengl_norm.c file
588 open(NORM, ">" . $norm_file);
589 print NORM "
590 /* Auto-generated file... Do not edit ! */
592 #include \"config.h\"
593 #include \"opengl_ext.h\"
594 #include \"wine/debug.h\"
596 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
598 foreach (sort keys %norm_functions) {
599 $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
601 print NORM "\n$string";
603 close(NORM);
606 # Finally, more complex, the opengl_ext.c file
608 open(EXT, ">" . $ext_file);
609 print EXT "
610 /* Auto-generated file... Do not edit ! */
612 #include \"config.h\"
613 #include \"opengl_ext.h\"
614 #include \"wine/debug.h\"
616 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
620 # First, generate the function pointers
621 foreach (sort keys %ext_functions) {
622 $func_ref = $ext_functions{$_};
623 print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
624 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
625 $type = ConvertType($func_ref->[2]->[$i]->[0]);
626 print EXT "$type";
627 if ($i != $#{@{$func_ref->[2]}}) {
628 print EXT ", ";
629 } else {
630 print EXT " ";
633 print EXT ") = (void *) 0xdeadbeef;\n";
636 # Then, the function prototypes
637 print EXT "\n\n/* The function prototypes */\n";
638 foreach (sort keys %ext_functions) {
639 $func_ref = $ext_functions{$_};
640 print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
641 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
642 $type = ConvertType($func_ref->[2]->[$i]->[0]);
643 print EXT "$type";
644 if ($i != $#{@{$func_ref->[2]}}) {
645 print EXT ", ";
646 } else {
647 print EXT " ";
650 print EXT ");\n";
653 # Then the table giving the string <-> function correspondance */
654 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
655 @tmp = keys %ext_functions;
656 print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
657 print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
658 $i = 0;
659 foreach (sort keys %ext_functions) {
660 $func_ref = $ext_functions{$_};
661 print EXT " { \"" . $func_ref->[0] . "\", \"" . $func_ref->[3] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
662 if ($i != $#tmp) {
663 print EXT ",";
665 $i++;
666 print EXT "\n";
668 print EXT "};\n";
670 # And, finally, the thunks themselves....
671 print EXT "\n/* The thunks themselves....*/";
672 foreach (sort keys %ext_functions) {
673 $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
675 print EXT "\n$string";
677 close(EXT);