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
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
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
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
94 ("GLbitfield" => "%d",
113 "GLintptrARB" => "%ld",
114 "GLsizeiptrARB" => "%ld",
116 "GLsizeiptr" => "%ld",
117 "GLhandleARB" => "%d",
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",
131 "unsigned int" => "%u",
135 "INT64" => "%s,wine_dbgstr_longlong(%s)",
136 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
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.
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
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";
211 # Used to convert some variable names
213 sub ConvertVarName
($)
217 my %hash = ( "near" => "nearParam",
218 "far" => "farParam" );
220 foreach my $org (keys %hash) {
221 if ($type =~ /^(.*)$org(.*)$/) {
222 return "$1$hash{$org}$2";
229 # This functions generates the thunk for a given function.
231 sub GenerateThunk
($$$$)
233 my ($name, $func_ref, $comment, $prefix) = @_;
236 my $trace_call_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. :-)
247 $ret .= "/***********************************************************************\n";
248 $ret .= " * $name (OPENGL32.\@)\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 =~ /(.*) (.*)/) {
258 } elsif ($type =~ /(.*)(\[.*)/) {
260 $type_specifier = $1;
261 $name_specifier = $name . $2
263 $ret .= ConvertType
($type_specifier) . " $name_specifier";
265 if ($type =~ /\*/ || $type =~ /\[/) {
267 $trace_call_arg .= $name;
268 } elsif (defined $debug_conv{$base_type}) {
269 if ($debug_conv{$base_type} =~ /(.*),(.*)/) {
271 $trace_call_arg .= sprintf $2, $name;
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]}) {
281 $trace_call_arg .= ", ";
286 $trace_call_arg .= " ";
289 $ret .= 'void ' if (!@
{$func_ref->[1]});
290 return "$ret) DECLSPEC_HIDDEN;\n" if $name eq "glGetStringi";
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";
297 $ret .= " TRACE(\"($trace_arg)\\n\"";
298 if ($trace_arg ne "") {
299 $ret .= ", $trace_call_arg";
303 if ($gen_thread_safe) {
304 $ret .= " ENTER_GL();\n";
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"
317 if ($func_ref->[0] ne "void") {
320 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
324 # Return this string....
328 sub generate_null_func
($$)
330 my ($name, $func_ref) = @_;
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]);
340 if ($type =~ /(.*)(\[.*)/) {
346 $ret .= ConvertType
($base_type) . " $name";
347 $ret .= "," if ($i+1 < @
{$func_ref->[1]});
350 $ret .= 'void ' if (!@
{$func_ref->[1]});
352 if ($name eq "glGetError")
354 $ret .= " return GL_INVALID_OPERATION;";
356 elsif ($func_ref->[0] ne "void")
358 $ret .= " return 0;";
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]};
380 # Extract and checks the number of arguments
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;
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
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.
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 :
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...
459 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], [ "GL_KTX_buffer_region" ] ],
460 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
463 [ "GLsizei", "width" ],
464 [ "GLsizei", "height" ] ], [ "GL_KTX_buffer_region" ] ],
465 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
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" ],
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" ],
497 [ "GLdouble", "t" ] ], [ "GL_SGIS_multitexture" ] ],
498 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
499 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
500 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
502 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
503 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
504 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
505 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
507 [ "GLint", "t" ] ], [ "GL_SGIS_multitexture" ] ],
508 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
509 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
510 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
512 [ "GLshort", "t" ] ], [ "GL_SGIS_multitexture" ] ],
513 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
514 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
515 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
518 [ "GLdouble", "r" ] ], [ "GL_SGIS_multitexture" ] ],
519 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
520 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
521 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
524 [ "GLfloat", "r" ] ], [ "GL_SGIS_multitexture" ] ],
525 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
526 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
527 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
530 [ "GLint", "r" ] ], [ "GL_SGIS_multitexture" ] ],
531 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
533 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
536 [ "GLshort", "r" ] ], [ "GL_SGIS_multitexture" ] ],
537 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
538 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
539 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
543 [ "GLdouble", "q" ] ], [ "GL_SGIS_multitexture" ] ],
544 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
545 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
546 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
550 [ "GLfloat", "q" ] ], [ "GL_SGIS_multitexture" ] ],
551 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
552 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
553 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
557 [ "GLint", "q" ] ], [ "GL_SGIS_multitexture" ] ],
558 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
559 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
560 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
564 [ "GLshort", "q" ] ], [ "GL_SGIS_multitexture" ] ],
565 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
566 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
567 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
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" ] ],
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" ],
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" ],
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,
619 sub parse_variable
($)
624 my $pnamebefore = '';
627 while (my ($k, $v) = each(%$p)){
630 } elsif ($k eq 'name') {
632 } elsif ($k eq 'content') {
633 if (ref($v) eq 'ARRAY') {
635 $pnamebefore = $n[0];
636 $pnameafter = $n[1] if (@n > 0);
637 } elsif ($v eq 'const ') {
644 $ptype = $pnamebefore . $ptype . $pnameafter;
645 $ptype =~ s/ \*/\*/g;
647 return [ $ptype, $pname ];
652 my ($file, $generate_enums) = @_;
653 my $xml = new XML
::Simple
;
654 my $data = $xml->XMLin($file, ForceArray
=> 1);
658 for my $command ( @
{${$data->{commands
}}[0]->{'command'}} ) {
663 while (my ($k, $v) = each(%$command)){
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
744 open HEADER
, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
747 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
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)", $_;
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";
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], $_;
825 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
826 foreach (sort keys %enums)
828 printf HEADER
"#define %-*s %s\n", $maxlen, $_, $enums{$_};
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";
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) {
847 for (my $i = 0; $i < @
{$norm_functions{$_}->[1]}; $i++) {
848 my $type = $norm_functions{$_}->[1]->[$i]->[0];
851 } elsif (defined($arg_conv{$type})) {
852 $args .= "$@$arg_conv{$type}[0] ";
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)
890 # After the spec file, the opengl_norm.c file
892 open(NORM
, ">$norm_file") or die "cannot create $norm_file";
894 /* Auto-generated file... Do not edit ! */
896 #include \"config.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";
933 # Finally, more complex, the opengl_ext.c file
935 open(EXT
, ">$ext_file") or die "cannot create $ext_file";
937 /* Auto-generated file... Do not edit ! */
939 #include \"config.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";
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";
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) {