d3d11: Add ID3D11Texture2D stub interface.
[wine.git] / dlls / opengl32 / make_opengl
blob2b15f58dad7198a04dafbcf95baa811f136ccf31
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 "glGetIntegerv";
240 return "" if $name eq "glGetString";
241 return "" if $func_ref->[2] && $func_ref->[2]->[0] =~ /WGL_/;
243 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
244 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
245 if ($comment eq 1) {
246 $ret .= "/***********************************************************************\n";
247 $ret .= " * $name (OPENGL32.\@)\n";
248 $ret .= " */\n";
250 $ret .= ConvertType($func_ref->[0]) . " WINAPI $name( ";
251 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
252 my $type = $func_ref->[1]->[$i]->[0];
253 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
254 my ($base_type, $type_specifier, $name_specifier) = ($type, $type, $name);
255 if ($type =~ /(.*) (.*)/) {
256 $base_type = $2;
257 } elsif ($type =~ /(.*)(\[.*)/) {
258 $base_type = $1;
259 $type_specifier = $1;
260 $name_specifier = $name . $2
262 $ret .= ConvertType($type_specifier) . " $name_specifier";
263 $call_arg .= $name;
264 if ($type =~ /\*/ || $type =~ /\[/) {
265 $trace_arg .= "%p";
266 $trace_call_arg .= $name;
267 } elsif (defined $debug_conv{$base_type}) {
268 if ($debug_conv{$base_type} =~ /(.*),(.*)/) {
269 $trace_arg .= $1;
270 $trace_call_arg .= sprintf $2, $name;
271 } else {
272 $trace_arg .= $debug_conv{$base_type};
273 $trace_call_arg .= $name;
276 else { printf "Unknown type %s\n", $type; }
277 if ($i+1 < @{$func_ref->[1]}) {
278 $ret .= ", ";
279 $call_arg .= ", ";
280 $trace_call_arg .= ", ";
281 $trace_arg .= ", ";
282 } else {
283 $ret .= " ";
284 $call_arg .= " ";
285 $trace_call_arg .= " ";
288 $ret .= 'void ' if (!@{$func_ref->[1]});
289 return "$ret) DECLSPEC_HIDDEN;\n" if $name eq "glGetStringi";
290 $ret .= ") {\n";
291 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
292 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
293 $ret .= " " . ConvertType($func_ref->[0]) . " ret_value;\n";
295 if ($gen_traces) {
296 $ret .= " TRACE(\"($trace_arg)\\n\"";
297 if ($trace_arg ne "") {
298 $ret .= ", $trace_call_arg";
300 $ret .= ");\n";
302 if ($gen_thread_safe) {
303 $ret .= " ENTER_GL();\n";
304 $ret .= " ";
305 if ($func_ref->[0] ne "void") {
306 $ret .= "ret_value = ";
308 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
309 $ret .= " LEAVE_GL();\n";
310 if ($func_ref->[0] ne "void") {
311 $ret .= " return ret_value;\n"
314 else {
315 $ret .= " ";
316 if ($func_ref->[0] ne "void") {
317 $ret .= "return ";
319 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
321 $ret .= "}\n";
323 # Return this string....
324 return $ret;
327 sub generate_null_func($$)
329 my ($name, $func_ref) = @_;
330 my $ret;
332 return "" if $name eq "glDebugEntry";
334 $ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
335 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
336 my $type = $func_ref->[1]->[$i]->[0];
337 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
338 my $base_type;
339 if ($type =~ /(.*)(\[.*)/) {
340 $base_type = $1;
341 $name .= $2;
342 } else {
343 $base_type = $type;
345 $ret .= ConvertType($base_type) . " $name";
346 $ret .= "," if ($i+1 < @{$func_ref->[1]});
347 $ret .= " ";
349 $ret .= 'void ' if (!@{$func_ref->[1]});
350 $ret .= ") {";
351 if ($name eq "glGetError")
353 $ret .= " return GL_INVALID_OPERATION;";
355 elsif ($func_ref->[0] ne "void")
357 $ret .= " return 0;";
359 $ret .= " }\n";
360 return $ret;
363 sub get_func_proto($$$)
365 my ($format, $name, $func) = @_;
366 my $ret = sprintf "%-10s", ConvertType($func->[0]);
367 $ret .= " " . sprintf($format,$name) . "(";
368 for (my $i = 0; $i < @{$func->[1]}; $i++)
370 $ret .= ConvertType($func->[1]->[$i]->[0]);
371 $ret .= "," if ($i+1 < @{$func->[1]});
373 $ret .= "void" unless @{$func->[1]};
374 $ret .= ")";
375 return $ret;
379 # Extract and checks the number of arguments
381 if (@ARGV > 1) {
382 my $name0=$0;
383 $name0=~s%^.*/%%;
384 die "Usage: $name0 [version]\n";
386 my $version = $ARGV[0] || "1.1";
387 if ($version eq "1.0") {
388 %norm_categories = %cat_1_0;
389 } elsif ($version eq "1.1") {
390 %norm_categories = %cat_1_1;
391 } elsif ($version eq "1.2") {
392 %norm_categories = %cat_1_2;
393 } elsif ($version eq "1.3") {
394 %norm_categories = %cat_1_3;
395 } elsif ($version eq "1.4") {
396 %norm_categories = %cat_1_4;
397 } elsif ($version eq "1.5") {
398 %norm_categories = %cat_1_5;
399 } else {
400 die "Incorrect OpenGL version.\n";
404 # Fetch the registry files
406 -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";
407 -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";
411 # Then, create the list of all OpenGL functions using the registry
412 # files. This will create two hash-tables, one with all the function
413 # whose category matches the one listed in '@norm_categories', the other
414 # with all other functions.
416 # An element of the hash table is a reference to an array with these
417 # elements :
419 # - function name
421 # - return type
423 # - reference to an array giving the list of arguments (an empty array
424 # for a 'void' function).
426 # The list of arguments is itself an array of reference to arrays. Each
427 # of these arrays represents the argument type and the argument name.
429 # An example :
431 # void glBitmap( GLsizei width, GLsizei height,
432 # GLfloat xorig, GLfloat yorig,
433 # GLfloat xmove, GLfloat ymove,
434 # const GLubyte *bitmap );
436 # Would give something like that :
438 # [ "glBitmap",
439 # "void",
440 # [ [ "GLsizei", "width" ],
441 # [ "GLsizei", "height" ],
442 # [ "GLfloat", "xorig" ],
443 # [ "GLfloat", "yorig" ],
444 # [ "GLfloat", "xmove" ],
445 # [ "GLfloat", "ymove" ],
446 # [ "GLubyte *", "bitmap"] ] ];
448 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
449 [ "GLint", "unknown2" ]] ] );
452 # This stores various extensions NOT part of the GL extension registry but still
453 # implemented by most OpenGL libraries out there...
456 my %ext_functions =
458 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], [ "GL_KTX_buffer_region" ] ],
459 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
460 [ "GLint", "x" ],
461 [ "GLint", "y" ],
462 [ "GLsizei", "width" ],
463 [ "GLsizei", "height" ] ], [ "GL_KTX_buffer_region" ] ],
464 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
465 [ "GLint", "x" ],
466 [ "GLint", "y" ],
467 [ "GLsizei", "width" ],
468 [ "GLsizei", "height" ],
469 [ "GLint", "xDest" ],
470 [ "GLint", "yDest" ] ], [ "GL_KTX_buffer_region" ] ],
471 "glBufferRegionEnabled" => [ "GLuint", [ ], [ "GL_KTX_buffer_region" ] ],
472 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], [ "GL_KTX_buffer_region" ] ],
473 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
474 [ "GLfloat", "s" ],
475 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
476 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
477 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
478 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
479 [ "GLdouble", "s" ] ], [ "GL_SGIS_multitexture" ] ],
480 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
481 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
482 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
483 [ "GLfloat", "s" ] ], [ "GL_SGIS_multitexture" ] ],
484 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
485 [ "const GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
486 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
487 [ "GLint", "s" ] ], [ "GL_SGIS_multitexture" ] ],
488 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
489 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
490 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
491 [ "GLshort", "s" ] ], [ "GL_SGIS_multitexture" ] ],
492 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
493 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
494 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
495 [ "GLdouble", "s"],
496 [ "GLdouble", "t" ] ], [ "GL_SGIS_multitexture" ] ],
497 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
498 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
499 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
500 [ "GLfloat", "s" ],
501 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
502 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
503 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
504 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
505 [ "GLint", "s" ],
506 [ "GLint", "t" ] ], [ "GL_SGIS_multitexture" ] ],
507 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
508 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
509 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
510 [ "GLshort", "s" ],
511 [ "GLshort", "t" ] ], [ "GL_SGIS_multitexture" ] ],
512 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
513 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
514 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
515 [ "GLdouble", "s" ],
516 [ "GLdouble", "t" ],
517 [ "GLdouble", "r" ] ], [ "GL_SGIS_multitexture" ] ],
518 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
519 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
520 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
521 [ "GLfloat", "s" ],
522 [ "GLfloat", "t" ],
523 [ "GLfloat", "r" ] ], [ "GL_SGIS_multitexture" ] ],
524 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
525 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
526 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
527 [ "GLint", "s" ],
528 [ "GLint", "t" ],
529 [ "GLint", "r" ] ], [ "GL_SGIS_multitexture" ] ],
530 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
531 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
532 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
533 [ "GLshort", "s" ],
534 [ "GLshort", "t" ],
535 [ "GLshort", "r" ] ], [ "GL_SGIS_multitexture" ] ],
536 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
538 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
539 [ "GLdouble", "s" ],
540 [ "GLdouble", "t" ],
541 [ "GLdouble", "r" ],
542 [ "GLdouble", "q" ] ], [ "GL_SGIS_multitexture" ] ],
543 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
544 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
545 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
546 [ "GLfloat", "s" ],
547 [ "GLfloat", "t" ],
548 [ "GLfloat", "r" ],
549 [ "GLfloat", "q" ] ], [ "GL_SGIS_multitexture" ] ],
550 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
551 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
552 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
553 [ "GLint", "s" ],
554 [ "GLint", "t" ],
555 [ "GLint", "r" ],
556 [ "GLint", "q" ] ], [ "GL_SGIS_multitexture" ] ],
557 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
558 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
559 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
560 [ "GLshort", "s" ],
561 [ "GLshort", "t" ],
562 [ "GLshort", "r" ],
563 [ "GLshort", "q" ] ], [ "GL_SGIS_multitexture" ] ],
564 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
565 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
566 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
567 [ "GLint", "size" ],
568 [ "GLenum", "type" ],
569 [ "GLsizei", "stride" ],
570 [ "GLvoid *", "pointer" ] ], [ "GL_SGIS_multitexture" ] ],
571 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
572 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
573 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], [ "GL_ATI_vertex_array_object" ] ],
574 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
575 [ "int", "format" ] ], [ "WGL_WINE_pixel_format_passthrough" ] ],
579 my %wgl_functions =
581 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
582 [ "struct wgl_context *", "dst" ],
583 [ "UINT", "mask" ] ] ],
584 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
585 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
586 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
587 [ "INT", "format" ],
588 [ "UINT", "size" ],
589 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
590 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
591 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
592 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
593 [ "struct wgl_context *", "context" ] ] ],
594 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
595 [ "INT", "format" ],
596 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
597 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
598 [ "struct wgl_context *", "dst" ] ] ],
599 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
602 my %supported_wgl_extensions =
604 "WGL_ARB_create_context" => 1,
605 "WGL_ARB_extensions_string" => 1,
606 "WGL_ARB_make_current_read" => 1,
607 "WGL_ARB_pbuffer" => 1,
608 "WGL_ARB_pixel_format" => 1,
609 "WGL_ARB_render_texture" => 1,
610 "WGL_EXT_extensions_string" => 1,
611 "WGL_EXT_swap_control" => 1,
612 "WGL_NV_vertex_array_range" => 1,
613 "WGL_WINE_pixel_format_passthrough" => 1,
616 my %enums = ();
618 sub parse_variable($)
620 my $p = shift;
621 my $ptype = '';
622 my $pname = '';
623 my $pnamebefore = '';
624 my $pnameafter = '';
626 while (my ($k, $v) = each(%$p)){
627 if ($k eq 'ptype') {
628 $ptype = ${$v}[0];
629 } elsif ($k eq 'name') {
630 $pname = ${$v}[0];
631 } elsif ($k eq 'content') {
632 if (ref($v) eq 'ARRAY') {
633 my @n = @{$v};
634 $pnamebefore = $n[0];
635 $pnameafter = $n[1] if (@n > 0);
636 } elsif ($v eq 'const ') {
637 $pnamebefore = $v;
638 } else {
639 $pnameafter = $v;
643 $ptype = $pnamebefore . $ptype . $pnameafter;
644 $ptype =~ s/ \*/\*/g;
645 $ptype =~ s/ $//g;
646 return [ $ptype, $pname ];
649 sub parse_file($$)
651 my ($file, $generate_enums) = @_;
652 my $xml = new XML::Simple;
653 my $data = $xml->XMLin($file, ForceArray => 1);
654 my %functions;
656 # save all functions
657 for my $command ( @{${$data->{commands}}[0]->{'command'}} ) {
658 my $name = '';
659 my $ret = '';
660 my $params = [];
661 my @alias = '';
662 while (my ($k, $v) = each(%$command)){
663 if ($k eq 'param') {
664 push(@$params, parse_variable($_)) for (@{$v});
665 } elsif ($k eq 'proto') {
666 ($ret, $name) = @{parse_variable(${$v}[0])};
669 $functions{$name} = [ $ret, $params ];
672 # save all enums (only GL)
673 if ($generate_enums) {
674 for my $enum ( @{$data->{'enums'}} ) {
675 if (ref($enum->{'enum'}) eq "HASH") {
676 while (my ($k, $v) = each(%{$enum->{'enum'}})){
677 $enums{$k} = $v->{'value'};
683 # generate norm functions
684 while (my ($k, $v) = each(%{$data->{feature}})) {
685 if ($norm_categories{$k}) {
686 for my $req (@{$v->{require}}) {
687 for(keys %{$req->{command}}) {
688 $norm_functions{$_} = $functions{$_};
694 # generate extension functions from norm functions, if they are newer than the category
695 while (my ($k, $v) = each(%{$data->{feature}})) {
696 if (!$norm_categories{$k} && $v->{api} =~ /^gl(\||$)/)
698 for my $req (@{$v->{require}}) {
699 for (keys %{$req->{command}}) {
700 if (!$norm_functions{$_}) {
701 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
708 # generate extension functions
709 while (my ($k, $v) = each(%{${$data->{extensions}}[0]->{extension}})) {
710 if ($v->{supported} =~ /^gl(\||$)/) {
711 for my $req (@{$v->{require}}) {
712 if (!defined $req->{api} || $req->{api} =~ /^gl(\||$)/) {
713 for (keys %{$req->{command}}) {
714 if (!$ext_functions{$_} && !$norm_functions{$_}) {
715 $ext_functions{$_} = [$functions{$_}[0], $functions{$_}[1], [ $k ]];
717 elsif ($ext_functions{$_}) {
718 push @{$ext_functions{$_}->[2]}, $k;
724 elsif ($v->{supported} =~ /^wgl$/) {
725 for (keys %{${$v->{require}}[0]->{command}}) {
726 if (defined $supported_wgl_extensions{$k}) {
727 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
734 parse_file( "gl.xml", 1 );
735 parse_file( "wgl.xml", 0 );
738 # Get the current wgl_driver.h version
740 my $wgl_version = 0;
741 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
742 while (<HEADER>)
744 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
745 $wgl_version = $1;
746 last;
748 close HEADER;
751 # Generate the wgl_driver.h file
753 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
754 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
755 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
756 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
757 print HEADER "#ifndef WINE_GLAPI\n";
758 print HEADER "#define WINE_GLAPI\n";
759 print HEADER "#endif\n\n";
761 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
763 print HEADER "struct wgl_context;\n";
764 print HEADER "struct wgl_pbuffer;\n\n";
766 print HEADER "struct opengl_funcs\n{\n";
767 print HEADER " struct\n {\n";
768 foreach (sort keys %wgl_functions)
770 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
772 print HEADER " } wgl;\n\n";
774 print HEADER " struct\n {\n";
775 foreach (sort keys %norm_functions)
777 next if $_ eq "glDebugEntry";
778 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
780 print HEADER " } gl;\n\n";
782 print HEADER " struct\n {\n";
783 foreach (sort keys %ext_functions)
785 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
787 print HEADER " } ext;\n";
788 print HEADER "};\n\n";
790 print HEADER "#define ALL_WGL_FUNCS";
791 foreach (sort keys %norm_functions)
793 next if $_ eq "glDebugEntry";
794 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
796 print HEADER "\n\n";
798 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
799 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
800 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
801 close HEADER;
804 # Generate the wgl.h file
806 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
807 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
808 print HEADER "#ifndef __WINE_WGL_H\n";
809 print HEADER "#define __WINE_WGL_H\n\n";
811 print HEADER "#ifndef GLAPIENTRY\n";
812 print HEADER "#define GLAPIENTRY __stdcall\n";
813 print HEADER "#endif\n\n";
815 foreach (sort keys %arg_conv)
817 printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
819 print HEADER "\n";
821 my $maxlen = 1;
822 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
823 foreach (sort keys %enums)
825 printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
827 print HEADER "\n";
829 foreach (sort keys %norm_functions)
831 printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
834 print HEADER "\n#endif /* __WINE_WGL_H */\n";
835 close HEADER;
838 # Now, generate the output files. First, the spec file.
840 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
842 foreach (sort keys %norm_functions) {
843 my $args=" ";
844 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
845 my $type = $norm_functions{$_}->[1]->[$i]->[0];
846 if ($type =~ /\*/) {
847 $args .= "ptr ";
848 } elsif (defined($arg_conv{$type})) {
849 $args .= "$@$arg_conv{$type}[0] ";
850 } else {
851 die "No conversion for GL type $type...\n";
854 $args = substr($args,1,-1);
855 print SPEC "@ stdcall $_($args)\n";
858 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
859 @ stdcall wglCopyContext(long long long)
860 @ stdcall wglCreateContext(long)
861 @ stdcall wglCreateLayerContext(long long)
862 @ stdcall wglDeleteContext(long)
863 @ stdcall wglDescribeLayerPlane(long long long long ptr)
864 @ stdcall wglDescribePixelFormat(long long long ptr)
865 @ stdcall wglGetCurrentContext()
866 @ stdcall wglGetCurrentDC()
867 @ stub wglGetDefaultProcAddress
868 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
869 @ stdcall wglGetPixelFormat(long)
870 @ stdcall wglGetProcAddress(str)
871 @ stdcall wglMakeCurrent(long long)
872 @ stdcall wglRealizeLayerPalette(long long long)
873 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
874 @ stdcall wglSetPixelFormat(long long ptr)
875 @ stdcall wglShareLists(long long)
876 @ stdcall wglSwapBuffers(long)
877 @ stdcall wglSwapLayerBuffers(long long)
878 @ stdcall wglUseFontBitmapsA(long long long long)
879 @ stdcall wglUseFontBitmapsW(long long long long)
880 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
881 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
884 close(SPEC);
887 # After the spec file, the opengl_norm.c file
889 open(NORM, ">$norm_file") or die "cannot create $norm_file";
890 print NORM "
891 /* Auto-generated file... Do not edit ! */
893 #include \"config.h\"
894 #include <stdarg.h>
895 #include \"winternl.h\"
896 #include \"wingdi.h\"
897 #include \"wine/wgl.h\"
898 #include \"wine/wgl_driver.h\"
899 #include \"wine/debug.h\"
901 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
904 foreach (sort keys %norm_functions) {
905 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
906 print NORM "\n$string" if $string;
909 foreach (sort keys %wgl_functions) {
910 print NORM generate_null_func($_, $wgl_functions{$_});
912 foreach (sort keys %norm_functions) {
913 print NORM generate_null_func($_, $norm_functions{$_});
915 foreach (sort keys %ext_functions) {
916 print NORM generate_null_func($_, $ext_functions{$_});
919 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
920 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
921 print NORM " },\n {\n";
922 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
923 print NORM " },\n {\n";
924 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
925 print NORM " }\n};\n";
927 close(NORM);
930 # Finally, more complex, the opengl_ext.c file
932 open(EXT, ">$ext_file") or die "cannot create $ext_file";
933 print EXT "
934 /* Auto-generated file... Do not edit ! */
936 #include \"config.h\"
937 #include <stdarg.h>
938 #include \"opengl_ext.h\"
939 #include \"winternl.h\"
940 #include \"wingdi.h\"
941 #include \"wine/wgl.h\"
942 #define WGL_WGLEXT_PROTOTYPES
943 #include \"wine/wglext.h\"
944 #include \"wine/wgl_driver.h\"
945 #include \"wine/debug.h\"
947 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
951 # The thunks themselves....
952 my $count = keys %ext_functions;
953 print EXT "const int extension_registry_size = $count;\n";
954 foreach (sort keys %ext_functions) {
955 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
956 if ($string =~ /DECLSPEC_HIDDEN/) {
957 print EXT "\n$string";
958 } else {
959 print EXT "\nstatic $string" if $string;
963 # Then the table giving the string <-> function correspondence */
964 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
965 my $i = 0;
966 foreach (sort keys %ext_functions) {
967 my $func_ref = $ext_functions{$_};
968 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
969 if ($i != $count-1) {
970 print EXT ",";
972 $i++;
973 print EXT "\n";
975 print EXT "};\n";
977 close(EXT);