user32/tests: Test DDE end to end with Chinese text that starts with Latin characters.
[wine.git] / dlls / opengl32 / make_opengl
bloba7d656da80ea89bbd1d9e19e6de297908d105009
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" ] ],
580 my %wgl_functions =
582 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
583 [ "struct wgl_context *", "dst" ],
584 [ "UINT", "mask" ] ] ],
585 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
586 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
587 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
588 [ "INT", "format" ],
589 [ "UINT", "size" ],
590 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
591 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
592 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
593 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
594 [ "struct wgl_context *", "context" ] ] ],
595 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
596 [ "INT", "format" ],
597 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
598 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
599 [ "struct wgl_context *", "dst" ] ] ],
600 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
603 my %supported_wgl_extensions =
605 "WGL_ARB_create_context" => 1,
606 "WGL_ARB_extensions_string" => 1,
607 "WGL_ARB_make_current_read" => 1,
608 "WGL_ARB_pbuffer" => 1,
609 "WGL_ARB_pixel_format" => 1,
610 "WGL_ARB_render_texture" => 1,
611 "WGL_EXT_extensions_string" => 1,
612 "WGL_EXT_swap_control" => 1,
613 "WGL_NV_vertex_array_range" => 1,
614 "WGL_WINE_pixel_format_passthrough" => 1,
617 my %enums = ();
619 sub parse_variable($)
621 my $p = shift;
622 my $ptype = '';
623 my $pname = '';
624 my $pnamebefore = '';
625 my $pnameafter = '';
627 while (my ($k, $v) = each(%$p)){
628 if ($k eq 'ptype') {
629 $ptype = ${$v}[0];
630 } elsif ($k eq 'name') {
631 $pname = ${$v}[0];
632 } elsif ($k eq 'content') {
633 if (ref($v) eq 'ARRAY') {
634 my @n = @{$v};
635 $pnamebefore = $n[0];
636 $pnameafter = $n[1] if (@n > 0);
637 } elsif ($v eq 'const ') {
638 $pnamebefore = $v;
639 } else {
640 $pnameafter = $v;
644 $ptype = $pnamebefore . $ptype . $pnameafter;
645 $ptype =~ s/ \*/\*/g;
646 $ptype =~ s/ $//g;
647 return [ $ptype, $pname ];
650 sub parse_file($$)
652 my ($file, $generate_enums) = @_;
653 my $xml = new XML::Simple;
654 my $data = $xml->XMLin($file, ForceArray => 1);
655 my %functions;
657 # save all functions
658 for my $command ( @{${$data->{commands}}[0]->{'command'}} ) {
659 my $name = '';
660 my $ret = '';
661 my $params = [];
662 my @alias = '';
663 while (my ($k, $v) = each(%$command)){
664 if ($k eq 'param') {
665 push(@$params, parse_variable($_)) for (@{$v});
666 } elsif ($k eq 'proto') {
667 ($ret, $name) = @{parse_variable(${$v}[0])};
670 $functions{$name} = [ $ret, $params ];
673 # save all enums (only GL)
674 if ($generate_enums) {
675 for my $enum ( @{$data->{'enums'}} ) {
676 if (ref($enum->{'enum'}) eq "HASH") {
677 while (my ($k, $v) = each(%{$enum->{'enum'}})){
678 $enums{$k} = $v->{'value'};
684 # generate norm functions
685 while (my ($k, $v) = each(%{$data->{feature}})) {
686 if ($norm_categories{$k}) {
687 for my $req (@{$v->{require}}) {
688 for(keys %{$req->{command}}) {
689 $norm_functions{$_} = $functions{$_};
695 # generate extension functions from norm functions, if they are newer than the category
696 my %features = %{$data->{feature}};
697 foreach (sort keys %features) {
698 my ($k, $v) = %features{$_};
699 if (!$norm_categories{$k} && $v->{api} =~ /^gl(\||$)/)
701 for my $req (@{$v->{require}}) {
702 for (keys %{$req->{command}}) {
703 if (!$ext_functions{$_} && !$norm_functions{$_}) {
704 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
711 # generate extension functions
712 while (my ($k, $v) = each(%{${$data->{extensions}}[0]->{extension}})) {
713 if ($v->{supported} =~ /^gl(\||$)/) {
714 for my $req (@{$v->{require}}) {
715 if (!defined $req->{api} || $req->{api} =~ /^gl(\||$)/) {
716 for (keys %{$req->{command}}) {
717 if (!$ext_functions{$_} && !$norm_functions{$_}) {
718 $ext_functions{$_} = [$functions{$_}[0], $functions{$_}[1], [ $k ]];
720 elsif ($ext_functions{$_}) {
721 push @{$ext_functions{$_}->[2]}, $k;
727 elsif ($v->{supported} =~ /^wgl$/) {
728 for (keys %{${$v->{require}}[0]->{command}}) {
729 if (defined $supported_wgl_extensions{$k}) {
730 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
737 parse_file( "gl.xml", 1 );
738 parse_file( "wgl.xml", 0 );
741 # Get the current wgl_driver.h version
743 my $wgl_version = 0;
744 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
745 while (<HEADER>)
747 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
748 $wgl_version = $1;
749 last;
751 close HEADER;
754 # Generate the wgl_driver.h file
756 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
757 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
758 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
759 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
760 print HEADER "#ifndef WINE_GLAPI\n";
761 print HEADER "#define WINE_GLAPI\n";
762 print HEADER "#endif\n\n";
764 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
766 print HEADER "struct wgl_context;\n";
767 print HEADER "struct wgl_pbuffer;\n\n";
769 print HEADER "struct opengl_funcs\n{\n";
770 print HEADER " struct\n {\n";
771 foreach (sort keys %wgl_functions)
773 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
775 print HEADER " } wgl;\n\n";
777 print HEADER " struct\n {\n";
778 foreach (sort keys %norm_functions)
780 next if $_ eq "glDebugEntry";
781 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
783 print HEADER " } gl;\n\n";
785 print HEADER " struct\n {\n";
786 foreach (sort keys %ext_functions)
788 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
790 print HEADER " } ext;\n";
791 print HEADER "};\n\n";
793 print HEADER "#define ALL_WGL_FUNCS";
794 foreach (sort keys %norm_functions)
796 next if $_ eq "glDebugEntry";
797 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
799 print HEADER "\n\n";
801 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
802 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
803 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
804 close HEADER;
807 # Generate the wgl.h file
809 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
810 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
811 print HEADER "#ifndef __WINE_WGL_H\n";
812 print HEADER "#define __WINE_WGL_H\n\n";
814 print HEADER "#ifndef GLAPIENTRY\n";
815 print HEADER "#define GLAPIENTRY __stdcall\n";
816 print HEADER "#endif\n\n";
818 foreach (sort keys %arg_conv)
820 printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
822 print HEADER "\n";
824 my $maxlen = 1;
825 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
826 foreach (sort keys %enums)
828 printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
830 print HEADER "\n";
832 foreach (sort keys %norm_functions)
834 printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
837 print HEADER "\n#endif /* __WINE_WGL_H */\n";
838 close HEADER;
841 # Now, generate the output files. First, the spec file.
843 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
845 foreach (sort keys %norm_functions) {
846 my $args=" ";
847 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
848 my $type = $norm_functions{$_}->[1]->[$i]->[0];
849 if ($type =~ /\*/) {
850 $args .= "ptr ";
851 } elsif (defined($arg_conv{$type})) {
852 $args .= "$@$arg_conv{$type}[0] ";
853 } else {
854 die "No conversion for GL type $type...\n";
857 $args = substr($args,1,-1);
858 print SPEC "@ stdcall $_($args)\n";
861 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
862 @ stdcall wglCopyContext(long long long)
863 @ stdcall wglCreateContext(long)
864 @ stdcall wglCreateLayerContext(long long)
865 @ stdcall wglDeleteContext(long)
866 @ stdcall wglDescribeLayerPlane(long long long long ptr)
867 @ stdcall wglDescribePixelFormat(long long long ptr)
868 @ stdcall wglGetCurrentContext()
869 @ stdcall wglGetCurrentDC()
870 @ stub wglGetDefaultProcAddress
871 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
872 @ stdcall wglGetPixelFormat(long)
873 @ stdcall wglGetProcAddress(str)
874 @ stdcall wglMakeCurrent(long long)
875 @ stdcall wglRealizeLayerPalette(long long long)
876 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
877 @ stdcall wglSetPixelFormat(long long ptr)
878 @ stdcall wglShareLists(long long)
879 @ stdcall wglSwapBuffers(long)
880 @ stdcall wglSwapLayerBuffers(long long)
881 @ stdcall wglUseFontBitmapsA(long long long long)
882 @ stdcall wglUseFontBitmapsW(long long long long)
883 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
884 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
887 close(SPEC);
890 # After the spec file, the opengl_norm.c file
892 open(NORM, ">$norm_file") or die "cannot create $norm_file";
893 print NORM "
894 /* Auto-generated file... Do not edit ! */
896 #include \"config.h\"
897 #include <stdarg.h>
898 #include \"winternl.h\"
899 #include \"wingdi.h\"
900 #include \"wine/wgl.h\"
901 #include \"wine/wgl_driver.h\"
902 #include \"wine/debug.h\"
904 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
907 foreach (sort keys %norm_functions) {
908 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
909 print NORM "\n$string" if $string;
912 foreach (sort keys %wgl_functions) {
913 print NORM generate_null_func($_, $wgl_functions{$_});
915 foreach (sort keys %norm_functions) {
916 print NORM generate_null_func($_, $norm_functions{$_});
918 foreach (sort keys %ext_functions) {
919 print NORM generate_null_func($_, $ext_functions{$_});
922 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
923 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
924 print NORM " },\n {\n";
925 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
926 print NORM " },\n {\n";
927 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
928 print NORM " }\n};\n";
930 close(NORM);
933 # Finally, more complex, the opengl_ext.c file
935 open(EXT, ">$ext_file") or die "cannot create $ext_file";
936 print EXT "
937 /* Auto-generated file... Do not edit ! */
939 #include \"config.h\"
940 #include <stdarg.h>
941 #include \"opengl_ext.h\"
942 #include \"winternl.h\"
943 #include \"wingdi.h\"
944 #include \"wine/wgl.h\"
945 #define WGL_WGLEXT_PROTOTYPES
946 #include \"wine/wglext.h\"
947 #include \"wine/wgl_driver.h\"
948 #include \"wine/debug.h\"
950 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
954 # The thunks themselves....
955 my $count = keys %ext_functions;
956 print EXT "const int extension_registry_size = $count;\n";
957 foreach (sort keys %ext_functions) {
958 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
959 if ($string =~ /DECLSPEC_HIDDEN/) {
960 print EXT "\n$string";
961 } else {
962 print EXT "\nstatic $string" if $string;
966 # Then the table giving the string <-> function correspondence */
967 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
968 my $i = 0;
969 foreach (sort keys %ext_functions) {
970 my $func_ref = $ext_functions{$_};
971 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
972 if ($i != $count-1) {
973 print EXT ",";
975 $i++;
976 print EXT "\n";
978 print EXT "};\n";
980 close(EXT);