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
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 # If set to 1, generate TRACEs for each OpenGL function
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
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" ],
143 "HGLRC" => "struct wgl_context *",
144 "HPBUFFERARB" => "struct wgl_pbuffer *",
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
163 my $ret = $arg->textContent();
164 my @type = $arg->findnodes("./ptype");
168 my $type = $type[0]->textContent();
169 $ret =~ s/$type/$remap_types{$type}/ if defined $remap_types{$type};
174 sub get_func_trace
($$)
176 my ($name, $func) = @_;
179 foreach my $arg (@
{$func->[1]})
181 my $ptype = get_arg_type
( $arg );
182 my $pname = get_arg_name
( $arg );
183 my $param = $arg->textContent();
184 if ($param =~ /\*/ || $param =~ /\[/)
186 $trace_fmt .= ", %p";
187 $trace_arg .= ", $pname";
189 elsif (defined $arg_types{$ptype})
191 my $format = ${$arg_types{$ptype}}[1];
192 $trace_fmt .= ", " . ($format =~ /^%/ ?
$format : "%s");
193 $trace_arg .= ", " . (sprintf $format =~ /^%/ ?
"%s" : $format, $pname);
195 else { printf "Unknown type %s in %s\n", $param, $name; }
197 $trace_fmt =~ s/^, //;
198 return "TRACE( \"($trace_fmt)\\n\"$trace_arg );\n";
201 sub get_func_args
($$$)
203 my ($func, $decl_args, $convert_args) = @_;
205 foreach my $arg (@
{$func->[1]})
207 my $pname = get_arg_name
( $arg );
210 $ret .= " " . ($convert_args ? ConvertType
( $arg ) : $arg->textContent()) . ",";
218 $ret ||= "void" if $decl_args;
223 # This functions generates the thunk for a given function.
225 sub GenerateThunk
($$$)
227 my ($name, $func_ref, $prefix) = @_;
228 my $call_args = get_func_args
( $func_ref, 0, 0 );
230 my $ret = get_func_proto
( "%s WINAPI %s(%s)", $name, $func_ref, 0 );
232 # special case for functions that take an HDC as first parameter
233 if (@
{$func_ref->[1]} && get_arg_type
( ${$func_ref->[1]}[0] ) eq "HDC")
235 my $pname = get_arg_name
( ${$func_ref->[1]}[0] );
236 $ret .= " const struct opengl_funcs *funcs = get_dc_funcs( $pname );\n";
237 $ret .= " " . get_func_trace
( $name, $func_ref ) if $gen_traces;
238 $ret .= " if (!funcs || !funcs->$prefix.p_$name) return";
239 $ret .= " 0" unless is_void_func
( $func_ref );
244 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
245 $ret .= " " . get_func_trace
( $name, $func_ref ) if $gen_traces;
248 $ret .= "return " unless is_void_func
( $func_ref );
249 $ret .= "funcs->$prefix.p_$name($call_args);\n";
254 sub generate_null_func
($$$)
256 my ($name, $func_ref, $callconv) = @_;
259 return "" if $name eq "glDebugEntry";
261 $ret = get_func_proto
( "static %s$callconv null_%s(%s)", $name, $func_ref, 1 );
263 if ($name eq "glGetError")
265 $ret .= " return GL_INVALID_OPERATION;";
267 elsif (!is_void_func
( $func_ref ))
269 $ret .= " return 0;";
275 sub generate_spec_entry
($$)
277 my ($name, $func) = @_;
279 foreach my $arg (@
{$func->[1]})
281 my $ptype = get_arg_type
( $arg );
282 my $param = $arg->textContent();
283 if ($param =~ /[[*]/) {
285 } elsif (defined($arg_types{$ptype})) {
286 $args .= "$@$arg_types{$ptype}[0] ";
288 die "No conversion for func $name type $param\n";
291 $args = substr($args,1,-1);
292 return "@ stdcall $_($args)";
298 return 0 if @
{$func->[0]->findnodes("./ptype")};
299 return $func->[0]->textContent() eq "void ";
305 my @type = $p->findnodes("./ptype");
306 return @type ?
$type[0]->textContent() : "GLint";
312 my @name = $p->findnodes("./name");
313 return $name[0]->textContent();
316 sub get_func_proto
($$$$)
318 my ($format, $name, $func, $convert_args) = @_;
319 die "unknown func $name" unless defined $func->[0];
320 my $proto = $convert_args ? ConvertType
( $func->[0] ) : $func->[0]->textContent();
323 foreach my $arg (@
{$func->[1]})
325 $args .= " " . ($convert_args ? ConvertType
( $arg ) : $arg->textContent()) . ",";
329 return sprintf $format, $proto, $name, $args;
333 # Extract and checks the number of arguments
338 die "Usage: $name0 [version]\n";
340 my $version = $ARGV[0] || "1.1";
341 if ($version eq "1.0") {
342 %norm_categories = %cat_1_0;
343 } elsif ($version eq "1.1") {
344 %norm_categories = %cat_1_1;
345 } elsif ($version eq "1.2") {
346 %norm_categories = %cat_1_2;
347 } elsif ($version eq "1.3") {
348 %norm_categories = %cat_1_3;
349 } elsif ($version eq "1.4") {
350 %norm_categories = %cat_1_4;
351 } elsif ($version eq "1.5") {
352 %norm_categories = %cat_1_5;
354 die "Incorrect OpenGL version.\n";
358 # Fetch the registry files
360 my $url="https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry";
361 my $commit="03e1bfb87c4664d34dc7822fb591841eec747094";
363 -f
"gl-$commit.xml" || system "wget", "-O", "gl-$commit.xml", "$url/$commit/xml/gl.xml" || die "cannot download gl.xml";
364 -f
"wgl-$commit.xml" || system "wget", "-O", "wgl-$commit.xml", "$url/$commit/xml/wgl.xml" || die "cannot download wgl.xml";
368 # Then, create the list of all OpenGL functions using the registry
369 # files. This will create two hash-tables, one with all the function
370 # whose category matches the one listed in '@norm_categories', the other
371 # with all other functions.
373 # An element of the hash table is a reference to an array with these
376 # - XML node of the function prototype
378 # - reference to an array of XML nodes giving the list of arguments (an empty array
379 # for a 'void' function).
385 my (%gl_types, @gl_types); # also use an array to preserve declaration order
387 my %supported_wgl_functions =
389 "wglCopyContext" => 1,
390 "wglCreateContext" => 1,
391 "wglDeleteContext" => 1,
392 "wglDescribePixelFormat" => 1,
393 "wglGetPixelFormat" => 1,
394 "wglGetProcAddress" => 1,
395 "wglMakeCurrent" => 1,
396 "wglSetPixelFormat" => 1,
397 "wglShareLists" => 1,
398 "wglSwapBuffers" => 1,
401 my %remapped_wgl_functions =
403 "ChoosePixelFormat" => "wglChoosePixelFormat",
404 "DescribePixelFormat" => "wglDescribePixelFormat",
405 "GetPixelFormat" => "wglGetPixelFormat",
406 "GetEnhMetaFilePixelFormat" => 0,
407 "SetPixelFormat" => "wglSetPixelFormat",
408 "SwapBuffers" => "wglSwapBuffers",
409 "wglUseFontBitmaps" => 0,
410 "wglUseFontOutlines" => 0,
413 my @extra_wgl_functions = ( "wglGetDefaultProcAddress" );
415 my %supported_wgl_extensions =
417 "WGL_ARB_create_context" => 1,
418 "WGL_ARB_create_context_no_error" => 1,
419 "WGL_ARB_create_context_profile" => 1,
420 "WGL_ARB_extensions_string" => 1,
421 "WGL_ARB_make_current_read" => 1,
422 "WGL_ARB_multisample" => 1,
423 "WGL_ARB_pbuffer" => 1,
424 "WGL_ARB_pixel_format" => 1,
425 "WGL_ARB_framebuffer_sRGB" => 1,
426 "WGL_ARB_pixel_format_float" => 1,
427 "WGL_ARB_render_texture" => 1,
428 "WGL_ATI_pixel_format_float" => 1,
429 "WGL_EXT_create_context_es2_profile" => 1,
430 "WGL_EXT_extensions_string" => 1,
431 "WGL_EXT_framebuffer_sRGB" => 1,
432 "WGL_EXT_pixel_format_packed_float" => 1,
433 "WGL_EXT_swap_control" => 1,
434 "WGL_EXT_swap_control_tear" => 1,
435 "WGL_NV_float_buffer" => 1,
436 "WGL_NV_render_depth_texture" => 1,
437 "WGL_NV_render_texture_rectangle" => 1,
438 "WGL_NV_vertex_array_range" => 1,
439 "WGL_WINE_pixel_format_passthrough" => 1,
440 "WGL_WINE_query_renderer" => 1,
448 sub is_supported_api
($)
451 foreach my $i (split /\|/, $api)
453 return 1 if defined $supported_apis{$i};
458 # some functions need a hand-written wrapper
459 sub needs_wrapper
($$)
464 "glDebugMessageCallback" => 1,
465 "glDebugMessageCallbackAMD" => 1,
466 "glDebugMessageCallbackARB" => 1,
467 "glGetIntegerv" => 1,
470 "wglGetCurrentReadDCARB" => 1,
472 my ($name, $func) = @_;
474 return 1 if defined $funcs{$name};
475 # check if return value needs special handling
476 (my $type = $func->[0]->textContent()) =~ s/ $//;
477 return 1 if defined $remap_types{$type};
478 # check if one of the arguments needs special handling
479 foreach (@
{$func->[1]})
481 $type = get_arg_type
( $_ );
482 return 1 if defined $remap_types{$type};
490 my $xml = XML
::LibXML
->load_xml( location
=> $file );
495 foreach my $command ($xml->findnodes("/registry/commands/command"))
497 my $proto = @
{$command->findnodes("./proto")}[0];
498 my $name = @
{$command->findnodes("./proto/name")}[0];
499 $proto->removeChild( $name );
500 my @params = $command->findnodes("./param");
501 $functions{$name->textContent()} = [ $proto, \
@params ];
505 foreach my $enum ($xml->findnodes("/registry/enums/enum"))
507 $enums{$enum->{name
}} = $enum->{value
};
511 foreach my $type ($xml->findnodes("/registry/types/type"))
513 next if $type->{api
};
514 my $name = @
{$type->findnodes("./name")}[0];
516 $name = $name->textContent;
517 push @gl_types, $name unless $gl_types{$name};
518 $gl_types{$name} = $type;
521 # generate norm functions
522 foreach my $feature ($xml->findnodes("/registry/feature"))
524 if ($feature->{api
} eq "wgl")
526 foreach my $cmd ($feature->findnodes("./require/command"))
528 my $name = $cmd->{name
};
529 if (defined $remapped_wgl_functions{$name})
531 next unless $remapped_wgl_functions{$name};
532 $name = $remapped_wgl_functions{$name};
534 $wgl_functions{$name} = $functions{$cmd->{name
}};
536 foreach my $name (@extra_wgl_functions)
538 $wgl_functions{$name} = $functions{$name} if defined $functions{$name};
541 next unless defined $norm_categories{$feature->{name
}};
542 foreach my $cmd ($feature->findnodes("./require/command"))
544 $norm_functions{$cmd->{name
}} = $functions{$cmd->{name
}};
546 foreach my $enum ($feature->findnodes("./require/enum"))
548 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
552 # generate extension functions from norm functions, if they are newer than the category
553 foreach my $feature ($xml->findnodes("/registry/feature"))
555 next if defined $norm_categories{$feature->{name
}};
556 next unless is_supported_api
( $feature->{api
} );
557 foreach my $cmd ($feature->findnodes("./require/command"))
559 my $name = $cmd->{name
};
560 next if $norm_functions{$name} || $ext_functions{$name};
561 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $feature->{name
} ] ];
563 foreach my $enum ($feature->findnodes("./require/enum"))
565 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
569 # generate extension functions
570 foreach my $ext ($xml->findnodes("/registry/extensions/extension"))
572 if ($ext->{supported
} eq "wgl")
574 next unless defined $supported_wgl_extensions{$ext->{name
}};
575 foreach my $cmd ($ext->findnodes("./require/command"))
577 my $name = $cmd->{name
};
578 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name
} ] ];
580 foreach my $enum ($ext->findnodes("./require/enum"))
582 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
586 next unless is_supported_api
( $ext->{supported
} );
587 foreach my $req ($ext->findnodes("./require"))
589 next unless !$req->{api
} || $req->{api
} eq "gl";
590 foreach my $cmd ($req->findnodes("./command"))
592 my $name = $cmd->{name
};
593 next if $norm_functions{$name};
594 if (!$ext_functions{$name})
596 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name
} ] ];
600 push @
{$ext_functions{$name}->[2]}, $ext->{name
};
604 foreach my $enum ($ext->findnodes("./require/enum"))
606 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
611 parse_file
( "gl-$commit.xml" );
612 parse_file
( "wgl-$commit.xml" );
613 parse_file
( "winegl.xml" );
616 # Get the current wgl_driver.h version
619 open HEADER
, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
622 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
629 # Generate the wgl_driver.h file
631 open HEADER
, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
632 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
633 print HEADER
"#ifndef __WINE_WGL_DRIVER_H\n";
634 print HEADER
"#define __WINE_WGL_DRIVER_H\n\n";
635 print HEADER
"#ifndef WINE_GLAPI\n";
636 print HEADER
"#define WINE_GLAPI\n";
637 print HEADER
"#endif\n\n";
639 printf HEADER
"#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
641 print HEADER
"struct wgl_context;\n";
642 print HEADER
"struct wgl_pbuffer;\n\n";
644 print HEADER
"struct opengl_funcs\n{\n";
645 print HEADER
" struct\n {\n";
646 foreach (sort keys %wgl_functions)
648 next unless defined $supported_wgl_functions{$_};
649 print HEADER get_func_proto
(" %-10s (WINAPI *p_%s)(%s);\n", $_, $wgl_functions{$_}, 1);
651 print HEADER
" } wgl;\n\n";
653 print HEADER
" struct\n {\n";
654 foreach (sort keys %norm_functions)
656 next if $_ eq "glDebugEntry";
657 print HEADER get_func_proto
(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $norm_functions{$_}, 1);
659 print HEADER
" } gl;\n\n";
661 print HEADER
" struct\n {\n";
662 foreach (sort keys %ext_functions)
664 print HEADER get_func_proto
(" %-10s (WINE_GLAPI *p_%s)(%s);\n", $_, $ext_functions{$_}, 1);
666 print HEADER
" } ext;\n";
667 print HEADER
"};\n\n";
669 print HEADER
"#define ALL_WGL_FUNCS";
670 foreach (sort keys %norm_functions)
672 next if $_ eq "glDebugEntry";
673 printf HEADER
" \\\n USE_GL_FUNC(\%s)", $_;
677 print HEADER
"extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n\n";
678 print HEADER
"#endif /* __WINE_WGL_DRIVER_H */\n";
682 # Generate the wgl.h file
684 open HEADER
, ">$wgl_file" or die "cannot create $wgl_file";
685 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
686 print HEADER
"#ifndef __WINE_WGL_H\n";
687 print HEADER
"#define __WINE_WGL_H\n\n";
689 print HEADER
"#ifndef GLAPIENTRY\n";
690 print HEADER
"#define GLAPIENTRY __stdcall\n";
691 print HEADER
"#endif\n\n";
695 my $type = $gl_types{$_}->textContent();
696 foreach my $t (keys %khronos_types) { $type =~ s/\s(\Q$t\E)\s/ $khronos_types{$t} /; }
697 printf HEADER
$type . "\n";
702 foreach (keys %gl_enums) { $maxlen = length($_) if length($_) > $maxlen; }
703 foreach (sort keys %gl_enums)
705 printf HEADER
"#define %-*s %s\n", $maxlen, $_, $gl_enums{$_};
709 foreach (sort keys %norm_functions)
711 printf HEADER
"%s;\n", get_func_proto
("%-10s GLAPIENTRY %s(%s)", $_, $norm_functions{$_}, 0);
714 print HEADER
"\n#endif /* __WINE_WGL_H */\n";
718 # Now, generate the output files. First, the spec file.
720 open(SPEC
, ">$spec_file") or die "cannot create $spec_file";
722 foreach (sort keys %norm_functions) {
723 printf SPEC
"%s\n", generate_spec_entry
( $_, $norm_functions{$_} );
725 foreach (sort keys %wgl_functions) {
726 printf SPEC
"%s\n", generate_spec_entry
( $_, $wgl_functions{$_} );
732 "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n" .
733 "#include \"config.h\"\n" .
734 "#include <stdarg.h>\n" .
735 "#include \"winternl.h\"\n" .
736 "#include \"opengl_ext.h\"\n" .
737 "#include \"wine/debug.h\"\n\n";
739 $file_header .= "WINE_DEFAULT_DEBUG_CHANNEL(opengl);\n\n" if $gen_traces;
742 # After the spec file, the opengl_norm.c file
744 open(NORM
, ">$norm_file") or die "cannot create $norm_file";
745 print NORM
$file_header;
747 foreach (sort keys %norm_functions) {
748 next if needs_wrapper
( $_, $norm_functions{$_} );
749 print NORM GenerateThunk
($_, $norm_functions{$_}, "gl");
752 foreach (sort keys %wgl_functions) {
753 next unless defined $supported_wgl_functions{$_};
754 print NORM generate_null_func
($_, $wgl_functions{$_}, " WINAPI");
756 foreach (sort keys %norm_functions) {
757 print NORM generate_null_func
($_, $norm_functions{$_}, "");
759 foreach (sort keys %ext_functions) {
760 print NORM generate_null_func
($_, $ext_functions{$_}, "");
763 print NORM
"\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
764 foreach (sort keys %wgl_functions)
766 next unless defined $supported_wgl_functions{$_};
767 print NORM
" null_$_,\n";
769 print NORM
" },\n {\n";
770 foreach (sort keys %norm_functions) { print NORM
" null_$_,\n" unless $_ eq "glDebugEntry"; }
771 print NORM
" },\n {\n";
772 foreach (sort keys %ext_functions) { print NORM
" null_$_,\n"; }
773 print NORM
" }\n};\n";
778 # Finally, more complex, the opengl_ext.c file
780 open(EXT
, ">$ext_file") or die "cannot create $ext_file";
781 print EXT
$file_header;
783 # The thunks themselves....
784 my $count = keys %ext_functions;
786 print EXT
"const int extension_registry_size = $count;\n\n";
787 foreach (sort keys %ext_functions) {
788 if (needs_wrapper
( $_, $ext_functions{$_} ))
790 $wrappers .= get_func_proto
("extern %s WINAPI %s(%s) DECLSPEC_HIDDEN;\n", $_, $ext_functions{$_}, 0);
794 print EXT
"static " . GenerateThunk
($_, $ext_functions{$_}, "ext");
799 # Then the table giving the string <-> function correspondence */
800 print EXT
"\nconst OpenGL_extension extension_registry[$count] = {\n";
802 foreach (sort keys %ext_functions) {
803 my $func_ref = $ext_functions{$_};
804 printf EXT
" { \"%s\", \"%s\", %s }", $_, join(" ", sort @
{$func_ref->[2]}), $_;
805 if ($i != $count-1) {