netapi32: Implement NetScheduleJobEnum.
[wine.git] / dlls / opengl32 / make_opengl
blobebdca6717579e57900da77fc720515f6371987b5
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 "GLenum" => [ "long", "%d" ],
102 "GLfixed" => [ "long", "%d" ],
103 "GLfloat" => [ "float", "%f" ],
104 "GLhalfNV" => [ "long", "%d" ],
105 "GLhandleARB" => [ "long", "%d" ],
106 "GLint" => [ "long", "%d" ],
107 "GLint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
108 "GLint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
109 "GLintptr" => [ "long", "%ld" ],
110 "GLintptrARB" => [ "long", "%ld" ],
111 "GLshort" => [ "long", "%d" ],
112 "GLsizei" => [ "long", "%d" ],
113 "GLsizeiptr" => [ "long", "%ld" ],
114 "GLsizeiptrARB" => [ "long", "%ld" ],
115 "GLstring" => [ "str", "wine_dbgstr_a(%s)" ],
116 "GLsync" => [ "ptr", "%p" ],
117 "GLubyte" => [ "long", "%d" ],
118 "GLuint" => [ "long", "%d" ],
119 "GLuint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
120 "GLuint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
121 "GLushort" => [ "long", "%d" ],
122 "GLvdpauSurfaceNV" => [ "long", "%ld" ],
123 "GLDEBUGPROC" => [ "ptr", "%p" ],
124 "GLDEBUGPROCARB" => [ "ptr", "%p" ],
125 "GLDEBUGPROCAMD" => [ "ptr", "%p" ],
126 "GLDEBUGPROCKHR" => [ "ptr", "%p" ],
127 "GLVULKANPROCNV" => [ "ptr", "%p" ],
128 "HDC" => [ "long", "%p" ],
129 "HGLRC" => [ "long", "%p" ],
130 "HPBUFFERARB" => [ "long", "%p" ],
131 "HENHMETAFILE" => [ "long", "%p" ],
132 "LPGLYPHMETRICSFLOAT" => [ "ptr", "%p" ],
133 "LPCSTR" => [ "str", "wine_dbgstr_a(%s)" ],
134 "UINT" => [ "long", "%u" ],
135 "DWORD" => [ "long", "%u" ],
136 "BOOL" => [ "long", "%u" ],
137 "FLOAT" => [ "float", "%f" ],
140 my %remap_types =
142 "HGLRC" => "struct wgl_context *",
143 "HPBUFFERARB" => "struct wgl_pbuffer *",
146 # Used to convert some types
148 sub ConvertType($)
150 my $arg = shift;
151 my $ret = $arg->textContent();
152 my @type = $arg->findnodes("./ptype");
154 if (@type)
156 my $type = $type[0]->textContent();
157 $ret =~ s/$type/$remap_types{$type}/ if defined $remap_types{$type};
159 return $ret;
163 # This functions generates the thunk for a given function.
165 sub GenerateThunk($$$)
167 my ($name, $func_ref, $prefix) = @_;
168 my $call_arg = "";
169 my $trace_call_arg = "";
170 my $trace_arg = "";
172 my $ret = get_func_proto( "%s WINAPI %s(%s)", $name, $func_ref, 0 );
173 foreach my $arg (@{$func_ref->[1]}) {
174 my $ptype = get_arg_type( $arg );
175 my $pname = get_arg_name( $arg );
176 my $param = $arg->textContent();
177 $call_arg .= " " . $pname . ",";
178 if ($param =~ /\*/ || $param =~ /\[/) {
179 $trace_arg .= ", %p";
180 $trace_call_arg .= ", " . $pname;
181 } elsif (defined $arg_types{$ptype}) {
182 my $format = ${$arg_types{$ptype}}[1];
183 $trace_arg .= ", " . ($format =~ /^%/ ? $format : "%s");
184 $trace_call_arg .= ", " . sprintf $format =~ /^%/ ? "%s" : $format, $pname;
186 else { printf "Unknown type %s in %s\n", $param, $name; }
188 $call_arg =~ s/,$/ /;
189 $trace_arg =~ s/^, //;
190 $ret .= "\n{\n";
191 # special case for functions that take an HDC as first parameter
192 if (@{$func_ref->[1]} && get_arg_type( ${$func_ref->[1]}[0] ) eq "HDC")
194 my $pname = get_arg_name( ${$func_ref->[1]}[0] );
195 $ret .= " const struct opengl_funcs *funcs = get_dc_funcs( $pname );\n";
196 $ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
197 $ret .= " if (!funcs || !funcs->$prefix.p_$name) return";
198 $ret .= " 0" unless is_void_func( $func_ref );
199 $ret .= ";\n";
201 else
203 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
204 $ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
206 $ret .= " ";
207 $ret .= "return " unless is_void_func( $func_ref );
208 $ret .= "funcs->$prefix.p_$name($call_arg);\n";
209 $ret .= "}\n\n";
210 return $ret;
213 sub generate_null_func($$)
215 my ($name, $func_ref) = @_;
216 my $ret;
218 return "" if $name eq "glDebugEntry";
220 $ret = get_func_proto( "static %s null_%s(%s)", $name, $func_ref, 1 );
221 $ret .= " {";
222 if ($name eq "glGetError")
224 $ret .= " return GL_INVALID_OPERATION;";
226 elsif (!is_void_func( $func_ref ))
228 $ret .= " return 0;";
230 $ret .= " }\n";
231 return $ret;
234 sub generate_spec_entry($$)
236 my ($name, $func) = @_;
237 my $args=" ";
238 foreach my $arg (@{$func->[1]})
240 my $ptype = get_arg_type( $arg );
241 my $param = $arg->textContent();
242 if ($param =~ /[[*]/) {
243 $args .= "ptr ";
244 } elsif (defined($arg_types{$ptype})) {
245 $args .= "$@$arg_types{$ptype}[0] ";
246 } else {
247 die "No conversion for func $name type $param\n";
250 $args = substr($args,1,-1);
251 return "@ stdcall $_($args)";
254 sub is_void_func($)
256 my $func = shift;
257 return 0 if @{$func->[0]->findnodes("./ptype")};
258 return $func->[0]->textContent() eq "void ";
261 sub get_arg_type($)
263 my $p = shift;
264 my @type = $p->findnodes("./ptype");
265 return @type ? $type[0]->textContent() : "GLint";
268 sub get_arg_name($)
270 my $p = shift;
271 my @name = $p->findnodes("./name");
272 return $name[0]->textContent();
275 sub get_func_proto($$$$)
277 my ($format, $name, $func, $convert_args) = @_;
278 die "unknown func $name" unless defined $func->[0];
279 my $proto = $convert_args ? ConvertType( $func->[0] ) : $func->[0]->textContent();
280 $proto =~ s/ $//;
281 my $args = "";
282 foreach my $arg (@{$func->[1]})
284 $args .= " " . ($convert_args ? ConvertType( $arg ) : $arg->textContent()) . ",";
286 $args =~ s/,$/ /;
287 $args ||= "void";
288 return sprintf $format, $proto, $name, $args;
292 # Extract and checks the number of arguments
294 if (@ARGV > 1) {
295 my $name0=$0;
296 $name0=~s%^.*/%%;
297 die "Usage: $name0 [version]\n";
299 my $version = $ARGV[0] || "1.1";
300 if ($version eq "1.0") {
301 %norm_categories = %cat_1_0;
302 } elsif ($version eq "1.1") {
303 %norm_categories = %cat_1_1;
304 } elsif ($version eq "1.2") {
305 %norm_categories = %cat_1_2;
306 } elsif ($version eq "1.3") {
307 %norm_categories = %cat_1_3;
308 } elsif ($version eq "1.4") {
309 %norm_categories = %cat_1_4;
310 } elsif ($version eq "1.5") {
311 %norm_categories = %cat_1_5;
312 } else {
313 die "Incorrect OpenGL version.\n";
317 # Fetch the registry files
319 -f "gl.xml" || system "wget https://raw.github.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml" || die "cannot download gl.xml";
320 -f "wgl.xml" || system "wget https://raw.github.com/KhronosGroup/OpenGL-Registry/master/xml/wgl.xml" || die "cannot download wgl.xml";
324 # Then, create the list of all OpenGL functions using the registry
325 # files. This will create two hash-tables, one with all the function
326 # whose category matches the one listed in '@norm_categories', the other
327 # with all other functions.
329 # An element of the hash table is a reference to an array with these
330 # elements :
332 # - XML node of the function prototype
334 # - reference to an array of XML nodes giving the list of arguments (an empty array
335 # for a 'void' function).
337 my %norm_functions;
338 my %ext_functions;
339 my %wgl_functions;
340 my %gl_enums;
341 my (%gl_types, @gl_types); # also use an array to preserve declaration order
343 my %supported_wgl_functions =
345 "wglCopyContext" => 1,
346 "wglCreateContext" => 1,
347 "wglDeleteContext" => 1,
348 "wglDescribePixelFormat" => 1,
349 "wglGetPixelFormat" => 1,
350 "wglGetProcAddress" => 1,
351 "wglMakeCurrent" => 1,
352 "wglSetPixelFormat" => 1,
353 "wglShareLists" => 1,
354 "wglSwapBuffers" => 1,
357 my %remapped_wgl_functions =
359 "ChoosePixelFormat" => "wglChoosePixelFormat",
360 "DescribePixelFormat" => "wglDescribePixelFormat",
361 "GetPixelFormat" => "wglGetPixelFormat",
362 "GetEnhMetaFilePixelFormat" => 0,
363 "SetPixelFormat" => "wglSetPixelFormat",
364 "SwapBuffers" => "wglSwapBuffers",
365 "wglUseFontBitmaps" => 0,
366 "wglUseFontOutlines" => 0,
369 my %supported_wgl_extensions =
371 "WGL_ARB_create_context" => 1,
372 "WGL_ARB_create_context_no_error" => 1,
373 "WGL_ARB_create_context_profile" => 1,
374 "WGL_ARB_extensions_string" => 1,
375 "WGL_ARB_make_current_read" => 1,
376 "WGL_ARB_multisample" => 1,
377 "WGL_ARB_pbuffer" => 1,
378 "WGL_ARB_pixel_format" => 1,
379 "WGL_ARB_framebuffer_sRGB" => 1,
380 "WGL_ARB_pixel_format_float" => 1,
381 "WGL_ARB_render_texture" => 1,
382 "WGL_ATI_pixel_format_float" => 1,
383 "WGL_EXT_create_context_es2_profile" => 1,
384 "WGL_EXT_extensions_string" => 1,
385 "WGL_EXT_framebuffer_sRGB" => 1,
386 "WGL_EXT_pixel_format_packed_float" => 1,
387 "WGL_EXT_swap_control" => 1,
388 "WGL_EXT_swap_control_tear" => 1,
389 "WGL_NV_float_buffer" => 1,
390 "WGL_NV_render_depth_texture" => 1,
391 "WGL_NV_render_texture_rectangle" => 1,
392 "WGL_NV_vertex_array_range" => 1,
393 "WGL_WINE_pixel_format_passthrough" => 1,
394 "WGL_WINE_query_renderer" => 1,
397 my %supported_apis =
399 "gl" => 1,
402 sub is_supported_api($)
404 my $api = shift;
405 foreach my $i (split /\|/, $api)
407 return 1 if defined $supported_apis{$i};
409 return 0;
412 # some functions need a hand-written wrapper
413 sub needs_wrapper($$)
415 my %funcs =
417 "glDebugEntry" => 1,
418 "glGetIntegerv" => 1,
419 "glGetString" => 1,
420 "glGetStringi" => 1,
421 "wglGetCurrentReadDCARB" => 1,
423 my ($name, $func) = @_;
425 return 1 if defined $funcs{$name};
426 # check if return value needs special handling
427 (my $type = $func->[0]->textContent()) =~ s/ $//;
428 return 1 if defined $remap_types{$type};
429 # check if one of the arguments needs special handling
430 foreach (@{$func->[1]})
432 $type = get_arg_type( $_ );
433 return 1 if defined $remap_types{$type};
435 return 0;
438 sub parse_file($)
440 my $file = shift;
441 my $xml = XML::LibXML->load_xml( location => $file );
442 my %functions;
443 my %enums;
445 # save all functions
446 foreach my $command ($xml->findnodes("/registry/commands/command"))
448 my $proto = @{$command->findnodes("./proto")}[0];
449 my $name = @{$command->findnodes("./proto/name")}[0];
450 $proto->removeChild( $name );
451 my @params = $command->findnodes("./param");
452 $functions{$name->textContent()} = [ $proto, \@params ];
455 # save all enums
456 foreach my $enum ($xml->findnodes("/registry/enums/enum"))
458 $enums{$enum->{name}} = $enum->{value};
461 # save all types
462 foreach my $type ($xml->findnodes("/registry/types/type"))
464 next if $type->{api};
465 my $name = @{$type->findnodes("./name")}[0];
466 next unless $name;
467 $name = $name->textContent;
468 push @gl_types, $name unless $gl_types{$name};
469 $gl_types{$name} = $type;
472 # generate norm functions
473 foreach my $feature ($xml->findnodes("/registry/feature"))
475 if ($feature->{api} eq "wgl")
477 foreach my $cmd ($feature->findnodes("./require/command"))
479 my $name = $cmd->{name};
480 if (defined $remapped_wgl_functions{$name})
482 next unless $remapped_wgl_functions{$name};
483 $name = $remapped_wgl_functions{$name};
485 $wgl_functions{$name} = $functions{$cmd->{name}};
488 next unless defined $norm_categories{$feature->{name}};
489 foreach my $cmd ($feature->findnodes("./require/command"))
491 $norm_functions{$cmd->{name}} = $functions{$cmd->{name}};
493 foreach my $enum ($feature->findnodes("./require/enum"))
495 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
499 # generate extension functions from norm functions, if they are newer than the category
500 foreach my $feature ($xml->findnodes("/registry/feature"))
502 next if defined $norm_categories{$feature->{name}};
503 next unless is_supported_api( $feature->{api} );
504 foreach my $cmd ($feature->findnodes("./require/command"))
506 my $name = $cmd->{name};
507 next if $norm_functions{$name} || $ext_functions{$name};
508 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $feature->{name} ] ];
510 foreach my $enum ($feature->findnodes("./require/enum"))
512 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
516 # generate extension functions
517 foreach my $ext ($xml->findnodes("/registry/extensions/extension"))
519 if ($ext->{supported} eq "wgl")
521 next unless defined $supported_wgl_extensions{$ext->{name}};
522 foreach my $cmd ($ext->findnodes("./require/command"))
524 my $name = $cmd->{name};
525 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name} ] ];
527 foreach my $enum ($ext->findnodes("./require/enum"))
529 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
531 next;
533 next unless is_supported_api( $ext->{supported} );
534 foreach my $req ($ext->findnodes("./require"))
536 next unless !$req->{api} || $req->{api} eq "gl";
537 foreach my $cmd ($req->findnodes("./command"))
539 my $name = $cmd->{name};
540 next if $norm_functions{$name};
541 if (!$ext_functions{$name})
543 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name} ] ];
545 else
547 push @{$ext_functions{$name}->[2]}, $ext->{name};
551 foreach my $enum ($ext->findnodes("./require/enum"))
553 $gl_enums{$enum->{name}} = $enums{$enum->{name}};
558 parse_file( "gl.xml" );
559 parse_file( "wgl.xml" );
560 parse_file( "winegl.xml" );
563 # Get the current wgl_driver.h version
565 my $wgl_version = 0;
566 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
567 while (<HEADER>)
569 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
570 $wgl_version = $1;
571 last;
573 close HEADER;
576 # Generate the wgl_driver.h file
578 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
579 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
580 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
581 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
582 print HEADER "#ifndef WINE_GLAPI\n";
583 print HEADER "#define WINE_GLAPI\n";
584 print HEADER "#endif\n\n";
586 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
588 print HEADER "struct wgl_context;\n";
589 print HEADER "struct wgl_pbuffer;\n\n";
591 print HEADER "struct opengl_funcs\n{\n";
592 print HEADER " struct\n {\n";
593 foreach (sort keys %wgl_functions)
595 next unless defined $supported_wgl_functions{$_};
596 print HEADER get_func_proto(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $wgl_functions{$_}, 1);
598 print HEADER " } wgl;\n\n";
600 print HEADER " struct\n {\n";
601 foreach (sort keys %norm_functions)
603 next if $_ eq "glDebugEntry";
604 print HEADER get_func_proto(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $norm_functions{$_}, 1);
606 print HEADER " } gl;\n\n";
608 print HEADER " struct\n {\n";
609 foreach (sort keys %ext_functions)
611 print HEADER get_func_proto(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $ext_functions{$_}, 1);
613 print HEADER " } ext;\n";
614 print HEADER "};\n\n";
616 print HEADER "#define ALL_WGL_FUNCS";
617 foreach (sort keys %norm_functions)
619 next if $_ eq "glDebugEntry";
620 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
622 print HEADER "\n\n";
624 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
625 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
626 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
627 close HEADER;
630 # Generate the wgl.h file
632 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
633 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
634 print HEADER "#ifndef __WINE_WGL_H\n";
635 print HEADER "#define __WINE_WGL_H\n\n";
637 print HEADER "#ifndef GLAPIENTRY\n";
638 print HEADER "#define GLAPIENTRY __stdcall\n";
639 print HEADER "#endif\n\n";
641 print HEADER "#undef near\n";
642 print HEADER "#undef far\n\n";
644 foreach (@gl_types)
646 printf HEADER $gl_types{$_}->textContent() . "\n";
648 print HEADER "\n";
650 my $maxlen = 1;
651 foreach (keys %gl_enums) { $maxlen = length($_) if length($_) > $maxlen; }
652 foreach (sort keys %gl_enums)
654 printf HEADER "#define %-*s %s\n", $maxlen, $_, $gl_enums{$_};
656 print HEADER "\n";
658 foreach (sort keys %norm_functions)
660 printf HEADER "%s;\n", get_func_proto("%-10s GLAPIENTRY %s(%s)", $_, $norm_functions{$_}, 0);
663 print HEADER "\n#endif /* __WINE_WGL_H */\n";
664 close HEADER;
667 # Now, generate the output files. First, the spec file.
669 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
671 foreach (sort keys %norm_functions) {
672 printf SPEC "%s\n", generate_spec_entry( $_, $norm_functions{$_} );
674 foreach (sort keys %wgl_functions) {
675 printf SPEC "%s\n", generate_spec_entry( $_, $wgl_functions{$_} );
678 close(SPEC);
680 my $file_header =
681 "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n" .
682 "#include \"config.h\"\n" .
683 "#include <stdarg.h>\n" .
684 "#include \"winternl.h\"\n" .
685 "#include \"opengl_ext.h\"\n" .
686 "#include \"wine/debug.h\"\n\n";
688 $file_header .= "WINE_DEFAULT_DEBUG_CHANNEL(opengl);\n\n" if $gen_traces;
691 # After the spec file, the opengl_norm.c file
693 open(NORM, ">$norm_file") or die "cannot create $norm_file";
694 print NORM $file_header;
696 foreach (sort keys %norm_functions) {
697 next if needs_wrapper( $_, $norm_functions{$_} );
698 print NORM GenerateThunk($_, $norm_functions{$_}, "gl");
701 foreach (sort keys %wgl_functions) {
702 next unless defined $supported_wgl_functions{$_};
703 print NORM generate_null_func($_, $wgl_functions{$_});
705 foreach (sort keys %norm_functions) {
706 print NORM generate_null_func($_, $norm_functions{$_});
708 foreach (sort keys %ext_functions) {
709 print NORM generate_null_func($_, $ext_functions{$_});
712 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
713 foreach (sort keys %wgl_functions)
715 next unless defined $supported_wgl_functions{$_};
716 print NORM " null_$_,\n";
718 print NORM " },\n {\n";
719 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
720 print NORM " },\n {\n";
721 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
722 print NORM " }\n};\n";
724 close(NORM);
727 # Finally, more complex, the opengl_ext.c file
729 open(EXT, ">$ext_file") or die "cannot create $ext_file";
730 print EXT $file_header;
732 # The thunks themselves....
733 my $count = keys %ext_functions;
734 my $wrappers = "";
735 print EXT "const int extension_registry_size = $count;\n\n";
736 foreach (sort keys %ext_functions) {
737 if (needs_wrapper( $_, $ext_functions{$_} ))
739 $wrappers .= get_func_proto("extern %s WINAPI %s(%s) DECLSPEC_HIDDEN;\n", $_, $ext_functions{$_}, 0);
741 else
743 print EXT "static " . GenerateThunk($_, $ext_functions{$_}, "ext");
746 print EXT $wrappers;
748 # Then the table giving the string <-> function correspondence */
749 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
750 my $i = 0;
751 foreach (sort keys %ext_functions) {
752 my $func_ref = $ext_functions{$_};
753 printf EXT " { \"%s\", \"%s\", %s }", $_, join(" ", sort @{$func_ref->[2]}), $_;
754 if ($i != $count-1) {
755 print EXT ",";
757 $i++;
758 print EXT "\n";
760 print EXT "};\n";
762 close(EXT);