d3dcompiler: Use an iface instead of a vtbl pointer in d3dcompiler_blob.
[wine/multimedia.git] / dlls / opengl32 / make_opengl
blobb30369540348d0d4964002c62a1aa46158ec647a
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 "GLDEBUGPROCARB" => "%p",
142 "GLDEBUGPROCAMD" => "%p",
143 "GLvdpauSurfaceNV" => "%ld",
144 "INT64" => "%s,wine_dbgstr_longlong(%s)",
145 "UINT64" => "%s,wine_dbgstr_longlong(%s)"
149 # This hash table gives the conversion between OpenGL types and what
150 # is used in the .spec file
152 my %arg_conv =
153 ("GLbitfield" => [ "long", 4 ],
154 "GLboolean" => [ "long", 4 ],
155 "GLbyte" => [ "long", 4 ],
156 "GLclampd" => [ "double", 8 ],
157 "GLclampf" => [ "float", 4 ],
158 "GLdouble" => [ "double", 8 ],
159 "GLenum" => [ "long", 4 ],
160 "GLfloat" => [ "float", 4 ],
161 "GLint" => [ "long", 4 ],
162 "GLshort" => [ "long", 4 ],
163 "GLsizei" => [ "long", 4 ],
164 "GLstring" => [ "str", 4 ],
165 "GLubyte" => [ "long", 4 ],
166 "GLuint" => [ "long", 4 ],
167 "GLushort" => [ "long", 4 ],
168 "GLhalfNV" => [ "long", 4 ],
169 "GLintptrARB" => [ "long", 4 ],
170 "GLsizeiptrARB" => [ "long", 4 ],
171 "GLhandleARB" => [ "long", 4 ],
172 "GLcharARB" => [ "long", 4 ],
173 "GLintptr" => [ "long", 4 ],
174 "GLsizeiptr" => [ "long", 4 ],
175 "_GLfuncptr" => [ "ptr", 4 ]);
178 # Used to convert some types
180 sub ConvertType($)
182 my ($type) = @_;
184 my %hash = ( "GLstring" => "const GLubyte *",
185 "GLintptrARB" => "INT_PTR",
186 "GLsizeiptrARB" => "INT_PTR",
187 "GLintptr" => "INT_PTR",
188 "GLsizeiptr" => "INT_PTR",
189 "GLhandleARB" => "unsigned int",
190 "GLcharARB" => "char",
191 "GLchar" => "char",
192 "GLhalfNV" => "unsigned short",
193 "GLvdpauSurfaceNV" => "INT_PTR",
194 "struct _cl_context" => "void",
195 "struct _cl_event" => "void",
196 "GLDEBUGPROCARB" => "void *",
197 "GLDEBUGPROCAMD" => "void *" );
199 foreach my $org (reverse sort keys %hash) {
200 if ($type =~ /$org/) {
201 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
202 return "$before$hash{$org}$after";
205 return $type;
209 # Used to convert some variable names
211 sub ConvertVarName($)
213 my ($type) = @_;
215 my %hash = ( "near" => "nearParam",
216 "far" => "farParam" );
218 foreach my $org (keys %hash) {
219 if ($type =~ /$org/) {
220 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
221 return "$before$hash{$org}$after";
224 return $type;
228 # This functions generates the thunk for a given function.
230 sub GenerateThunk($$$$$)
232 my ($func_ref, $comment, $prefix, $thread_safe, $local_var) = @_;
233 my $ret = "";
234 my $call_arg = "";
235 my $trace_call_arg = "";
236 my $trace_arg = "";
238 return "" if $func_ref->[0] eq "glGetString";
239 return "" if $func_ref->[0] eq "glGetIntegerv";
240 return "" if $func_ref->[0] eq "glFinish";
241 return "" if $func_ref->[0] eq "glFlush";
243 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
244 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
245 if ($comment eq 1) {
246 $ret = "$ret/***********************************************************************\n";
247 $ret = "$ret * $func_ref->[0] (OPENGL32.\@)\n";
248 $ret = "$ret */\n";
250 $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_$func_ref->[0]( ";
251 for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
252 ## Quick debug code :-)
253 ## print $func_ref->[2]->[$i]->[1] . "\n";
254 my $type = $func_ref->[2]->[$i]->[0];
255 my $name = ConvertVarName($func_ref->[2]->[$i]->[1]);
256 $ret .= ConvertType($type) . " $name";
257 $call_arg .= $name;
258 if ($type =~ /\*/) {
259 $trace_arg .= "%p";
260 $trace_call_arg .= $name;
261 } elsif (defined $debug_conv{$type}) {
262 if ($debug_conv{$type} =~ /(.*),(.*)/)
264 $trace_arg .= $1;
265 $trace_call_arg .= sprintf $2, $name;
267 else
269 $trace_arg .= $debug_conv{$type};
270 $trace_call_arg .= $name;
273 else { printf "Unknown type %s\n", $type; }
274 if ($i+1 < @{$func_ref->[2]}) {
275 $ret .= ", ";
276 $call_arg .= ", ";
277 $trace_call_arg .= ", ";
278 $trace_arg .= ", ";
279 } else {
280 $ret .= " ";
281 $call_arg .= " ";
282 $trace_call_arg .= " ";
285 $ret .= 'void ' if (!@{$func_ref->[2]});
286 $ret = "$ret) {\n";
287 if ($func_ref->[1] ne "void") {
288 $ret = "$ret " . ConvertType($func_ref->[1]) . " ret_value;\n";
290 $ret .= $local_var;
291 if ($gen_traces) {
292 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
293 if ($trace_arg ne "") {
294 $ret .= ", $trace_call_arg";
296 $ret = "$ret);\n";
298 if ($thread_safe) {
299 $ret = "$ret ENTER_GL();\n";
301 $ret = "$ret ";
302 if ($func_ref->[1] ne "void") {
303 $ret = $ret . "ret_value = ";
305 $ret = "$ret$prefix$func_ref->[0]( $call_arg);\n";
306 if ($thread_safe) {
307 $ret = "$ret LEAVE_GL();\n";
309 if ($func_ref->[1] ne "void") {
310 $ret = "$ret return ret_value;\n"
312 $ret = "$ret}\n";
314 # Return this string....
315 return $ret;
319 # Extract and checks the number of arguments
321 if (@ARGV > 1) {
322 my $name0=$0;
323 $name0=~s%^.*/%%;
324 die "Usage: $name0 [version]\n";
326 my $version = $ARGV[0] || "1.1";
327 if ($version eq "1.0") {
328 %norm_categories = %cat_1_0;
329 } elsif ($version eq "1.1") {
330 %norm_categories = %cat_1_1;
331 } elsif ($version eq "1.2") {
332 %norm_categories = %cat_1_2;
333 } elsif ($version eq "1.3") {
334 %norm_categories = %cat_1_3;
335 } elsif ($version eq "1.4") {
336 %norm_categories = %cat_1_4;
337 } elsif ($version eq "1.5") {
338 %norm_categories = %cat_1_5;
339 } else {
340 die "Incorrect OpenGL version.\n";
344 # Fetch the registry files
346 -f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
347 -f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
350 # Open the registry files
352 open(TYPES, "gl.tm") || die "Could not open gl.tm";
353 open(REGISTRY, "gl.spec") || die "Could not open gl.spec";
356 # First, create a mapping between the pseudo types used in the spec file
357 # and OpenGL types using the 'gl.tm' file.
359 my %pseudo_to_opengl = ();
360 while (my $line = <TYPES>) {
361 if ($line !~ /\w*\#/) {
362 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
363 $pseudo_to_opengl{$pseudo} = $opengl;
366 # This is to override the 'void' -> '*' bogus conversion
367 $pseudo_to_opengl{"void"} = "void";
368 $pseudo_to_opengl{"sync"} = "GLvoid*";
369 $pseudo_to_opengl{"Int64"} = "INT64";
370 $pseudo_to_opengl{"UInt64"} = "UINT64";
371 $pseudo_to_opengl{"Int64EXT"} = "INT64";
372 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
375 # Then, create the list of all OpenGL functions using the 'gl.spec'
376 # file. This will create two hash-tables, one with all the function
377 # whose category matches the one listed in '@norm_categories', the other
378 # with all other functions.
380 # An element of the hash table is a reference to an array with these
381 # elements :
383 # - function name
385 # - return type
387 # - reference to an array giving the list of arguments (an empty array
388 # for a 'void' function).
390 # The list of arguments is itself an array of reference to arrays. Each
391 # of these arrays represents the argument type and the argument name.
393 # An example :
395 # void glBitmap( GLsizei width, GLsizei height,
396 # GLfloat xorig, GLfloat yorig,
397 # GLfloat xmove, GLfloat ymove,
398 # const GLubyte *bitmap );
400 # Would give something like that :
402 # [ "glBitmap",
403 # "void",
404 # [ [ "GLsizei", "width" ],
405 # [ "GLsizei", "height" ],
406 # [ "GLfloat", "xorig" ],
407 # [ "GLfloat", "yorig" ],
408 # [ "GLfloat", "xmove" ],
409 # [ "GLfloat", "ymove" ],
410 # [ "GLubyte *", "bitmap"] ] ];
412 my %norm_functions = ();
415 # This stores various extensions NOT part of the GL extension registry but still
416 # implemented by most OpenGL libraries out there...
419 my %ext_functions =
420 ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion", "GL_KTX_buffer_region" ],
421 "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
422 [ "GLint", "x" ],
423 [ "GLint", "y" ],
424 [ "GLsizei", "width" ],
425 [ "GLsizei", "height" ] ], "glReadBufferRegion", "GL_KTX_buffer_region" ],
426 "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
427 [ "GLint", "x" ],
428 [ "GLint", "y" ],
429 [ "GLsizei", "width" ],
430 [ "GLsizei", "height" ],
431 [ "GLint", "xDest" ],
432 [ "GLint", "yDest" ] ], "glDrawBufferRegion", "GL_KTX_buffer_region" ],
433 "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled", "GL_KTX_buffer_region" ],
434 "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion", "GL_KTX_buffer_region" ],
435 "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
436 [ "GLfloat", "s" ],
437 [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS", "GL_SGIS_multitexture" ],
438 "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
439 [ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
440 "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
441 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS", "GL_SGIS_multitexture" ],
442 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
443 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS", "GL_SGIS_multitexture" ],
444 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
445 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS", "GL_SGIS_multitexture" ],
446 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
447 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS", "GL_SGIS_multitexture" ],
448 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
449 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS", "GL_SGIS_multitexture" ],
450 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
451 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS", "GL_SGIS_multitexture" ],
452 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
453 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS", "GL_SGIS_multitexture" ],
454 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
455 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS", "GL_SGIS_multitexture" ],
456 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
457 [ "GLdouble", "s"],
458 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS", "GL_SGIS_multitexture" ],
459 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
460 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS", "GL_SGIS_multitexture" ],
461 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
462 [ "GLfloat", "s" ],
463 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS", "GL_SGIS_multitexture" ],
464 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
465 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS", "GL_SGIS_multitexture" ],
466 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
467 [ "GLint", "s" ],
468 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS", "GL_SGIS_multitexture" ],
469 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
470 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS", "GL_SGIS_multitexture" ],
471 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
472 [ "GLshort", "s" ],
473 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS", "GL_SGIS_multitexture" ],
474 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
475 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS", "GL_SGIS_multitexture" ],
476 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
477 [ "GLdouble", "s" ],
478 [ "GLdouble", "t" ],
479 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS", "GL_SGIS_multitexture" ],
480 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
481 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS", "GL_SGIS_multitexture" ],
482 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
483 [ "GLfloat", "s" ],
484 [ "GLfloat", "t" ],
485 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS", "GL_SGIS_multitexture" ],
486 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
487 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS", "GL_SGIS_multitexture" ],
488 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
489 [ "GLint", "s" ],
490 [ "GLint", "t" ],
491 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS", "GL_SGIS_multitexture" ],
492 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
493 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS", "GL_SGIS_multitexture" ],
494 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
495 [ "GLshort", "s" ],
496 [ "GLshort", "t" ],
497 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS", "GL_SGIS_multitexture" ],
498 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
499 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS", "GL_SGIS_multitexture" ],
500 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
501 [ "GLdouble", "s" ],
502 [ "GLdouble", "t" ],
503 [ "GLdouble", "r" ],
504 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS", "GL_SGIS_multitexture" ],
505 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
506 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS", "GL_SGIS_multitexture" ],
507 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
508 [ "GLfloat", "s" ],
509 [ "GLfloat", "t" ],
510 [ "GLfloat", "r" ],
511 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS", "GL_SGIS_multitexture" ],
512 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
513 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS", "GL_SGIS_multitexture" ],
514 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
515 [ "GLint", "s" ],
516 [ "GLint", "t" ],
517 [ "GLint", "r" ],
518 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS", "GL_SGIS_multitexture" ],
519 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
520 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS", "GL_SGIS_multitexture" ],
521 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
522 [ "GLshort", "s" ],
523 [ "GLshort", "t" ],
524 [ "GLshort", "r" ],
525 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS", "GL_SGIS_multitexture" ],
526 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
527 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS", "GL_SGIS_multitexture" ],
528 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
529 [ "GLint", "size" ],
530 [ "GLenum", "type" ],
531 [ "GLsizei", "stride" ],
532 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS", "GL_SGIS_multitexture" ],
533 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS", "GL_SGIS_multitexture" ],
534 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS", "GL_SGIS_multitexture" ],
535 "glDeleteObjectBufferATI" => [ "glDeleteObjectBufferATI", "void", [ [ "GLuint", "buffer" ] ], "glDeleteObjectBufferATI", "GL_ATI_vertex_array_object" ]
538 my @arg_names;
539 my %arg_types;
540 while (my $line = <REGISTRY>) {
541 if ($line =~ /^\w*\(.*\)/) {
542 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
543 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
544 # and the argument names
545 @arg_names = split /\s*,\s*/, $args;
547 # After get :
548 # - the return type
549 # - category (the extension the function is part of)
550 # - the argument types
551 # - the category the function belongs
552 %arg_types = ();
553 my $category = "";
554 my $ret_type = "";
555 while (1) {
556 $line = <REGISTRY>;
557 unless (defined($line)) {
558 last;
559 } elsif ($line =~ /^\s*$/) {
560 if (($category eq "") || ($ret_type eq "")) {
561 die "Missing 'category' line in function $funcname.\n";
563 last;
564 } elsif ($line =~ /\t*return\t*(\w*)/) {
565 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
566 $ret_type = $pseudo_to_opengl{$ret_type};
567 unless (defined($ret_type)) {
568 die "Unsupported return type in function $funcname\n";
570 } elsif ($line =~ /^\t*category/) {
571 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
572 } elsif ($line =~ /^\t*param/) {
573 my ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
574 my $ptr = 0;
575 unless (defined($name)) {
576 chomp $line;
577 die "Broken spec file line $line in function $funcname\n";
580 if ($ext =~ /array/) {
581 # This is a pointer
582 $ptr = 1;
583 } elsif ($ext =~ /reference/) {
584 # This is a pointer
585 $ptr = 1;
586 } elsif ($ext =~ /value/) {
587 # And this a 'normal' value
588 $ptr = 0;
589 } else {
590 chomp $line;
591 die "Unsupported type : $line in function $funcname\n";
593 # Get the 'real' type and append a '*' in case of a pointer
594 my $type = $pseudo_to_opengl{$base_type};
595 unless (defined($type)) {
596 chomp $line;
597 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
599 if ($ptr) {
600 $type = "$type*";
603 $arg_types{$name} = $type;
607 # Now, build the argument reference
608 my $arg_ref = [ ];
609 for (my $i = 0; $i < @arg_names; $i++) {
610 unless (defined($arg_types{$arg_names[$i]})) {
611 print "@arg_names\n";
612 foreach (sort keys %arg_types) {
613 print "$_ => $arg_types{$_}\n";
615 die "Undefined type for $arg_names[$i] in function $funcname\n";
618 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
620 my $func_ref = [ "gl$funcname",
621 $ret_type,
622 $arg_ref,
623 "gl$funcname",
624 "GL_$category" ];
626 # Now, put in one or the other hash table
627 if ($norm_categories{$category}) {
628 $norm_functions{"gl$funcname"} = $func_ref;
629 } else {
630 $ext_functions{"gl$funcname"} = $func_ref;
636 # Clean up the input files
638 close(TYPES);
639 close(REGISTRY);
642 # Now, generate the output files. First, the spec file.
644 open(SPEC, ">$spec_file");
646 foreach (sort keys %norm_functions) {
647 my $func_name = $norm_functions{$_}->[0];
648 print SPEC "@ stdcall $func_name( ";
649 for (my $i = 0; $i < @{$norm_functions{$_}->[2]}; $i++) {
650 my $type = $norm_functions{$_}->[2]->[$i]->[0];
651 if ($type =~ /\*/) {
652 print SPEC "ptr ";
653 } elsif (defined($arg_conv{$type})) {
654 print SPEC "$@$arg_conv{$type}[0] ";
655 } else {
656 die "No conversion for GL type $type...\n";
659 print SPEC ") wine_$func_name\n";
662 print SPEC "@ stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
663 @ stdcall wglCopyContext(long long long) gdi32.wglCopyContext
664 @ stdcall wglCreateContext(long) gdi32.wglCreateContext
665 @ stdcall wglCreateLayerContext(long long)
666 @ stdcall wglDeleteContext(long) gdi32.wglDeleteContext
667 @ stdcall wglDescribeLayerPlane(long long long long ptr)
668 @ stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
669 @ stdcall wglGetCurrentContext() gdi32.wglGetCurrentContext
670 @ stdcall wglGetCurrentDC() gdi32.wglGetCurrentDC
671 @ stub wglGetDefaultProcAddress
672 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
673 @ stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
674 @ stdcall wglGetProcAddress(str)
675 @ stdcall wglMakeCurrent(long long) gdi32.wglMakeCurrent
676 @ stdcall wglRealizeLayerPalette(long long long)
677 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
678 @ stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
679 @ stdcall wglShareLists(long long) gdi32.wglShareLists
680 @ stdcall wglSwapBuffers(long)
681 @ stdcall wglSwapLayerBuffers(long long)
682 @ stdcall wglUseFontBitmapsA(long long long long) gdi32.wglUseFontBitmapsA
683 @ stdcall wglUseFontBitmapsW(long long long long) gdi32.wglUseFontBitmapsW
684 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
685 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
688 close(SPEC);
691 # After the spec file, the opengl_norm.c file
693 open(NORM, ">$norm_file");
694 print NORM "
695 /* Auto-generated file... Do not edit ! */
697 #include \"config.h\"
698 #include \"opengl_ext.h\"
699 #include \"wine/debug.h\"
701 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
703 foreach (sort keys %norm_functions) {
704 my $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe, "");
706 print NORM "\n$string" if $string;
708 close(NORM);
711 # Finally, more complex, the opengl_ext.c file
713 open(EXT, ">$ext_file");
714 print EXT "
715 /* Auto-generated file... Do not edit ! */
717 #include \"config.h\"
718 #include \"opengl_ext.h\"
719 #include \"wine/debug.h\"
721 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
725 # The thunks themselves....
726 my $count = keys %ext_functions;
727 print EXT "enum extensions\n{\n";
728 foreach (sort keys %ext_functions) {
729 my $func_ref = $ext_functions{$_};
730 print EXT " EXT_$func_ref->[0],\n";
732 print EXT " NB_EXTENSIONS\n};\n\n";
733 print EXT "const int extension_registry_size = NB_EXTENSIONS;\n";
734 print EXT "void *extension_funcs[NB_EXTENSIONS];\n";
735 print EXT "\n/* The thunks themselves....*/";
736 foreach (sort keys %ext_functions) {
737 my $func_ref = $ext_functions{$_};
738 my $local_var = " " . ConvertType($func_ref->[1]) . " (*$ext_prefix$func_ref->[0])( ";
739 for (my $i = 0; $i < @{$func_ref->[2]}; $i++) {
740 my $type = ConvertType($func_ref->[2]->[$i]->[0]);
741 $local_var .= "$type";
742 if ($i+1 < @{$func_ref->[2]}) {
743 $local_var .= ", ";
744 } else {
745 $local_var .= " ";
748 $local_var .= 'void ' if (!@{$func_ref->[2]});
749 $local_var .= ") = extension_funcs[EXT_$func_ref->[0]];\n";
750 print EXT "\nstatic ", GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe, $local_var);
753 # Then the table giving the string <-> function correspondence */
754 print EXT "\n\n/* The table giving the correspondence between names and functions */\n";
755 print EXT "const OpenGL_extension extension_registry[NB_EXTENSIONS] = {\n";
756 my $i = 0;
757 foreach (sort keys %ext_functions) {
758 my $func_ref = $ext_functions{$_};
759 if ($func_ref->[0] eq $func_ref->[3])
761 print EXT " { \"$func_ref->[0]\", \"$func_ref->[4]\", wine_$func_ref->[0] }";
763 if ($i != $count-1) {
764 print EXT ",";
766 $i++;
767 print EXT "\n";
769 print EXT "};\n";
771 close(EXT);