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 "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",
130 "unsigned int" => "%u",
134 "INT64" => "%s,wine_dbgstr_longlong(%s)",
135 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
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.
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
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";
210 # Used to convert some variable names
212 sub ConvertVarName
($)
216 my %hash = ( "near" => "nearParam",
217 "far" => "farParam" );
219 foreach my $org (keys %hash) {
220 if ($type =~ /^(.*)$org(.*)$/) {
221 return "$1$hash{$org}$2";
228 # This functions generates the thunk for a given function.
230 sub GenerateThunk
($$$$)
232 my ($name, $func_ref, $comment, $prefix) = @_;
235 my $trace_call_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. :-)
245 $ret .= "/***********************************************************************\n";
246 $ret .= " * $name (OPENGL32.\@)\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 my ($base_type, $type_specifier, $name_specifier) = ($type, $type, $name);
254 if ($type =~ /(.*) (.*)/) {
256 } elsif ($type =~ /(.*)(\[.*)/) {
258 $type_specifier = $1;
259 $name_specifier = $name . $2
261 $ret .= ConvertType
($type_specifier) . " $name_specifier";
263 if ($type =~ /\*/ || $type =~ /\[/) {
265 $trace_call_arg .= $name;
266 } elsif (defined $debug_conv{$base_type}) {
267 if ($debug_conv{$base_type} =~ /(.*),(.*)/) {
269 $trace_call_arg .= sprintf $2, $name;
271 $trace_arg .= $debug_conv{$base_type};
272 $trace_call_arg .= $name;
275 else { printf "Unknown type %s\n", $type; }
276 if ($i+1 < @
{$func_ref->[1]}) {
279 $trace_call_arg .= ", ";
284 $trace_call_arg .= " ";
287 $ret .= 'void ' if (!@
{$func_ref->[1]});
289 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
290 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
291 $ret .= " " . ConvertType
($func_ref->[0]) . " ret_value;\n";
294 $ret .= " TRACE(\"($trace_arg)\\n\"";
295 if ($trace_arg ne "") {
296 $ret .= ", $trace_call_arg";
300 if ($gen_thread_safe) {
301 $ret .= " ENTER_GL();\n";
303 if ($func_ref->[0] ne "void") {
304 $ret .= "ret_value = ";
306 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
307 $ret .= " LEAVE_GL();\n";
308 if ($func_ref->[0] ne "void") {
309 $ret .= " return ret_value;\n"
314 if ($func_ref->[0] ne "void") {
317 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
321 # Return this string....
325 sub generate_null_func
($$)
327 my ($name, $func_ref) = @_;
330 return "" if $name eq "glDebugEntry";
332 $ret = "static " . ConvertType
($func_ref->[0]) . " null_$name( ";
333 for (my $i = 0; $i < @
{$func_ref->[1]}; $i++) {
334 my $type = $func_ref->[1]->[$i]->[0];
335 my $name = ConvertVarName
($func_ref->[1]->[$i]->[1]);
337 if ($type =~ /(.*)(\[.*)/) {
343 $ret .= ConvertType
($base_type) . " $name";
344 $ret .= "," if ($i+1 < @
{$func_ref->[1]});
347 $ret .= 'void ' if (!@
{$func_ref->[1]});
349 if ($name eq "glGetError")
351 $ret .= " return GL_INVALID_OPERATION;";
353 elsif ($func_ref->[0] ne "void")
355 $ret .= " return 0;";
361 sub get_func_proto
($$$)
363 my ($format, $name, $func) = @_;
364 my $ret = sprintf "%-10s", ConvertType
($func->[0]);
365 $ret .= " " . sprintf($format,$name) . "(";
366 for (my $i = 0; $i < @
{$func->[1]}; $i++)
368 $ret .= ConvertType
($func->[1]->[$i]->[0]);
369 $ret .= "," if ($i+1 < @
{$func->[1]});
371 $ret .= "void" unless @
{$func->[1]};
377 # Extract and checks the number of arguments
382 die "Usage: $name0 [version]\n";
384 my $version = $ARGV[0] || "1.1";
385 if ($version eq "1.0") {
386 %norm_categories = %cat_1_0;
387 } elsif ($version eq "1.1") {
388 %norm_categories = %cat_1_1;
389 } elsif ($version eq "1.2") {
390 %norm_categories = %cat_1_2;
391 } elsif ($version eq "1.3") {
392 %norm_categories = %cat_1_3;
393 } elsif ($version eq "1.4") {
394 %norm_categories = %cat_1_4;
395 } elsif ($version eq "1.5") {
396 %norm_categories = %cat_1_5;
398 die "Incorrect OpenGL version.\n";
402 # Fetch the registry files
404 -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";
405 -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";
409 # Then, create the list of all OpenGL functions using the registry
410 # files. This will create two hash-tables, one with all the function
411 # whose category matches the one listed in '@norm_categories', the other
412 # with all other functions.
414 # An element of the hash table is a reference to an array with these
421 # - reference to an array giving the list of arguments (an empty array
422 # for a 'void' function).
424 # The list of arguments is itself an array of reference to arrays. Each
425 # of these arrays represents the argument type and the argument name.
429 # void glBitmap( GLsizei width, GLsizei height,
430 # GLfloat xorig, GLfloat yorig,
431 # GLfloat xmove, GLfloat ymove,
432 # const GLubyte *bitmap );
434 # Would give something like that :
438 # [ [ "GLsizei", "width" ],
439 # [ "GLsizei", "height" ],
440 # [ "GLfloat", "xorig" ],
441 # [ "GLfloat", "yorig" ],
442 # [ "GLfloat", "xmove" ],
443 # [ "GLfloat", "ymove" ],
444 # [ "GLubyte *", "bitmap"] ] ];
446 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
447 [ "GLint", "unknown2" ]] ] );
450 # This stores various extensions NOT part of the GL extension registry but still
451 # implemented by most OpenGL libraries out there...
456 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], [ "GL_KTX_buffer_region" ] ],
457 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
460 [ "GLsizei", "width" ],
461 [ "GLsizei", "height" ] ], [ "GL_KTX_buffer_region" ] ],
462 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
465 [ "GLsizei", "width" ],
466 [ "GLsizei", "height" ],
467 [ "GLint", "xDest" ],
468 [ "GLint", "yDest" ] ], [ "GL_KTX_buffer_region" ] ],
469 "glBufferRegionEnabled" => [ "GLuint", [ ], [ "GL_KTX_buffer_region" ] ],
470 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], [ "GL_KTX_buffer_region" ] ],
471 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
473 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
474 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
475 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
476 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
477 [ "GLdouble", "s" ] ], [ "GL_SGIS_multitexture" ] ],
478 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
479 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
480 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
481 [ "GLfloat", "s" ] ], [ "GL_SGIS_multitexture" ] ],
482 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
483 [ "const GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
484 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
485 [ "GLint", "s" ] ], [ "GL_SGIS_multitexture" ] ],
486 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
487 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
488 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
489 [ "GLshort", "s" ] ], [ "GL_SGIS_multitexture" ] ],
490 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
491 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
492 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
494 [ "GLdouble", "t" ] ], [ "GL_SGIS_multitexture" ] ],
495 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
496 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
497 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
499 [ "GLfloat", "t" ] ], [ "GL_SGIS_multitexture" ] ],
500 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
501 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
502 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
504 [ "GLint", "t" ] ], [ "GL_SGIS_multitexture" ] ],
505 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
506 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
507 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
509 [ "GLshort", "t" ] ], [ "GL_SGIS_multitexture" ] ],
510 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
511 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
512 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
515 [ "GLdouble", "r" ] ], [ "GL_SGIS_multitexture" ] ],
516 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
517 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
518 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
521 [ "GLfloat", "r" ] ], [ "GL_SGIS_multitexture" ] ],
522 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
523 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
524 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
527 [ "GLint", "r" ] ], [ "GL_SGIS_multitexture" ] ],
528 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
529 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
530 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
533 [ "GLshort", "r" ] ], [ "GL_SGIS_multitexture" ] ],
534 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
535 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
536 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
540 [ "GLdouble", "q" ] ], [ "GL_SGIS_multitexture" ] ],
541 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
542 [ "GLdouble *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
543 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLfloat", "q" ] ], [ "GL_SGIS_multitexture" ] ],
548 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
549 [ "GLfloat *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
550 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
554 [ "GLint", "q" ] ], [ "GL_SGIS_multitexture" ] ],
555 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
556 [ "GLint *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
557 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
561 [ "GLshort", "q" ] ], [ "GL_SGIS_multitexture" ] ],
562 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
563 [ "GLshort *", "v" ] ], [ "GL_SGIS_multitexture" ] ],
564 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
566 [ "GLenum", "type" ],
567 [ "GLsizei", "stride" ],
568 [ "GLvoid *", "pointer" ] ], [ "GL_SGIS_multitexture" ] ],
569 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
570 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], [ "GL_SGIS_multitexture" ] ],
571 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], [ "GL_ATI_vertex_array_object" ] ],
572 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
573 [ "int", "format" ] ], [ "WGL_WINE_pixel_format_passthrough" ] ],
579 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
580 [ "struct wgl_context *", "dst" ],
581 [ "UINT", "mask" ] ] ],
582 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
583 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
584 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
587 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
588 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
589 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
590 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
591 [ "struct wgl_context *", "context" ] ] ],
592 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
594 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
595 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
596 [ "struct wgl_context *", "dst" ] ] ],
597 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
600 my %supported_wgl_extensions =
602 "WGL_ARB_create_context" => 1,
603 "WGL_ARB_extensions_string" => 1,
604 "WGL_ARB_make_current_read" => 1,
605 "WGL_ARB_pbuffer" => 1,
606 "WGL_ARB_pixel_format" => 1,
607 "WGL_ARB_render_texture" => 1,
608 "WGL_EXT_extensions_string" => 1,
609 "WGL_EXT_swap_control" => 1,
610 "WGL_NV_vertex_array_range" => 1,
611 "WGL_WINE_pixel_format_passthrough" => 1,
616 sub parse_variable
($)
621 my $pnamebefore = '';
624 while (my ($k, $v) = each(%$p)){
627 } elsif ($k eq 'name') {
629 } elsif ($k eq 'content') {
630 if (ref($v) eq 'ARRAY') {
632 $pnamebefore = $n[0];
633 $pnameafter = $n[1] if (@n > 0);
634 } elsif ($v eq 'const ') {
641 $ptype = $pnamebefore . $ptype . $pnameafter;
642 $ptype =~ s/ \*/\*/g;
644 return [ $ptype, $pname ];
649 my ($file, $generate_enums) = @_;
650 my $xml = new XML
::Simple
;
651 my $data = $xml->XMLin($file, ForceArray
=> 1);
655 for my $command ( @
{${$data->{commands
}}[0]->{'command'}} ) {
660 while (my ($k, $v) = each(%$command)){
662 push(@
$params, parse_variable
($_)) for (@
{$v});
663 } elsif ($k eq 'proto') {
664 ($ret, $name) = @
{parse_variable
(${$v}[0])};
667 $functions{$name} = [ $ret, $params ];
670 # save all enums (only GL)
671 if ($generate_enums) {
672 for my $enum ( @
{$data->{'enums'}} ) {
673 if (ref($enum->{'enum'}) eq "HASH") {
674 while (my ($k, $v) = each(%{$enum->{'enum'}})){
675 $enums{$k} = $v->{'value'};
681 # generate norm functions
682 while (my ($k, $v) = each(%{$data->{feature
}})) {
683 if ($norm_categories{$k}) {
684 for my $req (@
{$v->{require}}) {
685 for(keys %{$req->{command
}}) {
686 $norm_functions{$_} = $functions{$_};
692 # generate extension functions from norm functions, if they are newer than the category
693 while (my ($k, $v) = each(%{$data->{feature
}})) {
694 if (!$norm_categories{$k} && $v->{api
} =~ /^gl(\||$)/)
696 for my $req (@
{$v->{require}}) {
697 for (keys %{$req->{command
}}) {
698 if (!$norm_functions{$_}) {
699 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
706 # generate extension functions
707 while (my ($k, $v) = each(%{${$data->{extensions
}}[0]->{extension
}})) {
708 if ($v->{supported
} =~ /^gl(\||$)/) {
709 for my $req (@
{$v->{require}}) {
710 if (!defined $req->{api
} || $req->{api
} =~ /^gl(\||$)/) {
711 for (keys %{$req->{command
}}) {
712 if (!$ext_functions{$_} && !$norm_functions{$_}) {
713 $ext_functions{$_} = [$functions{$_}[0], $functions{$_}[1], [ $k ]];
715 elsif ($ext_functions{$_}) {
716 push @
{$ext_functions{$_}->[2]}, $k;
722 elsif ($v->{supported
} =~ /^wgl$/) {
723 for (keys %{${$v->{require}}[0]->{command
}}) {
724 if (defined $supported_wgl_extensions{$k}) {
725 $ext_functions{$_} = [ $functions{$_}[0], $functions{$_}[1], [ $k ] ];
732 parse_file
( "gl.xml", 1 );
733 parse_file
( "wgl.xml", 0 );
736 # Get the current wgl_driver.h version
739 open HEADER
, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
742 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
749 # Generate the wgl_driver.h file
751 open HEADER
, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
752 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
753 print HEADER
"#ifndef __WINE_WGL_DRIVER_H\n";
754 print HEADER
"#define __WINE_WGL_DRIVER_H\n\n";
755 print HEADER
"#ifndef WINE_GLAPI\n";
756 print HEADER
"#define WINE_GLAPI\n";
757 print HEADER
"#endif\n\n";
759 printf HEADER
"#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
761 print HEADER
"struct wgl_context;\n";
762 print HEADER
"struct wgl_pbuffer;\n\n";
764 print HEADER
"struct opengl_funcs\n{\n";
765 print HEADER
" struct\n {\n";
766 foreach (sort keys %wgl_functions)
768 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
770 print HEADER
" } wgl;\n\n";
772 print HEADER
" struct\n {\n";
773 foreach (sort keys %norm_functions)
775 next if $_ eq "glDebugEntry";
776 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
778 print HEADER
" } gl;\n\n";
780 print HEADER
" struct\n {\n";
781 foreach (sort keys %ext_functions)
783 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
785 print HEADER
" } ext;\n";
786 print HEADER
"};\n\n";
788 print HEADER
"#define ALL_WGL_FUNCS";
789 foreach (sort keys %norm_functions)
791 next if $_ eq "glDebugEntry";
792 printf HEADER
" \\\n USE_GL_FUNC(\%s)", $_;
796 print HEADER
"extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
797 print HEADER
"extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
798 print HEADER
"#endif /* __WINE_WGL_DRIVER_H */\n";
802 # Generate the wgl.h file
804 open HEADER
, ">$wgl_file" or die "cannot create $wgl_file";
805 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
806 print HEADER
"#ifndef __WINE_WGL_H\n";
807 print HEADER
"#define __WINE_WGL_H\n\n";
809 print HEADER
"#ifndef GLAPIENTRY\n";
810 print HEADER
"#define GLAPIENTRY __stdcall\n";
811 print HEADER
"#endif\n\n";
813 foreach (sort keys %arg_conv)
815 printf HEADER
"typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
820 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
821 foreach (sort keys %enums)
823 printf HEADER
"#define %-*s %s\n", $maxlen, $_, $enums{$_};
827 foreach (sort keys %norm_functions)
829 printf HEADER
"%s;\n", get_func_proto
("GLAPIENTRY %s", $_, $norm_functions{$_});
832 print HEADER
"\n#endif /* __WINE_WGL_H */\n";
836 # Now, generate the output files. First, the spec file.
838 open(SPEC
, ">$spec_file") or die "cannot create $spec_file";
840 foreach (sort keys %norm_functions) {
842 for (my $i = 0; $i < @
{$norm_functions{$_}->[1]}; $i++) {
843 my $type = $norm_functions{$_}->[1]->[$i]->[0];
846 } elsif (defined($arg_conv{$type})) {
847 $args .= "$@$arg_conv{$type}[0] ";
849 die "No conversion for GL type $type...\n";
852 $args = substr($args,1,-1);
853 print SPEC
"@ stdcall $_($args)\n";
856 print SPEC
"@ stdcall wglChoosePixelFormat(long ptr)
857 @ stdcall wglCopyContext(long long long)
858 @ stdcall wglCreateContext(long)
859 @ stdcall wglCreateLayerContext(long long)
860 @ stdcall wglDeleteContext(long)
861 @ stdcall wglDescribeLayerPlane(long long long long ptr)
862 @ stdcall wglDescribePixelFormat(long long long ptr)
863 @ stdcall wglGetCurrentContext()
864 @ stdcall wglGetCurrentDC()
865 @ stub wglGetDefaultProcAddress
866 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
867 @ stdcall wglGetPixelFormat(long)
868 @ stdcall wglGetProcAddress(str)
869 @ stdcall wglMakeCurrent(long long)
870 @ stdcall wglRealizeLayerPalette(long long long)
871 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
872 @ stdcall wglSetPixelFormat(long long ptr)
873 @ stdcall wglShareLists(long long)
874 @ stdcall wglSwapBuffers(long)
875 @ stdcall wglSwapLayerBuffers(long long)
876 @ stdcall wglUseFontBitmapsA(long long long long)
877 @ stdcall wglUseFontBitmapsW(long long long long)
878 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
879 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
885 # After the spec file, the opengl_norm.c file
887 open(NORM
, ">$norm_file") or die "cannot create $norm_file";
889 /* Auto-generated file... Do not edit ! */
891 #include \"config.h\"
893 #include \"winternl.h\"
894 #include \"wingdi.h\"
895 #include \"wine/wgl.h\"
896 #include \"wine/wgl_driver.h\"
897 #include \"wine/debug.h\"
899 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
902 foreach (sort keys %norm_functions) {
903 my $string = GenerateThunk
($_, $norm_functions{$_}, 1, "gl");
904 print NORM
"\n$string" if $string;
907 foreach (sort keys %wgl_functions) {
908 print NORM generate_null_func
($_, $wgl_functions{$_});
910 foreach (sort keys %norm_functions) {
911 print NORM generate_null_func
($_, $norm_functions{$_});
913 foreach (sort keys %ext_functions) {
914 print NORM generate_null_func
($_, $ext_functions{$_});
917 print NORM
"\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
918 foreach (sort keys %wgl_functions) { print NORM
" null_$_,\n"; }
919 print NORM
" },\n {\n";
920 foreach (sort keys %norm_functions) { print NORM
" null_$_,\n" unless $_ eq "glDebugEntry"; }
921 print NORM
" },\n {\n";
922 foreach (sort keys %ext_functions) { print NORM
" null_$_,\n"; }
923 print NORM
" }\n};\n";
928 # Finally, more complex, the opengl_ext.c file
930 open(EXT
, ">$ext_file") or die "cannot create $ext_file";
932 /* Auto-generated file... Do not edit ! */
934 #include \"config.h\"
936 #include \"opengl_ext.h\"
937 #include \"winternl.h\"
938 #include \"wingdi.h\"
939 #include \"wine/wgl.h\"
940 #define WGL_WGLEXT_PROTOTYPES
941 #include \"wine/wglext.h\"
942 #include \"wine/wgl_driver.h\"
943 #include \"wine/debug.h\"
945 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
949 # The thunks themselves....
950 my $count = keys %ext_functions;
951 print EXT
"const int extension_registry_size = $count;\n";
952 foreach (sort keys %ext_functions) {
953 my $string = GenerateThunk
($_, $ext_functions{$_}, 0, "ext");
954 print EXT
"\nstatic $string" if $string;
957 # Then the table giving the string <-> function correspondence */
958 print EXT
"\nconst OpenGL_extension extension_registry[$count] = {\n";
960 foreach (sort keys %ext_functions) {
961 my $func_ref = $ext_functions{$_};
962 printf EXT
" { \"%s\", \"%s\", %s }", $_, join(" ", sort @
{$func_ref->[2]}), $_;
963 if ($i != $count-1) {