dinput: Factor out IDirectInputDevice ansi vtable.
[wine.git] / dlls / opengl32 / make_opengl
blobebfd3c9161e5724f5aa7059c564ee4752c22014c
1 #!/usr/bin/perl -w
2 use strict;
3 use XML::LibXML;
5 # This script is called thus :
7 # make_opengl [opengl_version]
9 # - It needs files from the OpenGL extension registry:
11 # https://raw.github.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml
12 # https://raw.github.com/KhronosGroup/OpenGL-Registry/master/xml/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 # If set to 1, generate TRACEs for each OpenGL function
71 my $gen_traces = 1;
74 # List of categories to put in the 'opengl_norm.c' file
76 my %cat_1_0 = ( "GL_VERSION_1_0" => 1 );
77 my %cat_1_1 = ( %cat_1_0, "GL_VERSION_1_1" => 1 );
78 my %cat_1_2 = ( %cat_1_1, "GL_VERSION_1_2" => 1 );
79 my %cat_1_3 = ( %cat_1_2, "GL_VERSION_1_3" => 1 );
80 my %cat_1_4 = ( %cat_1_3, "GL_VERSION_1_4" => 1 );
81 my %cat_1_5 = ( %cat_1_4, "GL_VERSION_1_5" => 1 );
83 my %norm_categories = ();
86 # This hash table gives the conversion between OpenGL types and
87 # the .spec type and debug format
89 my %arg_types =
91 "GLbitfield" => [ "long", "%d" ],
92 "GLboolean" => [ "long", "%d" ],
93 "GLbyte" => [ "long", "%d" ],
94 "GLchar" => [ "long", "%c" ],
95 "GLcharARB" => [ "long", "%c" ],
96 "GLclampd" => [ "double", "%f" ],
97 "GLclampf" => [ "float", "%f" ],
98 "GLclampx" => [ "long", "%d" ],
99 "GLdouble" => [ "double", "%f" ],
100 "GLeglClientBufferEXT" => [ "ptr", "%p" ],
101 "GLeglImageOES" => [ "ptr", "%p" ],
102 "GLenum" => [ "long", "%d" ],
103 "GLfixed" => [ "long", "%d" ],
104 "GLfloat" => [ "float", "%f" ],
105 "GLhalfNV" => [ "long", "%d" ],
106 "GLhandleARB" => [ "long", "%d" ],
107 "GLint" => [ "long", "%d" ],
108 "GLint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
109 "GLint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
110 "GLintptr" => [ "long", "%ld" ],
111 "GLintptrARB" => [ "long", "%ld" ],
112 "GLshort" => [ "long", "%d" ],
113 "GLsizei" => [ "long", "%d" ],
114 "GLsizeiptr" => [ "long", "%ld" ],
115 "GLsizeiptrARB" => [ "long", "%ld" ],
116 "GLstring" => [ "str", "wine_dbgstr_a(%s)" ],
117 "GLsync" => [ "ptr", "%p" ],
118 "GLubyte" => [ "long", "%d" ],
119 "GLuint" => [ "long", "%d" ],
120 "GLuint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
121 "GLuint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
122 "GLushort" => [ "long", "%d" ],
123 "GLvdpauSurfaceNV" => [ "long", "%ld" ],
124 "GLDEBUGPROC" => [ "ptr", "%p" ],
125 "GLDEBUGPROCARB" => [ "ptr", "%p" ],
126 "GLDEBUGPROCAMD" => [ "ptr", "%p" ],
127 "GLDEBUGPROCKHR" => [ "ptr", "%p" ],
128 "GLVULKANPROCNV" => [ "ptr", "%p" ],
129 "HDC" => [ "long", "%p" ],
130 "HGLRC" => [ "long", "%p" ],
131 "HPBUFFERARB" => [ "long", "%p" ],
132 "HENHMETAFILE" => [ "long", "%p" ],
133 "LPGLYPHMETRICSFLOAT" => [ "ptr", "%p" ],
134 "LPCSTR" => [ "str", "wine_dbgstr_a(%s)" ],
135 "UINT" => [ "long", "%u" ],
136 "DWORD" => [ "long", "%u" ],
137 "BOOL" => [ "long", "%u" ],
138 "FLOAT" => [ "float", "%f" ],
141 my %remap_types =
143 "HGLRC" => "struct wgl_context *",
144 "HPBUFFERARB" => "struct wgl_pbuffer *",
147 my %khronos_types =
149 "khronos_int8_t" => "signed char",
150 "khronos_uint8_t" => "unsigned char",
151 "khronos_int16_t" => "short",
152 "khronos_uint16_t" => "unsigned short",
153 "khronos_int32_t" => "int",
154 "khronos_uint32_t" => "unsigned int",
155 "khronos_float_t" => "float",
158 # Used to convert some types
160 sub ConvertType($)
162 my $arg = shift;
163 my $ret = $arg->textContent();
164 my @type = $arg->findnodes("./ptype");
166 if (@type)
168 my $type = $type[0]->textContent();
169 $ret =~ s/$type/$remap_types{$type}/ if defined $remap_types{$type};
171 return $ret;
175 # This functions generates the thunk for a given function.
177 sub GenerateThunk($$$)
179 my ($name, $func_ref, $prefix) = @_;
180 my $call_arg = "";
181 my $trace_call_arg = "";
182 my $trace_arg = "";
184 my $ret = get_func_proto( "%s WINAPI %s(%s)", $name, $func_ref, 0 );
185 foreach my $arg (@{$func_ref->[1]}) {
186 my $ptype = get_arg_type( $arg );
187 my $pname = get_arg_name( $arg );
188 my $param = $arg->textContent();
189 $call_arg .= " " . $pname . ",";
190 if ($param =~ /\*/ || $param =~ /\[/) {
191 $trace_arg .= ", %p";
192 $trace_call_arg .= ", " . $pname;
193 } elsif (defined $arg_types{$ptype}) {
194 my $format = ${$arg_types{$ptype}}[1];
195 $trace_arg .= ", " . ($format =~ /^%/ ? $format : "%s");
196 $trace_call_arg .= ", " . sprintf $format =~ /^%/ ? "%s" : $format, $pname;
198 else { printf "Unknown type %s in %s\n", $param, $name; }
200 $call_arg =~ s/,$/ /;
201 $trace_arg =~ s/^, //;
202 $ret .= "\n{\n";
203 # special case for functions that take an HDC as first parameter
204 if (@{$func_ref->[1]} && get_arg_type( ${$func_ref->[1]}[0] ) eq "HDC")
206 my $pname = get_arg_name( ${$func_ref->[1]}[0] );
207 $ret .= " const struct opengl_funcs *funcs = get_dc_funcs( $pname );\n";
208 $ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
209 $ret .= " if (!funcs || !funcs->$prefix.p_$name) return";
210 $ret .= " 0" unless is_void_func( $func_ref );
211 $ret .= ";\n";
213 else
215 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
216 $ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
218 $ret .= " ";
219 $ret .= "return " unless is_void_func( $func_ref );
220 $ret .= "funcs->$prefix.p_$name($call_arg);\n";
221 $ret .= "}\n\n";
222 return $ret;
225 sub generate_null_func($$$)
227 my ($name, $func_ref, $callconv) = @_;
228 my $ret;
230 return "" if $name eq "glDebugEntry";
232 $ret = get_func_proto( "static %s$callconv null_%s(%s)", $name, $func_ref, 1 );
233 $ret .= " {";
234 if ($name eq "glGetError")
236 $ret .= " return GL_INVALID_OPERATION;";
238 elsif (!is_void_func( $func_ref ))
240 $ret .= " return 0;";
242 $ret .= " }\n";
243 return $ret;
246 sub generate_spec_entry($$)
248 my ($name, $func) = @_;
249 my $args=" ";
250 foreach my $arg (@{$func->[1]})
252 my $ptype = get_arg_type( $arg );
253 my $param = $arg->textContent();
254 if ($param =~ /[[*]/) {
255 $args .= "ptr ";
256 } elsif (defined($arg_types{$ptype})) {
257 $args .= "$@$arg_types{$ptype}[0] ";
258 } else {
259 die "No conversion for func $name type $param\n";
262 $args = substr($args,1,-1);
263 return "@ stdcall $_($args)";
266 sub is_void_func($)
268 my $func = shift;
269 return 0 if @{$func->[0]->findnodes("./ptype")};
270 return $func->[0]->textContent() eq "void ";
273 sub get_arg_type($)
275 my $p = shift;
276 my @type = $p->findnodes("./ptype");
277 return @type ? $type[0]->textContent() : "GLint";
280 sub get_arg_name($)
282 my $p = shift;
283 my @name = $p->findnodes("./name");
284 return $name[0]->textContent();
287 sub get_func_proto($$$$)
289 my ($format, $name, $func, $convert_args) = @_;
290 die "unknown func $name" unless defined $func->[0];
291 my $proto = $convert_args ? ConvertType( $func->[0] ) : $func->[0]->textContent();
292 $proto =~ s/ $//;
293 my $args = "";
294 foreach my $arg (@{$func->[1]})
296 $args .= " " . ($convert_args ? ConvertType( $arg ) : $arg->textContent()) . ",";
298 $args =~ s/,$/ /;
299 $args ||= "void";
300 return sprintf $format, $proto, $name, $args;
304 # Extract and checks the number of arguments
306 if (@ARGV > 1) {
307 my $name0=$0;
308 $name0=~s%^.*/%%;
309 die "Usage: $name0 [version]\n";
311 my $version = $ARGV[0] || "1.1";
312 if ($version eq "1.0") {
313 %norm_categories = %cat_1_0;
314 } elsif ($version eq "1.1") {
315 %norm_categories = %cat_1_1;
316 } elsif ($version eq "1.2") {
317 %norm_categories = %cat_1_2;
318 } elsif ($version eq "1.3") {
319 %norm_categories = %cat_1_3;
320 } elsif ($version eq "1.4") {
321 %norm_categories = %cat_1_4;
322 } elsif ($version eq "1.5") {
323 %norm_categories = %cat_1_5;
324 } else {
325 die "Incorrect OpenGL version.\n";
329 # Fetch the registry files
331 my $url="https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry";
332 my $commit="03e1bfb87c4664d34dc7822fb591841eec747094";
334 -f "gl-$commit.xml" || system "wget", "-O", "gl-$commit.xml", "$url/$commit/xml/gl.xml" || die "cannot download gl.xml";
335 -f "wgl-$commit.xml" || system "wget", "-O", "wgl-$commit.xml", "$url/$commit/xml/wgl.xml" || die "cannot download wgl.xml";
339 # Then, create the list of all OpenGL functions using the registry
340 # files. This will create two hash-tables, one with all the function
341 # whose category matches the one listed in '@norm_categories', the other
342 # with all other functions.
344 # An element of the hash table is a reference to an array with these
345 # elements :
347 # - XML node of the function prototype
349 # - reference to an array of XML nodes giving the list of arguments (an empty array
350 # for a 'void' function).
352 my %norm_functions;
353 my %ext_functions;
354 my %wgl_functions;
355 my %gl_enums;
356 my (%gl_types, @gl_types); # also use an array to preserve declaration order
358 my %supported_wgl_functions =
360 "wglCopyContext" => 1,
361 "wglCreateContext" => 1,
362 "wglDeleteContext" => 1,
363 "wglDescribePixelFormat" => 1,
364 "wglGetPixelFormat" => 1,
365 "wglGetProcAddress" => 1,
366 "wglMakeCurrent" => 1,
367 "wglSetPixelFormat" => 1,
368 "wglShareLists" => 1,
369 "wglSwapBuffers" => 1,
372 my %remapped_wgl_functions =
374 "ChoosePixelFormat" => "wglChoosePixelFormat",
375 "DescribePixelFormat" => "wglDescribePixelFormat",
376 "GetPixelFormat" => "wglGetPixelFormat",
377 "GetEnhMetaFilePixelFormat" => 0,
378 "SetPixelFormat" => "wglSetPixelFormat",
379 "SwapBuffers" => "wglSwapBuffers",
380 "wglUseFontBitmaps" => 0,
381 "wglUseFontOutlines" => 0,
384 my @extra_wgl_functions = ( "wglGetDefaultProcAddress" );
386 my %supported_wgl_extensions =
388 "WGL_ARB_create_context" => 1,
389 "WGL_ARB_create_context_no_error" => 1,
390 "WGL_ARB_create_context_profile" => 1,
391 "WGL_ARB_extensions_string" => 1,
392 "WGL_ARB_make_current_read" => 1,
393 "WGL_ARB_multisample" => 1,
394 "WGL_ARB_pbuffer" => 1,
395 "WGL_ARB_pixel_format" => 1,
396 "WGL_ARB_framebuffer_sRGB" => 1,
397 "WGL_ARB_pixel_format_float" => 1,
398 "WGL_ARB_render_texture" => 1,
399 "WGL_ATI_pixel_format_float" => 1,
400 "WGL_EXT_create_context_es2_profile" => 1,
401 "WGL_EXT_extensions_string" => 1,
402 "WGL_EXT_framebuffer_sRGB" => 1,
403 "WGL_EXT_pixel_format_packed_float" => 1,
404 "WGL_EXT_swap_control" => 1,
405 "WGL_EXT_swap_control_tear" => 1,
406 "WGL_NV_float_buffer" => 1,
407 "WGL_NV_render_depth_texture" => 1,
408 "WGL_NV_render_texture_rectangle" => 1,
409 "WGL_NV_vertex_array_range" => 1,
410 "WGL_WINE_pixel_format_passthrough" => 1,
411 "WGL_WINE_query_renderer" => 1,
414 my %supported_apis =
416 "gl" => 1,
419 sub is_supported_api($)
421 my $api = shift;
422 foreach my $i (split /\|/, $api)
424 return 1 if defined $supported_apis{$i};
426 return 0;
429 # some functions need a hand-written wrapper
430 sub needs_wrapper($$)
432 my %funcs =
434 "glDebugEntry" => 1,
435 "glDebugMessageCallback" => 1,
436 "glDebugMessageCallbackAMD" => 1,
437 "glDebugMessageCallbackARB" => 1,
438 "glGetIntegerv" => 1,
439 "glGetString" => 1,
440 "glGetStringi" => 1,
441 "wglGetCurrentReadDCARB" => 1,
443 my ($name, $func) = @_;
445 return 1 if defined $funcs{$name};
446 # check if return value needs special handling
447 (my $type = $func->[0]->textContent()) =~ s/ $//;
448 return 1 if defined $remap_types{$type};
449 # check if one of the arguments needs special handling
450 foreach (@{$func->[1]})
452 $type = get_arg_type( $_ );
453 return 1 if defined $remap_types{$type};
455 return 0;
458 sub parse_file($)
460 my $file = shift;
461 my $xml = XML::LibXML->load_xml( location => $file );
462 my %functions;
463 my %enums;
465 # save all functions
466 foreach my $command ($xml->findnodes("/registry/commands/command"))
468 my $proto = @{$command->findnodes("./proto")}[0];
469 my $name = @{$command->findnodes("./proto/name")}[0];
470 $proto->removeChild( $name );
471 my @params = $command->findnodes("./param");
472 $functions{$name->textContent()} = [ $proto, \@params ];
475 # save all enums
476 foreach my $enum ($xml->findnodes("/registry/enums/enum"))
478 $enums{$enum->{name}} = $enum->{value};
481 # save all types
482 foreach my $type ($xml->findnodes("/registry/types/type"))
484 next if $type->{api};
485 my $name = @{$type->findnodes("./name")}[0];
486 next unless $name;
487 $name = $name->textContent;
488 push @gl_types, $name unless $gl_types{$name};
489 $gl_types{$name} = $type;
492 # generate norm functions
493 foreach my $feature ($xml->findnodes("/registry/feature"))
495 if ($feature->{api} eq "wgl")
497 foreach my $cmd ($feature->findnodes("./require/command"))
499 my $name = $cmd->{name};
500 if (defined $remapped_wgl_functions{$name})
502 next unless $remapped_wgl_functions{$name};
503 $name = $remapped_wgl_functions{$name};
505 $wgl_functions{$name} = $functions{$cmd->{name}};
507 foreach my $name (@extra_wgl_functions)
509 $wgl_functions{$name} = $functions{$name} if defined $functions{$name};
512 next unless defined $norm_categories{$feature->{name}};
513 foreach my $cmd ($feature->findnodes("./require/command"))
515 $norm_functions{$cmd->{name}} = $functions{$cmd->{name}};
517 foreach my $enum ($feature->findnodes("./require/enum"))
519 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
523 # generate extension functions from norm functions, if they are newer than the category
524 foreach my $feature ($xml->findnodes("/registry/feature"))
526 next if defined $norm_categories{$feature->{name}};
527 next unless is_supported_api( $feature->{api} );
528 foreach my $cmd ($feature->findnodes("./require/command"))
530 my $name = $cmd->{name};
531 next if $norm_functions{$name} || $ext_functions{$name};
532 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $feature->{name} ] ];
534 foreach my $enum ($feature->findnodes("./require/enum"))
536 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
540 # generate extension functions
541 foreach my $ext ($xml->findnodes("/registry/extensions/extension"))
543 if ($ext->{supported} eq "wgl")
545 next unless defined $supported_wgl_extensions{$ext->{name}};
546 foreach my $cmd ($ext->findnodes("./require/command"))
548 my $name = $cmd->{name};
549 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name} ] ];
551 foreach my $enum ($ext->findnodes("./require/enum"))
553 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
555 next;
557 next unless is_supported_api( $ext->{supported} );
558 foreach my $req ($ext->findnodes("./require"))
560 next unless !$req->{api} || $req->{api} eq "gl";
561 foreach my $cmd ($req->findnodes("./command"))
563 my $name = $cmd->{name};
564 next if $norm_functions{$name};
565 if (!$ext_functions{$name})
567 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name} ] ];
569 else
571 push @{$ext_functions{$name}->[2]}, $ext->{name};
575 foreach my $enum ($ext->findnodes("./require/enum"))
577 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
582 parse_file( "gl-$commit.xml" );
583 parse_file( "wgl-$commit.xml" );
584 parse_file( "winegl.xml" );
587 # Get the current wgl_driver.h version
589 my $wgl_version = 0;
590 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
591 while (<HEADER>)
593 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
594 $wgl_version = $1;
595 last;
597 close HEADER;
600 # Generate the wgl_driver.h file
602 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
603 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
604 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
605 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
606 print HEADER "#ifndef WINE_GLAPI\n";
607 print HEADER "#define WINE_GLAPI\n";
608 print HEADER "#endif\n\n";
610 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
612 print HEADER "struct wgl_context;\n";
613 print HEADER "struct wgl_pbuffer;\n\n";
615 print HEADER "struct opengl_funcs\n{\n";
616 print HEADER " struct\n {\n";
617 foreach (sort keys %wgl_functions)
619 next unless defined $supported_wgl_functions{$_};
620 print HEADER get_func_proto(" %-10s (WINAPI *p_%s)(%s);\n", $_, $wgl_functions{$_}, 1);
622 print HEADER " } wgl;\n\n";
624 print HEADER " struct\n {\n";
625 foreach (sort keys %norm_functions)
627 next if $_ eq "glDebugEntry";
628 print HEADER get_func_proto(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $norm_functions{$_}, 1);
630 print HEADER " } gl;\n\n";
632 print HEADER " struct\n {\n";
633 foreach (sort keys %ext_functions)
635 print HEADER get_func_proto(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $ext_functions{$_}, 1);
637 print HEADER " } ext;\n";
638 print HEADER "};\n\n";
640 print HEADER "#define ALL_WGL_FUNCS";
641 foreach (sort keys %norm_functions)
643 next if $_ eq "glDebugEntry";
644 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
646 print HEADER "\n\n";
648 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
649 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
650 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
651 close HEADER;
654 # Generate the wgl.h file
656 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
657 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
658 print HEADER "#ifndef __WINE_WGL_H\n";
659 print HEADER "#define __WINE_WGL_H\n\n";
661 print HEADER "#ifndef GLAPIENTRY\n";
662 print HEADER "#define GLAPIENTRY __stdcall\n";
663 print HEADER "#endif\n\n";
665 foreach (@gl_types)
667 my $type = $gl_types{$_}->textContent();
668 foreach my $t (keys %khronos_types) { $type =~ s/\s(\Q$t\E)\s/ $khronos_types{$t} /; }
669 printf HEADER $type . "\n";
671 print HEADER "\n";
673 my $maxlen = 1;
674 foreach (keys %gl_enums) { $maxlen = length($_) if length($_) > $maxlen; }
675 foreach (sort keys %gl_enums)
677 printf HEADER "#define %-*s %s\n", $maxlen, $_, $gl_enums{$_};
679 print HEADER "\n";
681 foreach (sort keys %norm_functions)
683 printf HEADER "%s;\n", get_func_proto("%-10s GLAPIENTRY %s(%s)", $_, $norm_functions{$_}, 0);
686 print HEADER "\n#endif /* __WINE_WGL_H */\n";
687 close HEADER;
690 # Now, generate the output files. First, the spec file.
692 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
694 foreach (sort keys %norm_functions) {
695 printf SPEC "%s\n", generate_spec_entry( $_, $norm_functions{$_} );
697 foreach (sort keys %wgl_functions) {
698 printf SPEC "%s\n", generate_spec_entry( $_, $wgl_functions{$_} );
701 close(SPEC);
703 my $file_header =
704 "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n" .
705 "#include \"config.h\"\n" .
706 "#include <stdarg.h>\n" .
707 "#include \"winternl.h\"\n" .
708 "#include \"opengl_ext.h\"\n" .
709 "#include \"wine/debug.h\"\n\n";
711 $file_header .= "WINE_DEFAULT_DEBUG_CHANNEL(opengl);\n\n" if $gen_traces;
714 # After the spec file, the opengl_norm.c file
716 open(NORM, ">$norm_file") or die "cannot create $norm_file";
717 print NORM $file_header;
719 foreach (sort keys %norm_functions) {
720 next if needs_wrapper( $_, $norm_functions{$_} );
721 print NORM GenerateThunk($_, $norm_functions{$_}, "gl");
724 foreach (sort keys %wgl_functions) {
725 next unless defined $supported_wgl_functions{$_};
726 print NORM generate_null_func($_, $wgl_functions{$_}, " WINAPI");
728 foreach (sort keys %norm_functions) {
729 print NORM generate_null_func($_, $norm_functions{$_}, "");
731 foreach (sort keys %ext_functions) {
732 print NORM generate_null_func($_, $ext_functions{$_}, "");
735 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
736 foreach (sort keys %wgl_functions)
738 next unless defined $supported_wgl_functions{$_};
739 print NORM " null_$_,\n";
741 print NORM " },\n {\n";
742 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
743 print NORM " },\n {\n";
744 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
745 print NORM " }\n};\n";
747 close(NORM);
750 # Finally, more complex, the opengl_ext.c file
752 open(EXT, ">$ext_file") or die "cannot create $ext_file";
753 print EXT $file_header;
755 # The thunks themselves....
756 my $count = keys %ext_functions;
757 my $wrappers = "";
758 print EXT "const int extension_registry_size = $count;\n\n";
759 foreach (sort keys %ext_functions) {
760 if (needs_wrapper( $_, $ext_functions{$_} ))
762 $wrappers .= get_func_proto("extern %s WINAPI %s(%s) DECLSPEC_HIDDEN;\n", $_, $ext_functions{$_}, 0);
764 else
766 print EXT "static " . GenerateThunk($_, $ext_functions{$_}, "ext");
769 print EXT $wrappers;
771 # Then the table giving the string <-> function correspondence */
772 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
773 my $i = 0;
774 foreach (sort keys %ext_functions) {
775 my $func_ref = $ext_functions{$_};
776 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
777 if ($i != $count-1) {
778 print EXT ",";
780 $i++;
781 print EXT "\n";
783 print EXT "};\n";
785 close(EXT);