webservices: Write correct envelope headers for WS_ENVELOPE_VERSION_NONE.
[wine.git] / dlls / opengl32 / make_opengl
blob45e3f720ea6275b59ffe292e182d2dc90d709f47
1 #!/usr/bin/perl -w
2 use strict;
3 use XML::Simple;
5 # This script is called thus :
7 # make_opengl [opengl_version]
9 # - It needs files from the OpenGL extension registry:
11 # https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml
12 # https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/wgl.xml
14 # If they are not found in the current directory the script will
15 # attempt to download them from there.
17 # - opengl_version is the OpenGL version emulated by the library
18 # (can be 1.0 to 1.5). The default is 1.1.
20 # This script generates the three following files :
22 # - opengl32.spec : the spec file giving all the exported functions
23 # of the OpenGL32.DLL library. These functions are the one an
24 # application can directly link to (and are all the functions
25 # defined in the OpenGL core for the version defined by
26 # 'opengl_version').
28 # - opengl_norm.c : this file contains the thunks for all OpenGL
29 # functions that are defined in 'opengl32.spec'. The corresponding
30 # functions NEED to be defined in Linux's libGL or the library
31 # won't be able to be linked in.
33 # - opengl_ext.c : in this file are stored thunks for ALL possible
34 # OpenGL extensions (at least, all the extensions that are defined
35 # in the OpenGL extension registry). Contrary to 'opengl_norm.c',
36 # you do not need to have these extensions in your libGL to have
37 # OpenGL work (as they are resolved at run-time using
38 # glXGetProcAddressARB).
40 # - include/wine/wgl_driver.h: definitions for the tables of OpenGL functions.
43 # Copyright 2000 Lionel Ulmer
44 # Copyright 2012 Alexandre Julliard
46 # This library is free software; you can redistribute it and/or
47 # modify it under the terms of the GNU Lesser General Public
48 # License as published by the Free Software Foundation; either
49 # version 2.1 of the License, or (at your option) any later version.
51 # This library is distributed in the hope that it will be useful,
52 # but WITHOUT ANY WARRANTY; without even the implied warranty of
53 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54 # Lesser General Public License for more details.
56 # You should have received a copy of the GNU Lesser General Public
57 # License along with this library; if not, write to the Free Software
58 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
62 # Files to generate
64 my $spec_file = "opengl32.spec";
65 my $norm_file = "opengl_norm.c";
66 my $ext_file = "opengl_ext.c";
67 my $wgl_driver_file = "../../include/wine/wgl_driver.h";
68 my $wgl_file = "../../include/wine/wgl.h";
70 # Set to 0 for removing the ENTER / LEAVE GL calls
71 my $gen_thread_safe = 0;
72 # Prefix used for the local variables
73 my $ext_prefix = "func_";
74 # If set to 1, generate TRACEs for each OpenGL function
75 my $gen_traces = 1;
78 # List of categories to put in the 'opengl_norm.c' file
80 my %cat_1_0 = ( "GL_VERSION_1_0" => 1 );
81 my %cat_1_1 = ( %cat_1_0, "GL_VERSION_1_1" => 1 );
82 my %cat_1_2 = ( %cat_1_1, "GL_VERSION_1_2" => 1 );
83 my %cat_1_3 = ( %cat_1_2, "GL_VERSION_1_3" => 1 );
84 my %cat_1_4 = ( %cat_1_3, "GL_VERSION_1_4" => 1 );
85 my %cat_1_5 = ( %cat_1_4, "GL_VERSION_1_5" => 1 );
87 my %norm_categories = ();
90 # This hash table gives the conversion between OpenGL types and what
91 # is used by the TRACE printfs
93 my %debug_conv =
94 ("GLbitfield" => "%d",
95 "GLboolean" => "%d",
96 "GLbyte" => "%d",
97 "GLclampd" => "%f",
98 "GLclampf" => "%f",
99 "GLclampx" => "%d",
100 "GLdouble" => "%f",
101 "GLenum" => "%d",
102 "GLfloat" => "%f",
103 "GLfixed" => "%d",
104 "GLint" => "%d",
105 "GLshort" => "%d",
106 "GLsizei" => "%d",
107 "GLstring" => "%s",
108 "GLsync" => "%p",
109 "GLubyte" => "%d",
110 "GLuint" => "%d",
111 "GLushort" => "%d",
112 "GLhalfNV" => "%d",
113 "GLintptrARB" => "%ld",
114 "GLsizeiptrARB" => "%ld",
115 "GLintptr" => "%ld",
116 "GLsizeiptr" => "%ld",
117 "GLhandleARB" => "%d",
118 "GLcharARB" => "%c",
119 "GLuint64" => "%s,wine_dbgstr_longlong(%s)",
120 "GLint64" => "%s,wine_dbgstr_longlong(%s)",
121 "GLuint64EXT" => "%s,wine_dbgstr_longlong(%s)",
122 "GLint64EXT" => "%s,wine_dbgstr_longlong(%s)",
123 "GLvoid" => "(void)",
124 "_GLfuncptr" => "%p",
125 "GLDEBUGPROC" => "%p",
126 "GLDEBUGPROCARB" => "%p",
127 "GLDEBUGPROCAMD" => "%p",
128 "GLDEBUGPROCKHR" => "%p",
129 "GLvdpauSurfaceNV" => "%ld",
130 "int" => "%d",
131 "unsigned int" => "%u",
132 "UINT" => "%u",
133 "DWORD" => "%u",
134 "BOOL" => "%u",
135 "INT64" => "%s,wine_dbgstr_longlong(%s)",
136 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
137 "LPVOID" => "%p",
138 "HANDLE" => "%p",
139 "HDC" => "%p",
140 "HGLRC" => "%p",
141 "HPBUFFERARB" => "%p",
142 "HPBUFFEREXT" => "%p",
146 # This hash table gives the conversion between OpenGL types and what
147 # is used in the .spec and header files.
149 my %arg_conv =
150 ("GLbitfield" => [ "long", "unsigned int" ],
151 "GLboolean" => [ "long", "unsigned char" ],
152 "GLbyte" => [ "long", "signed char" ],
153 "GLchar" => [ "long", "char" ],
154 "GLclampd" => [ "double", "double" ],
155 "GLclampf" => [ "float", "float" ],
156 "GLclampx" => [ "long", "int" ],
157 "GLdouble" => [ "double", "double" ],
158 "GLenum" => [ "long", "unsigned int" ],
159 "GLfloat" => [ "float", "float" ],
160 "GLfixed" => [ "long", "int" ],
161 "GLint" => [ "long", "int" ],
162 "GLint64" => [ "int64", "INT64" ],
163 "GLint64EXT" => [ "int64", "INT64" ],
164 "GLintptr" => [ "long", "INT_PTR" ],
165 "GLshort" => [ "long", "short" ],
166 "GLsizei" => [ "long", "int" ],
167 "GLsizeiptr" => [ "long", "INT_PTR" ],
168 "GLstring" => [ "str", "const unsigned char *" ],
169 "GLsync" => [ "ptr", "struct __GLsync *" ],
170 "GLubyte" => [ "long", "unsigned char" ],
171 "GLuint" => [ "long", "unsigned int" ],
172 "GLuint64" => [ "int64", "UINT64" ],
173 "GLuint64EXT" => [ "int64", "UINT64" ],
174 "GLushort" => [ "long", "unsigned short" ],
175 "GLvoid" => [ "void", "void" ],
176 "GLcharARB" => [ "long", "char" ],
177 "GLhandleARB" => [ "long", "unsigned int" ],
178 "GLintptrARB" => [ "long", "INT_PTR" ],
179 "GLsizeiptrARB" => [ "long", "INT_PTR" ],
180 "GLhalfNV" => [ "long", "unsigned short" ],
181 "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
184 # Used to convert some types
186 sub ConvertType($)
188 my ($type) = @_;
190 my %hash = (
191 "struct _cl_context" => "void",
192 "struct _cl_event" => "void",
193 "HGLRC" => "struct wgl_context *",
194 "GLDEBUGPROC" => "void *",
195 "GLDEBUGPROCARB" => "void *",
196 "GLDEBUGPROCAMD" => "void *",
197 "GLDEBUGPROCKHR" => "void *",
198 "HPBUFFERARB" => "struct wgl_pbuffer *",
199 "HPBUFFEREXT" => "struct wgl_pbuffer *",
202 foreach my $org (reverse sort keys %hash) {
203 if ($type =~ /^(.*)$org(.*)$/) {
204 return "$1$hash{$org}$2";
207 return $type;
211 # Used to convert some variable names
213 sub ConvertVarName($)
215 my ($type) = @_;
217 my %hash = ( "near" => "nearParam",
218 "far" => "farParam" );
220 foreach my $org (keys %hash) {
221 if ($type =~ /^(.*)$org(.*)$/) {
222 return "$1$hash{$org}$2";
225 return $type;
229 # This functions generates the thunk for a given function.
231 sub GenerateThunk($$$$)
233 my ($name, $func_ref, $comment, $prefix) = @_;
234 my $ret = "";
235 my $call_arg = "";
236 my $trace_call_arg = "";
237 my $trace_arg = "";
239 return "" if $name eq "glDebugEntry";
240 return "" if $name eq "glGetIntegerv";
241 return "" if $name eq "glGetString";
242 return "" if $func_ref->[2] && $func_ref->[2]->[0] =~ /WGL_/;
244 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
245 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
246 if ($comment eq 1) {
247 $ret .= "/***********************************************************************\n";
248 $ret .= " * $name (OPENGL32.\@)\n";
249 $ret .= " */\n";
251 $ret .= ConvertType($func_ref->[0]) . " WINAPI $name( ";
252 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
253 my $type = $func_ref->[1]->[$i]->[0];
254 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
255 my ($base_type, $type_specifier, $name_specifier) = ($type, $type, $name);
256 if ($type =~ /(.*) (.*)/) {
257 $base_type = $2;
258 } elsif ($type =~ /(.*)(\[.*)/) {
259 $base_type = $1;
260 $type_specifier = $1;
261 $name_specifier = $name . $2
263 $ret .= ConvertType($type_specifier) . " $name_specifier";
264 $call_arg .= $name;
265 if ($type =~ /\*/ || $type =~ /\[/) {
266 $trace_arg .= "%p";
267 $trace_call_arg .= $name;
268 } elsif (defined $debug_conv{$base_type}) {
269 if ($debug_conv{$base_type} =~ /(.*),(.*)/) {
270 $trace_arg .= $1;
271 $trace_call_arg .= sprintf $2, $name;
272 } else {
273 $trace_arg .= $debug_conv{$base_type};
274 $trace_call_arg .= $name;
277 else { printf "Unknown type %s\n", $type; }
278 if ($i+1 < @{$func_ref->[1]}) {
279 $ret .= ", ";
280 $call_arg .= ", ";
281 $trace_call_arg .= ", ";
282 $trace_arg .= ", ";
283 } else {
284 $ret .= " ";
285 $call_arg .= " ";
286 $trace_call_arg .= " ";
289 $ret .= 'void ' if (!@{$func_ref->[1]});
290 return "$ret) DECLSPEC_HIDDEN;\n" if $name eq "glGetStringi";
291 $ret .= ") {\n";
292 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
293 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
294 $ret .= " " . ConvertType($func_ref->[0]) . " ret_value;\n";
296 if ($gen_traces) {
297 $ret .= " TRACE(\"($trace_arg)\\n\"";
298 if ($trace_arg ne "") {
299 $ret .= ", $trace_call_arg";
301 $ret .= ");\n";
303 if ($gen_thread_safe) {
304 $ret .= " ENTER_GL();\n";
305 $ret .= " ";
306 if ($func_ref->[0] ne "void") {
307 $ret .= "ret_value = ";
309 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
310 $ret .= " LEAVE_GL();\n";
311 if ($func_ref->[0] ne "void") {
312 $ret .= " return ret_value;\n"
315 else {
316 $ret .= " ";
317 if ($func_ref->[0] ne "void") {
318 $ret .= "return ";
320 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
322 $ret .= "}\n";
324 # Return this string....
325 return $ret;
328 sub generate_null_func($$)
330 my ($name, $func_ref) = @_;
331 my $ret;
333 return "" if $name eq "glDebugEntry";
335 $ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
336 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
337 my $type = $func_ref->[1]->[$i]->[0];
338 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
339 my $base_type;
340 if ($type =~ /(.*)(\[.*)/) {
341 $base_type = $1;
342 $name .= $2;
343 } else {
344 $base_type = $type;
346 $ret .= ConvertType($base_type) . " $name";
347 $ret .= "," if ($i+1 < @{$func_ref->[1]});
348 $ret .= " ";
350 $ret .= 'void ' if (!@{$func_ref->[1]});
351 $ret .= ") {";
352 if ($name eq "glGetError")
354 $ret .= " return GL_INVALID_OPERATION;";
356 elsif ($func_ref->[0] ne "void")
358 $ret .= " return 0;";
360 $ret .= " }\n";
361 return $ret;
364 sub get_func_proto($$$)
366 my ($format, $name, $func) = @_;
367 my $ret = sprintf "%-10s", ConvertType($func->[0]);
368 $ret .= " " . sprintf($format,$name) . "(";
369 for (my $i = 0; $i < @{$func->[1]}; $i++)
371 $ret .= ConvertType($func->[1]->[$i]->[0]);
372 $ret .= "," if ($i+1 < @{$func->[1]});
374 $ret .= "void" unless @{$func->[1]};
375 $ret .= ")";
376 return $ret;
380 # Extract and checks the number of arguments
382 if (@ARGV > 1) {
383 my $name0=$0;
384 $name0=~s%^.*/%%;
385 die "Usage: $name0 [version]\n";
387 my $version = $ARGV[0] || "1.1";
388 if ($version eq "1.0") {
389 %norm_categories = %cat_1_0;
390 } elsif ($version eq "1.1") {
391 %norm_categories = %cat_1_1;
392 } elsif ($version eq "1.2") {
393 %norm_categories = %cat_1_2;
394 } elsif ($version eq "1.3") {
395 %norm_categories = %cat_1_3;
396 } elsif ($version eq "1.4") {
397 %norm_categories = %cat_1_4;
398 } elsif ($version eq "1.5") {
399 %norm_categories = %cat_1_5;
400 } else {
401 die "Incorrect OpenGL version.\n";
405 # Fetch the registry files
407 -f "gl.xml" || system "wget --no-check-certificate https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml" || die "cannot download gl.xml";
408 -f "wgl.xml" || system "wget --no-check-certificate https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/wgl.xml" || die "cannot download wgl.xml";
412 # Then, create the list of all OpenGL functions using the registry
413 # files. This will create two hash-tables, one with all the function
414 # whose category matches the one listed in '@norm_categories', the other
415 # with all other functions.
417 # An element of the hash table is a reference to an array with these
418 # elements :
420 # - function name
422 # - return type
424 # - reference to an array giving the list of arguments (an empty array
425 # for a 'void' function).
427 # The list of arguments is itself an array of reference to arrays. Each
428 # of these arrays represents the argument type and the argument name.
430 # An example :
432 # void glBitmap( GLsizei width, GLsizei height,
433 # GLfloat xorig, GLfloat yorig,
434 # GLfloat xmove, GLfloat ymove,
435 # const GLubyte *bitmap );
437 # Would give something like that :
439 # [ "glBitmap",
440 # "void",
441 # [ [ "GLsizei", "width" ],
442 # [ "GLsizei", "height" ],
443 # [ "GLfloat", "xorig" ],
444 # [ "GLfloat", "yorig" ],
445 # [ "GLfloat", "xmove" ],
446 # [ "GLfloat", "ymove" ],
447 # [ "GLubyte *", "bitmap"] ] ];
449 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
450 [ "GLint", "unknown2" ]] ] );
453 # This stores various extensions NOT part of the GL extension registry but still
454 # implemented by most OpenGL libraries out there...
457 my %ext_functions =
459 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], [ "GL_KTX_buffer_region" ] ],
460 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
461 [ "GLint", "x" ],
462 [ "GLint", "y" ],
463 [ "GLsizei", "width" ],
464 [ "GLsizei", "height" ] ], [ "GL_KTX_buffer_region" ] ],
465 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
466 [ "GLint", "x" ],
467 [ "GLint", "y" ],
468 [ "GLsizei", "width" ],
469 [ "GLsizei", "height" ],
470 [ "GLint", "xDest" ],
471 [ "GLint", "yDest" ] ], [ "GL_KTX_buffer_region" ] ],
472 "glBufferRegionEnabled" => [ "GLuint", [ ], [ "GL_KTX_buffer_region" ] ],
473 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], [ "GL_KTX_buffer_region" ] ],
474 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
475 [ "GLfloat", "s" ],
476 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
477 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
478 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
479 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
480 [ "GLdouble", "s" ] ], [ "GL_SGIS_multitexture" ] ],
481 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
482 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
483 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
484 [ "GLfloat", "s" ] ], [ "GL_SGIS_multitexture" ] ],
485 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
486 [ "const GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
487 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
488 [ "GLint", "s" ] ], [ "GL_SGIS_multitexture" ] ],
489 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
490 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
491 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
492 [ "GLshort", "s" ] ], [ "GL_SGIS_multitexture" ] ],
493 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
494 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
495 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
496 [ "GLdouble", "s"],
497 [ "GLdouble", "t" ] ], [ "GL_SGIS_multitexture" ] ],
498 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
499 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
500 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
501 [ "GLfloat", "s" ],
502 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
503 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
504 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
505 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
506 [ "GLint", "s" ],
507 [ "GLint", "t" ] ], [ "GL_SGIS_multitexture" ] ],
508 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
509 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
510 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
511 [ "GLshort", "s" ],
512 [ "GLshort", "t" ] ], [ "GL_SGIS_multitexture" ] ],
513 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
514 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
515 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
516 [ "GLdouble", "s" ],
517 [ "GLdouble", "t" ],
518 [ "GLdouble", "r" ] ], [ "GL_SGIS_multitexture" ] ],
519 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
520 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
521 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
522 [ "GLfloat", "s" ],
523 [ "GLfloat", "t" ],
524 [ "GLfloat", "r" ] ], [ "GL_SGIS_multitexture" ] ],
525 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
526 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
527 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
528 [ "GLint", "s" ],
529 [ "GLint", "t" ],
530 [ "GLint", "r" ] ], [ "GL_SGIS_multitexture" ] ],
531 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
533 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
534 [ "GLshort", "s" ],
535 [ "GLshort", "t" ],
536 [ "GLshort", "r" ] ], [ "GL_SGIS_multitexture" ] ],
537 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
538 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
539 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
540 [ "GLdouble", "s" ],
541 [ "GLdouble", "t" ],
542 [ "GLdouble", "r" ],
543 [ "GLdouble", "q" ] ], [ "GL_SGIS_multitexture" ] ],
544 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
545 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
546 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLfloat", "s" ],
548 [ "GLfloat", "t" ],
549 [ "GLfloat", "r" ],
550 [ "GLfloat", "q" ] ], [ "GL_SGIS_multitexture" ] ],
551 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
552 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
553 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
554 [ "GLint", "s" ],
555 [ "GLint", "t" ],
556 [ "GLint", "r" ],
557 [ "GLint", "q" ] ], [ "GL_SGIS_multitexture" ] ],
558 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
559 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
560 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
561 [ "GLshort", "s" ],
562 [ "GLshort", "t" ],
563 [ "GLshort", "r" ],
564 [ "GLshort", "q" ] ], [ "GL_SGIS_multitexture" ] ],
565 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
566 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
567 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
568 [ "GLint", "size" ],
569 [ "GLenum", "type" ],
570 [ "GLsizei", "stride" ],
571 [ "GLvoid *", "pointer" ] ], [ "GL_SGIS_multitexture" ] ],
572 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
573 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
574 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], [ "GL_ATI_vertex_array_object" ] ],
575 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
576 [ "int", "format" ] ], [ "WGL_WINE_pixel_format_passthrough" ] ],
577 "wglQueryCurrentRendererIntegerWINE" => [ "BOOL", [ [ "GLenum", "attribute" ],
578 [ "GLuint *", "value" ] ], [ "WGL_WINE_query_renderer" ] ],
579 "wglQueryCurrentRendererStringWINE" => [ "const GLchar *", [ [ "GLenum", "attribute" ] ],
580 [ "WGL_WINE_query_renderer" ] ],
581 "wglQueryRendererIntegerWINE" => [ "BOOL", [ [ "HDC", "dc" ],
582 [ "GLint", "renderer" ],
583 [ "GLenum", "attribute" ],
584 [ "GLuint *", "value" ] ], [ "WGL_WINE_query_renderer" ] ],
585 "wglQueryRendererStringWINE" => [ "const GLchar *", [ [ "HDC", "dc" ],
586 [ "GLint", "renderer" ],
587 [ "GLenum", "attribute" ] ], [ "WGL_WINE_query_renderer" ] ],
591 my %wgl_functions =
593 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
594 [ "struct wgl_context *", "dst" ],
595 [ "UINT", "mask" ] ] ],
596 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
597 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
598 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
599 [ "INT", "format" ],
600 [ "UINT", "size" ],
601 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
602 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
603 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
604 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
605 [ "struct wgl_context *", "context" ] ] ],
606 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
607 [ "INT", "format" ],
608 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
609 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
610 [ "struct wgl_context *", "dst" ] ] ],
611 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
614 my %supported_wgl_extensions =
616 "WGL_ARB_create_context" => 1,
617 "WGL_ARB_extensions_string" => 1,
618 "WGL_ARB_make_current_read" => 1,
619 "WGL_ARB_pbuffer" => 1,
620 "WGL_ARB_pixel_format" => 1,
621 "WGL_ARB_render_texture" => 1,
622 "WGL_EXT_extensions_string" => 1,
623 "WGL_EXT_swap_control" => 1,
624 "WGL_NV_vertex_array_range" => 1,
625 "WGL_WINE_pixel_format_passthrough" => 1,
628 my %enums =
630 "WGL_RENDERER_VENDOR_ID_WINE" => "0x8183",
631 "WGL_RENDERER_DEVICE_ID_WINE" => "0x8184",
632 "WGL_RENDERER_VERSION_WINE" => "0x8185",
633 "WGL_RENDERER_ACCELERATED_WINE" => "0x8186",
634 "WGL_RENDERER_VIDEO_MEMORY_WINE" => "0x8187",
635 "WGL_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_WINE" => "0x8188",
636 "WGL_RENDERER_PREFERRED_PROFILE_WINE" => "0x8189",
637 "WGL_RENDERER_OPENGL_CORE_PROFILE_VERSION_WINE" => "0x818A",
638 "WGL_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_WINE" => "0x818B",
639 "WGL_RENDERER_OPENGL_ES_PROFILE_VERSION_WINE" => "0x818C",
640 "WGL_RENDERER_OPENGL_ES2_PROFILE_VERSION_WINE" => "0x818D",
641 "WGL_RENDERER_ID_WINE" => "0x818E",
644 sub parse_variable($)
646 my $p = shift;
647 my $ptype = '';
648 my $pname = '';
649 my $pnamebefore = '';
650 my $pnameafter = '';
652 while (my ($k, $v) = each(%$p)){
653 if ($k eq 'ptype') {
654 $ptype = ${$v}[0];
655 } elsif ($k eq 'name') {
656 $pname = ${$v}[0];
657 } elsif ($k eq 'content') {
658 if (ref($v) eq 'ARRAY') {
659 my @n = @{$v};
660 $pnamebefore = $n[0];
661 $pnameafter = $n[1] if (@n > 0);
662 } elsif ($v eq 'const ') {
663 $pnamebefore = $v;
664 } else {
665 $pnameafter = $v;
669 $ptype = $pnamebefore . $ptype . $pnameafter;
670 $ptype =~ s/ \*/\*/g;
671 $ptype =~ s/ $//g;
672 return [ $ptype, $pname ];
675 sub parse_file($$)
677 my ($file, $generate_enums) = @_;
678 my $xml = new XML::Simple;
679 my $data = $xml->XMLin($file, ForceArray => 1);
680 my %functions;
682 # save all functions
683 for my $command ( @{${$data->{commands}}[0]->{'command'}} ) {
684 my $name = '';
685 my $ret = '';
686 my $params = [];
687 my @alias = '';
688 while (my ($k, $v) = each(%$command)){
689 if ($k eq 'param') {
690 push(@$params, parse_variable($_)) for (@{$v});
691 } elsif ($k eq 'proto') {
692 ($ret, $name) = @{parse_variable(${$v}[0])};
695 $functions{$name} = [ $ret, $params ];
698 # save all enums (only GL)
699 if ($generate_enums) {
700 for my $enum ( @{$data->{'enums'}} ) {
701 if (ref($enum->{'enum'}) eq "HASH") {
702 while (my ($k, $v) = each(%{$enum->{'enum'}})){
703 $enums{$k} = $v->{'value'};
709 # generate norm functions
710 while (my ($k, $v) = each(%{$data->{feature}})) {
711 if ($norm_categories{$k}) {
712 for my $req (@{$v->{require}}) {
713 for(keys %{$req->{command}}) {
714 $norm_functions{$_} = $functions{$_};
720 # generate extension functions from norm functions, if they are newer than the category
721 my %features = %{$data->{feature}};
722 foreach (sort keys %features) {
723 my ($k, $v) = %features{$_};
724 if (!$norm_categories{$k} && $v->{api} =~ /^gl(\||$)/)
726 for my $req (@{$v->{require}}) {
727 for (keys %{$req->{command}}) {
728 if (!$ext_functions{$_} && !$norm_functions{$_}) {
729 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
736 # generate extension functions
737 while (my ($k, $v) = each(%{${$data->{extensions}}[0]->{extension}})) {
738 if ($v->{supported} =~ /^gl(\||$)/) {
739 for my $req (@{$v->{require}}) {
740 if (!defined $req->{api} || $req->{api} =~ /^gl(\||$)/) {
741 for (keys %{$req->{command}}) {
742 if (!$ext_functions{$_} && !$norm_functions{$_}) {
743 $ext_functions{$_} = [$functions{$_}[0], $functions{$_}[1], [ $k ]];
745 elsif ($ext_functions{$_}) {
746 push @{$ext_functions{$_}->[2]}, $k;
752 elsif ($v->{supported} =~ /^wgl$/) {
753 for (keys %{${$v->{require}}[0]->{command}}) {
754 if (defined $supported_wgl_extensions{$k}) {
755 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
762 parse_file( "gl.xml", 1 );
763 parse_file( "wgl.xml", 0 );
766 # Get the current wgl_driver.h version
768 my $wgl_version = 0;
769 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
770 while (<HEADER>)
772 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
773 $wgl_version = $1;
774 last;
776 close HEADER;
779 # Generate the wgl_driver.h file
781 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
782 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
783 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
784 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
785 print HEADER "#ifndef WINE_GLAPI\n";
786 print HEADER "#define WINE_GLAPI\n";
787 print HEADER "#endif\n\n";
789 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
791 print HEADER "struct wgl_context;\n";
792 print HEADER "struct wgl_pbuffer;\n\n";
794 print HEADER "struct opengl_funcs\n{\n";
795 print HEADER " struct\n {\n";
796 foreach (sort keys %wgl_functions)
798 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
800 print HEADER " } wgl;\n\n";
802 print HEADER " struct\n {\n";
803 foreach (sort keys %norm_functions)
805 next if $_ eq "glDebugEntry";
806 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
808 print HEADER " } gl;\n\n";
810 print HEADER " struct\n {\n";
811 foreach (sort keys %ext_functions)
813 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
815 print HEADER " } ext;\n";
816 print HEADER "};\n\n";
818 print HEADER "#define ALL_WGL_FUNCS";
819 foreach (sort keys %norm_functions)
821 next if $_ eq "glDebugEntry";
822 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
824 print HEADER "\n\n";
826 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
827 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
828 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
829 close HEADER;
832 # Generate the wgl.h file
834 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
835 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
836 print HEADER "#ifndef __WINE_WGL_H\n";
837 print HEADER "#define __WINE_WGL_H\n\n";
839 print HEADER "#ifndef GLAPIENTRY\n";
840 print HEADER "#define GLAPIENTRY __stdcall\n";
841 print HEADER "#endif\n\n";
843 foreach (sort keys %arg_conv)
845 printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
847 print HEADER "\n";
849 my $maxlen = 1;
850 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
851 foreach (sort keys %enums)
853 printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
855 print HEADER "\n";
857 foreach (sort keys %norm_functions)
859 printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
862 print HEADER "\n#endif /* __WINE_WGL_H */\n";
863 close HEADER;
866 # Now, generate the output files. First, the spec file.
868 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
870 foreach (sort keys %norm_functions) {
871 my $args=" ";
872 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
873 my $type = $norm_functions{$_}->[1]->[$i]->[0];
874 if ($type =~ /\*/) {
875 $args .= "ptr ";
876 } elsif (defined($arg_conv{$type})) {
877 $args .= "$@$arg_conv{$type}[0] ";
878 } else {
879 die "No conversion for GL type $type...\n";
882 $args = substr($args,1,-1);
883 print SPEC "@ stdcall $_($args)\n";
886 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
887 @ stdcall wglCopyContext(long long long)
888 @ stdcall wglCreateContext(long)
889 @ stdcall wglCreateLayerContext(long long)
890 @ stdcall wglDeleteContext(long)
891 @ stdcall wglDescribeLayerPlane(long long long long ptr)
892 @ stdcall wglDescribePixelFormat(long long long ptr)
893 @ stdcall wglGetCurrentContext()
894 @ stdcall wglGetCurrentDC()
895 @ stub wglGetDefaultProcAddress
896 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
897 @ stdcall wglGetPixelFormat(long)
898 @ stdcall wglGetProcAddress(str)
899 @ stdcall wglMakeCurrent(long long)
900 @ stdcall wglRealizeLayerPalette(long long long)
901 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
902 @ stdcall wglSetPixelFormat(long long ptr)
903 @ stdcall wglShareLists(long long)
904 @ stdcall wglSwapBuffers(long)
905 @ stdcall wglSwapLayerBuffers(long long)
906 @ stdcall wglUseFontBitmapsA(long long long long)
907 @ stdcall wglUseFontBitmapsW(long long long long)
908 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
909 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
912 close(SPEC);
915 # After the spec file, the opengl_norm.c file
917 open(NORM, ">$norm_file") or die "cannot create $norm_file";
918 print NORM "
919 /* Auto-generated file... Do not edit ! */
921 #include \"config.h\"
922 #include <stdarg.h>
923 #include \"winternl.h\"
924 #include \"wingdi.h\"
925 #include \"wine/wgl.h\"
926 #include \"wine/wgl_driver.h\"
927 #include \"wine/debug.h\"
929 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
932 foreach (sort keys %norm_functions) {
933 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
934 print NORM "\n$string" if $string;
937 foreach (sort keys %wgl_functions) {
938 print NORM generate_null_func($_, $wgl_functions{$_});
940 foreach (sort keys %norm_functions) {
941 print NORM generate_null_func($_, $norm_functions{$_});
943 foreach (sort keys %ext_functions) {
944 print NORM generate_null_func($_, $ext_functions{$_});
947 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
948 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
949 print NORM " },\n {\n";
950 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
951 print NORM " },\n {\n";
952 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
953 print NORM " }\n};\n";
955 close(NORM);
958 # Finally, more complex, the opengl_ext.c file
960 open(EXT, ">$ext_file") or die "cannot create $ext_file";
961 print EXT "
962 /* Auto-generated file... Do not edit ! */
964 #include \"config.h\"
965 #include <stdarg.h>
966 #include \"opengl_ext.h\"
967 #include \"winternl.h\"
968 #include \"wingdi.h\"
969 #include \"wine/wgl.h\"
970 #define WGL_WGLEXT_PROTOTYPES
971 #include \"wine/wglext.h\"
972 #include \"wine/wgl_driver.h\"
973 #include \"wine/debug.h\"
975 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
979 # The thunks themselves....
980 my $count = keys %ext_functions;
981 print EXT "const int extension_registry_size = $count;\n";
982 foreach (sort keys %ext_functions) {
983 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
984 if ($string =~ /DECLSPEC_HIDDEN/) {
985 print EXT "\n$string";
986 } else {
987 print EXT "\nstatic $string" if $string;
991 # Then the table giving the string <-> function correspondence */
992 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
993 my $i = 0;
994 foreach (sort keys %ext_functions) {
995 my $func_ref = $ext_functions{$_};
996 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
997 if ($i != $count-1) {
998 print EXT ",";
1000 $i++;
1001 print EXT "\n";
1003 print EXT "};\n";
1005 close(EXT);