opengl32: Download OpenGL registry files even if server certificate can't be verified.
[wine/multimedia.git] / dlls / opengl32 / make_opengl
blobb0b9c00a37c4d3fd8aebe55cc1c5e7c9872a10d6
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 "GLuint64EXT" => "%s,wine_dbgstr_longlong(%s)",
121 "GLint64EXT" => "%s,wine_dbgstr_longlong(%s)",
122 "GLvoid" => "(void)",
123 "_GLfuncptr" => "%p",
124 "GLDEBUGPROC" => "%p",
125 "GLDEBUGPROCARB" => "%p",
126 "GLDEBUGPROCAMD" => "%p",
127 "GLDEBUGPROCKHR" => "%p",
128 "GLvdpauSurfaceNV" => "%ld",
129 "int" => "%d",
130 "unsigned int" => "%u",
131 "UINT" => "%u",
132 "DWORD" => "%u",
133 "BOOL" => "%u",
134 "INT64" => "%s,wine_dbgstr_longlong(%s)",
135 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
136 "LPVOID" => "%p",
137 "HANDLE" => "%p",
138 "HDC" => "%p",
139 "HGLRC" => "%p",
140 "HPBUFFERARB" => "%p",
141 "HPBUFFEREXT" => "%p",
145 # This hash table gives the conversion between OpenGL types and what
146 # is used in the .spec and header files.
148 my %arg_conv =
149 ("GLbitfield" => [ "long", "unsigned int" ],
150 "GLboolean" => [ "long", "unsigned char" ],
151 "GLbyte" => [ "long", "signed char" ],
152 "GLchar" => [ "long", "char" ],
153 "GLclampd" => [ "double", "double" ],
154 "GLclampf" => [ "float", "float" ],
155 "GLclampx" => [ "long", "int" ],
156 "GLdouble" => [ "double", "double" ],
157 "GLenum" => [ "long", "unsigned int" ],
158 "GLfloat" => [ "float", "float" ],
159 "GLfixed" => [ "long", "int" ],
160 "GLint" => [ "long", "int" ],
161 "GLint64" => [ "int64", "INT64" ],
162 "GLint64EXT" => [ "int64", "INT64" ],
163 "GLintptr" => [ "long", "INT_PTR" ],
164 "GLshort" => [ "long", "short" ],
165 "GLsizei" => [ "long", "int" ],
166 "GLsizeiptr" => [ "long", "INT_PTR" ],
167 "GLstring" => [ "str", "const unsigned char *" ],
168 "GLsync" => [ "ptr", "struct __GLsync *" ],
169 "GLubyte" => [ "long", "unsigned char" ],
170 "GLuint" => [ "long", "unsigned int" ],
171 "GLuint64" => [ "int64", "UINT64" ],
172 "GLuint64EXT" => [ "int64", "UINT64" ],
173 "GLushort" => [ "long", "unsigned short" ],
174 "GLvoid" => [ "void", "void" ],
175 "GLcharARB" => [ "long", "char" ],
176 "GLhandleARB" => [ "long", "unsigned int" ],
177 "GLintptrARB" => [ "long", "INT_PTR" ],
178 "GLsizeiptrARB" => [ "long", "INT_PTR" ],
179 "GLhalfNV" => [ "long", "unsigned short" ],
180 "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
183 # Used to convert some types
185 sub ConvertType($)
187 my ($type) = @_;
189 my %hash = (
190 "struct _cl_context" => "void",
191 "struct _cl_event" => "void",
192 "HGLRC" => "struct wgl_context *",
193 "GLDEBUGPROC" => "void *",
194 "GLDEBUGPROCARB" => "void *",
195 "GLDEBUGPROCAMD" => "void *",
196 "GLDEBUGPROCKHR" => "void *",
197 "HPBUFFERARB" => "struct wgl_pbuffer *",
198 "HPBUFFEREXT" => "struct wgl_pbuffer *",
201 foreach my $org (reverse sort keys %hash) {
202 if ($type =~ /^(.*)$org(.*)$/) {
203 return "$1$hash{$org}$2";
206 return $type;
210 # Used to convert some variable names
212 sub ConvertVarName($)
214 my ($type) = @_;
216 my %hash = ( "near" => "nearParam",
217 "far" => "farParam" );
219 foreach my $org (keys %hash) {
220 if ($type =~ /^(.*)$org(.*)$/) {
221 return "$1$hash{$org}$2";
224 return $type;
228 # This functions generates the thunk for a given function.
230 sub GenerateThunk($$$$)
232 my ($name, $func_ref, $comment, $prefix) = @_;
233 my $ret = "";
234 my $call_arg = "";
235 my $trace_call_arg = "";
236 my $trace_arg = "";
238 return "" if $name eq "glDebugEntry";
239 return "" if $name eq "glGetString";
240 return "" if $func_ref->[2] && $func_ref->[2]->[0] =~ /WGL_/;
242 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
243 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
244 if ($comment eq 1) {
245 $ret .= "/***********************************************************************\n";
246 $ret .= " * $name (OPENGL32.\@)\n";
247 $ret .= " */\n";
249 $ret .= ConvertType($func_ref->[0]) . " WINAPI $name( ";
250 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
251 my $type = $func_ref->[1]->[$i]->[0];
252 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
253 $ret .= ConvertType($type) . " $name";
254 $call_arg .= $name;
255 if ($type =~ /\*/) {
256 $trace_arg .= "%p";
257 $trace_call_arg .= $name;
258 } elsif (defined $debug_conv{$type}) {
259 if ($debug_conv{$type} =~ /(.*),(.*)/)
261 $trace_arg .= $1;
262 $trace_call_arg .= sprintf $2, $name;
264 else
266 $trace_arg .= $debug_conv{$type};
267 $trace_call_arg .= $name;
270 else { printf "Unknown type %s\n", $type; }
271 if ($i+1 < @{$func_ref->[1]}) {
272 $ret .= ", ";
273 $call_arg .= ", ";
274 $trace_call_arg .= ", ";
275 $trace_arg .= ", ";
276 } else {
277 $ret .= " ";
278 $call_arg .= " ";
279 $trace_call_arg .= " ";
282 $ret .= 'void ' if (!@{$func_ref->[1]});
283 $ret .= ") {\n";
284 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
285 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
286 $ret .= " " . ConvertType($func_ref->[0]) . " ret_value;\n";
288 if ($gen_traces) {
289 $ret .= " TRACE(\"($trace_arg)\\n\"";
290 if ($trace_arg ne "") {
291 $ret .= ", $trace_call_arg";
293 $ret .= ");\n";
295 if ($gen_thread_safe) {
296 $ret .= " ENTER_GL();\n";
297 $ret .= " ";
298 if ($func_ref->[0] ne "void") {
299 $ret .= "ret_value = ";
301 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
302 $ret .= " LEAVE_GL();\n";
303 if ($func_ref->[0] ne "void") {
304 $ret .= " return ret_value;\n"
307 else {
308 $ret .= " ";
309 if ($func_ref->[0] ne "void") {
310 $ret .= "return ";
312 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
314 $ret .= "}\n";
316 # Return this string....
317 return $ret;
320 sub generate_null_func($$)
322 my ($name, $func_ref) = @_;
323 my $ret;
325 return "" if $name eq "glDebugEntry";
327 $ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
328 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
329 my $type = $func_ref->[1]->[$i]->[0];
330 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
331 $ret .= ConvertType($type) . " $name";
332 $ret .= "," if ($i+1 < @{$func_ref->[1]});
333 $ret .= " ";
335 $ret .= 'void ' if (!@{$func_ref->[1]});
336 $ret .= ") {";
337 if ($name eq "glGetError")
339 $ret .= " return GL_INVALID_OPERATION;";
341 elsif ($func_ref->[0] ne "void")
343 $ret .= " return 0;";
345 $ret .= " }\n";
346 return $ret;
349 sub get_func_proto($$$)
351 my ($format, $name, $func) = @_;
352 my $ret = sprintf "%-10s", ConvertType($func->[0]);
353 $ret .= " " . sprintf($format,$name) . "(";
354 for (my $i = 0; $i < @{$func->[1]}; $i++)
356 $ret .= ConvertType($func->[1]->[$i]->[0]);
357 $ret .= "," if ($i+1 < @{$func->[1]});
359 $ret .= "void" unless @{$func->[1]};
360 $ret .= ")";
361 return $ret;
365 # Extract and checks the number of arguments
367 if (@ARGV > 1) {
368 my $name0=$0;
369 $name0=~s%^.*/%%;
370 die "Usage: $name0 [version]\n";
372 my $version = $ARGV[0] || "1.1";
373 if ($version eq "1.0") {
374 %norm_categories = %cat_1_0;
375 } elsif ($version eq "1.1") {
376 %norm_categories = %cat_1_1;
377 } elsif ($version eq "1.2") {
378 %norm_categories = %cat_1_2;
379 } elsif ($version eq "1.3") {
380 %norm_categories = %cat_1_3;
381 } elsif ($version eq "1.4") {
382 %norm_categories = %cat_1_4;
383 } elsif ($version eq "1.5") {
384 %norm_categories = %cat_1_5;
385 } else {
386 die "Incorrect OpenGL version.\n";
390 # Fetch the registry files
392 -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";
393 -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";
397 # Then, create the list of all OpenGL functions using the registry
398 # files. This will create two hash-tables, one with all the function
399 # whose category matches the one listed in '@norm_categories', the other
400 # with all other functions.
402 # An element of the hash table is a reference to an array with these
403 # elements :
405 # - function name
407 # - return type
409 # - reference to an array giving the list of arguments (an empty array
410 # for a 'void' function).
412 # The list of arguments is itself an array of reference to arrays. Each
413 # of these arrays represents the argument type and the argument name.
415 # An example :
417 # void glBitmap( GLsizei width, GLsizei height,
418 # GLfloat xorig, GLfloat yorig,
419 # GLfloat xmove, GLfloat ymove,
420 # const GLubyte *bitmap );
422 # Would give something like that :
424 # [ "glBitmap",
425 # "void",
426 # [ [ "GLsizei", "width" ],
427 # [ "GLsizei", "height" ],
428 # [ "GLfloat", "xorig" ],
429 # [ "GLfloat", "yorig" ],
430 # [ "GLfloat", "xmove" ],
431 # [ "GLfloat", "ymove" ],
432 # [ "GLubyte *", "bitmap"] ] ];
434 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
435 [ "GLint", "unknown2" ]] ] );
438 # This stores various extensions NOT part of the GL extension registry but still
439 # implemented by most OpenGL libraries out there...
442 my %ext_functions =
444 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], [ "GL_KTX_buffer_region" ] ],
445 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
446 [ "GLint", "x" ],
447 [ "GLint", "y" ],
448 [ "GLsizei", "width" ],
449 [ "GLsizei", "height" ] ], [ "GL_KTX_buffer_region" ] ],
450 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
451 [ "GLint", "x" ],
452 [ "GLint", "y" ],
453 [ "GLsizei", "width" ],
454 [ "GLsizei", "height" ],
455 [ "GLint", "xDest" ],
456 [ "GLint", "yDest" ] ], [ "GL_KTX_buffer_region" ] ],
457 "glBufferRegionEnabled" => [ "GLuint", [ ], [ "GL_KTX_buffer_region" ] ],
458 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], [ "GL_KTX_buffer_region" ] ],
459 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
460 [ "GLfloat", "s" ],
461 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
462 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
463 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
464 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
465 [ "GLdouble", "s" ] ], [ "GL_SGIS_multitexture" ] ],
466 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
467 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
468 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
469 [ "GLfloat", "s" ] ], [ "GL_SGIS_multitexture" ] ],
470 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
471 [ "const GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
472 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
473 [ "GLint", "s" ] ], [ "GL_SGIS_multitexture" ] ],
474 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
475 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
476 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
477 [ "GLshort", "s" ] ], [ "GL_SGIS_multitexture" ] ],
478 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
479 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
480 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
481 [ "GLdouble", "s"],
482 [ "GLdouble", "t" ] ], [ "GL_SGIS_multitexture" ] ],
483 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
484 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
485 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
486 [ "GLfloat", "s" ],
487 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
488 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
489 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
490 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
491 [ "GLint", "s" ],
492 [ "GLint", "t" ] ], [ "GL_SGIS_multitexture" ] ],
493 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
494 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
495 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
496 [ "GLshort", "s" ],
497 [ "GLshort", "t" ] ], [ "GL_SGIS_multitexture" ] ],
498 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
499 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
500 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
501 [ "GLdouble", "s" ],
502 [ "GLdouble", "t" ],
503 [ "GLdouble", "r" ] ], [ "GL_SGIS_multitexture" ] ],
504 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
505 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
506 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
507 [ "GLfloat", "s" ],
508 [ "GLfloat", "t" ],
509 [ "GLfloat", "r" ] ], [ "GL_SGIS_multitexture" ] ],
510 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
511 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
512 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
513 [ "GLint", "s" ],
514 [ "GLint", "t" ],
515 [ "GLint", "r" ] ], [ "GL_SGIS_multitexture" ] ],
516 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
517 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
518 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
519 [ "GLshort", "s" ],
520 [ "GLshort", "t" ],
521 [ "GLshort", "r" ] ], [ "GL_SGIS_multitexture" ] ],
522 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
523 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
524 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
525 [ "GLdouble", "s" ],
526 [ "GLdouble", "t" ],
527 [ "GLdouble", "r" ],
528 [ "GLdouble", "q" ] ], [ "GL_SGIS_multitexture" ] ],
529 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
530 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
531 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLfloat", "s" ],
533 [ "GLfloat", "t" ],
534 [ "GLfloat", "r" ],
535 [ "GLfloat", "q" ] ], [ "GL_SGIS_multitexture" ] ],
536 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
538 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
539 [ "GLint", "s" ],
540 [ "GLint", "t" ],
541 [ "GLint", "r" ],
542 [ "GLint", "q" ] ], [ "GL_SGIS_multitexture" ] ],
543 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
544 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
545 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
546 [ "GLshort", "s" ],
547 [ "GLshort", "t" ],
548 [ "GLshort", "r" ],
549 [ "GLshort", "q" ] ], [ "GL_SGIS_multitexture" ] ],
550 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
551 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
552 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
553 [ "GLint", "size" ],
554 [ "GLenum", "type" ],
555 [ "GLsizei", "stride" ],
556 [ "GLvoid *", "pointer" ] ], [ "GL_SGIS_multitexture" ] ],
557 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
558 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
559 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], [ "GL_ATI_vertex_array_object" ] ],
560 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
561 [ "int", "format" ] ], [ "WGL_WINE_pixel_format_passthrough" ] ],
565 my %wgl_functions =
567 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
568 [ "struct wgl_context *", "dst" ],
569 [ "UINT", "mask" ] ] ],
570 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
571 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
572 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
573 [ "INT", "format" ],
574 [ "UINT", "size" ],
575 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
576 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
577 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
578 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
579 [ "struct wgl_context *", "context" ] ] ],
580 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
581 [ "INT", "format" ],
582 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
583 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
584 [ "struct wgl_context *", "dst" ] ] ],
585 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
588 my %supported_wgl_extensions =
590 "WGL_ARB_create_context" => 1,
591 "WGL_ARB_extensions_string" => 1,
592 "WGL_ARB_make_current_read" => 1,
593 "WGL_ARB_pbuffer" => 1,
594 "WGL_ARB_pixel_format" => 1,
595 "WGL_ARB_render_texture" => 1,
596 "WGL_EXT_extensions_string" => 1,
597 "WGL_EXT_swap_control" => 1,
598 "WGL_NV_vertex_array_range" => 1,
599 "WGL_WINE_pixel_format_passthrough" => 1,
602 my %enums = ();
604 sub parse_variable($)
606 my $p = shift;
607 my $ptype = '';
608 my $pname = '';
609 my $pnamebefore = '';
610 my $pnameafter = '';
612 while (my ($k, $v) = each(%$p)){
613 if ($k eq 'ptype') {
614 $ptype = ${$v}[0];
615 } elsif ($k eq 'name') {
616 $pname = ${$v}[0];
617 } elsif ($k eq 'content') {
618 if (ref($v) eq 'ARRAY') {
619 my @n = @{$v};
620 $pnamebefore = $n[0];
621 $pnameafter = $n[1] if (@n > 0);
622 } else {
623 $pnameafter = $v;
627 $ptype = $pnamebefore . $ptype . $pnameafter;
628 $ptype =~ s/ \*/\*/g;
629 $ptype =~ s/ $//g;
630 return [ $ptype, $pname ];
633 sub parse_file($$)
635 my ($file, $generate_enums) = @_;
636 my $xml = new XML::Simple;
637 my $data = $xml->XMLin($file, ForceArray => 1);
638 my %functions;
640 # save all functions
641 for my $command ( @{${$data->{commands}}[0]->{'command'}} ) {
642 my $name = '';
643 my $ret = '';
644 my $params = [];
645 my @alias = '';
646 while (my ($k, $v) = each(%$command)){
647 if ($k eq 'param') {
648 push(@$params, parse_variable($_)) for (@{$v});
649 } elsif ($k eq 'proto') {
650 ($ret, $name) = @{parse_variable(${$v}[0])};
653 $functions{$name} = [ $ret, $params ];
656 # save all enums (only GL)
657 if ($generate_enums) {
658 for my $enum ( @{$data->{'enums'}} ) {
659 if (ref($enum->{'enum'}) eq "HASH") {
660 while (my ($k, $v) = each(%{$enum->{'enum'}})){
661 $enums{$k} = $v->{'value'};
667 # generate norm functions
668 while (my ($k, $v) = each(%{$data->{feature}})) {
669 if ($norm_categories{$k}) {
670 for my $req (@{$v->{require}}) {
671 for(keys %{$req->{command}}) {
672 $norm_functions{$_} = $functions{$_};
678 # generate extension functions from norm functions, if they are newer than the category
679 while (my ($k, $v) = each(%{$data->{feature}})) {
680 if (!$norm_categories{$k} && $v->{api} =~ /^gl(\||$)/)
682 for my $req (@{$v->{require}}) {
683 for (keys %{$req->{command}}) {
684 if (!$norm_functions{$_}) {
685 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
692 # generate extension functions
693 while (my ($k, $v) = each(%{${$data->{extensions}}[0]->{extension}})) {
694 if ($v->{supported} =~ /^gl(\||$)/) {
695 for my $req (@{$v->{require}}) {
696 if (!defined $req->{api} || $req->{api} =~ /^gl(\||$)/) {
697 for (keys %{$req->{command}}) {
698 if (!$ext_functions{$_} && !$norm_functions{$_}) {
699 $ext_functions{$_} = [$functions{$_}[0], $functions{$_}[1], [ $k ]];
701 elsif ($ext_functions{$_}) {
702 push @{$ext_functions{$_}->[2]}, $k;
708 elsif ($v->{supported} =~ /^wgl$/) {
709 for (keys %{${$v->{require}}[0]->{command}}) {
710 if (defined $supported_wgl_extensions{$k}) {
711 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
718 parse_file( "gl.xml", 1 );
719 parse_file( "wgl.xml", 0 );
722 # Get the current wgl_driver.h version
724 my $wgl_version = 0;
725 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
726 while (<HEADER>)
728 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
729 $wgl_version = $1;
730 last;
732 close HEADER;
735 # Generate the wgl_driver.h file
737 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
738 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
739 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
740 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
741 print HEADER "#ifndef WINE_GLAPI\n";
742 print HEADER "#define WINE_GLAPI\n";
743 print HEADER "#endif\n\n";
745 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
747 print HEADER "struct wgl_context;\n";
748 print HEADER "struct wgl_pbuffer;\n\n";
750 print HEADER "struct opengl_funcs\n{\n";
751 print HEADER " struct\n {\n";
752 foreach (sort keys %wgl_functions)
754 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
756 print HEADER " } wgl;\n\n";
758 print HEADER " struct\n {\n";
759 foreach (sort keys %norm_functions)
761 next if $_ eq "glDebugEntry";
762 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
764 print HEADER " } gl;\n\n";
766 print HEADER " struct\n {\n";
767 foreach (sort keys %ext_functions)
769 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
771 print HEADER " } ext;\n";
772 print HEADER "};\n\n";
774 print HEADER "#define ALL_WGL_FUNCS";
775 foreach (sort keys %norm_functions)
777 next if $_ eq "glDebugEntry";
778 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
780 print HEADER "\n\n";
782 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
783 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
784 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
785 close HEADER;
788 # Generate the wgl.h file
790 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
791 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
792 print HEADER "#ifndef __WINE_WGL_H\n";
793 print HEADER "#define __WINE_WGL_H\n\n";
795 print HEADER "#ifndef GLAPIENTRY\n";
796 print HEADER "#define GLAPIENTRY __stdcall\n";
797 print HEADER "#endif\n\n";
799 foreach (sort keys %arg_conv)
801 printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
803 print HEADER "\n";
805 my $maxlen = 1;
806 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
807 foreach (sort keys %enums)
809 printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
811 print HEADER "\n";
813 foreach (sort keys %norm_functions)
815 printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
818 print HEADER "\n#endif /* __WINE_WGL_H */\n";
819 close HEADER;
822 # Now, generate the output files. First, the spec file.
824 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
826 foreach (sort keys %norm_functions) {
827 my $args=" ";
828 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
829 my $type = $norm_functions{$_}->[1]->[$i]->[0];
830 if ($type =~ /\*/) {
831 $args .= "ptr ";
832 } elsif (defined($arg_conv{$type})) {
833 $args .= "$@$arg_conv{$type}[0] ";
834 } else {
835 die "No conversion for GL type $type...\n";
838 $args = substr($args,1,-1);
839 print SPEC "@ stdcall $_($args)\n";
842 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
843 @ stdcall wglCopyContext(long long long)
844 @ stdcall wglCreateContext(long)
845 @ stdcall wglCreateLayerContext(long long)
846 @ stdcall wglDeleteContext(long)
847 @ stdcall wglDescribeLayerPlane(long long long long ptr)
848 @ stdcall wglDescribePixelFormat(long long long ptr)
849 @ stdcall wglGetCurrentContext()
850 @ stdcall wglGetCurrentDC()
851 @ stub wglGetDefaultProcAddress
852 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
853 @ stdcall wglGetPixelFormat(long)
854 @ stdcall wglGetProcAddress(str)
855 @ stdcall wglMakeCurrent(long long)
856 @ stdcall wglRealizeLayerPalette(long long long)
857 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
858 @ stdcall wglSetPixelFormat(long long ptr)
859 @ stdcall wglShareLists(long long)
860 @ stdcall wglSwapBuffers(long)
861 @ stdcall wglSwapLayerBuffers(long long)
862 @ stdcall wglUseFontBitmapsA(long long long long)
863 @ stdcall wglUseFontBitmapsW(long long long long)
864 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
865 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
868 close(SPEC);
871 # After the spec file, the opengl_norm.c file
873 open(NORM, ">$norm_file") or die "cannot create $norm_file";
874 print NORM "
875 /* Auto-generated file... Do not edit ! */
877 #include \"config.h\"
878 #include <stdarg.h>
879 #include \"winternl.h\"
880 #include \"wingdi.h\"
881 #include \"wine/wgl.h\"
882 #include \"wine/wgl_driver.h\"
883 #include \"wine/debug.h\"
885 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
888 foreach (sort keys %norm_functions) {
889 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
890 print NORM "\n$string" if $string;
893 foreach (sort keys %wgl_functions) {
894 print NORM generate_null_func($_, $wgl_functions{$_});
896 foreach (sort keys %norm_functions) {
897 print NORM generate_null_func($_, $norm_functions{$_});
899 foreach (sort keys %ext_functions) {
900 print NORM generate_null_func($_, $ext_functions{$_});
903 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
904 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
905 print NORM " },\n {\n";
906 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
907 print NORM " },\n {\n";
908 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
909 print NORM " }\n};\n";
911 close(NORM);
914 # Finally, more complex, the opengl_ext.c file
916 open(EXT, ">$ext_file") or die "cannot create $ext_file";
917 print EXT "
918 /* Auto-generated file... Do not edit ! */
920 #include \"config.h\"
921 #include <stdarg.h>
922 #include \"opengl_ext.h\"
923 #include \"winternl.h\"
924 #include \"wingdi.h\"
925 #include \"wine/wgl.h\"
926 #define WGL_WGLEXT_PROTOTYPES
927 #include \"wine/wglext.h\"
928 #include \"wine/wgl_driver.h\"
929 #include \"wine/debug.h\"
931 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
935 # The thunks themselves....
936 my $count = keys %ext_functions;
937 print EXT "const int extension_registry_size = $count;\n";
938 foreach (sort keys %ext_functions) {
939 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
940 print EXT "\nstatic $string" if $string;
943 # Then the table giving the string <-> function correspondence */
944 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
945 my $i = 0;
946 foreach (sort keys %ext_functions) {
947 my $func_ref = $ext_functions{$_};
948 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
949 if ($i != $count-1) {
950 print EXT ",";
952 $i++;
953 print EXT "\n";
955 print EXT "};\n";
957 close(EXT);