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 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 # - include/wine/wgl_driver.h: definitions for the tables of OpenGL functions.
31 # Copyright 2000 Lionel Ulmer
32 # Copyright 2012 Alexandre Julliard
34 # This library is free software; you can redistribute it and/or
35 # modify it under the terms of the GNU Lesser General Public
36 # License as published by the Free Software Foundation; either
37 # version 2.1 of the License, or (at your option) any later version.
39 # This library is distributed in the hope that it will be useful,
40 # but WITHOUT ANY WARRANTY; without even the implied warranty of
41 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 # Lesser General Public License for more details.
44 # You should have received a copy of the GNU Lesser General Public
45 # License along with this library; if not, write to the Free Software
46 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
52 my $spec_file = "opengl32.spec";
53 my $wgl_driver_file = "../../include/wine/wgl_driver.h";
54 my $wgl_file = "../../include/wine/wgl.h";
56 # If set to 1, generate TRACEs for each OpenGL function
60 # List of norm categories
62 my %cat_1_0 = ( "GL_VERSION_1_0" => 1 );
63 my %cat_1_1 = ( %cat_1_0, "GL_VERSION_1_1" => 1 );
64 my %cat_1_2 = ( %cat_1_1, "GL_VERSION_1_2" => 1 );
65 my %cat_1_3 = ( %cat_1_2, "GL_VERSION_1_3" => 1 );
66 my %cat_1_4 = ( %cat_1_3, "GL_VERSION_1_4" => 1 );
67 my %cat_1_5 = ( %cat_1_4, "GL_VERSION_1_5" => 1 );
69 my %norm_categories = ();
72 # This hash table gives the conversion between OpenGL types and
73 # the .spec type and debug format
77 "GLbitfield" => [ "long", "%d" ],
78 "GLboolean" => [ "long", "%d" ],
79 "GLbyte" => [ "long", "%d" ],
80 "GLchar" => [ "long", "%c" ],
81 "GLcharARB" => [ "long", "%c" ],
82 "GLclampd" => [ "double", "%f" ],
83 "GLclampf" => [ "float", "%f" ],
84 "GLclampx" => [ "long", "%d" ],
85 "GLdouble" => [ "double", "%f" ],
86 "GLeglClientBufferEXT" => [ "ptr", "%p" ],
87 "GLeglImageOES" => [ "ptr", "%p" ],
88 "GLenum" => [ "long", "%d" ],
89 "GLfixed" => [ "long", "%d" ],
90 "GLfloat" => [ "float", "%f" ],
91 "GLhalfNV" => [ "long", "%d" ],
92 "GLhandleARB" => [ "long", "%d" ],
93 "int" => [ "long", "%d" ],
94 "GLint" => [ "long", "%d" ],
95 "GLint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
96 "GLint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
97 "GLintptr" => [ "long", "%Id" ],
98 "GLintptrARB" => [ "long", "%Id" ],
99 "GLshort" => [ "long", "%d" ],
100 "GLsizei" => [ "long", "%d" ],
101 "GLsizeiptr" => [ "long", "%Id" ],
102 "GLsizeiptrARB" => [ "long", "%Id" ],
103 "GLstring" => [ "str", "wine_dbgstr_a(%s)" ],
104 "GLsync" => [ "ptr", "%p" ],
105 "GLubyte" => [ "long", "%d" ],
106 "GLuint" => [ "long", "%d" ],
107 "GLuint64" => [ "int64", "wine_dbgstr_longlong(%s)" ],
108 "GLuint64EXT" => [ "int64", "wine_dbgstr_longlong(%s)" ],
109 "GLushort" => [ "long", "%d" ],
110 "GLvdpauSurfaceNV" => [ "long", "%Id" ],
111 "GLDEBUGPROC" => [ "ptr", "%p" ],
112 "GLDEBUGPROCARB" => [ "ptr", "%p" ],
113 "GLDEBUGPROCAMD" => [ "ptr", "%p" ],
114 "GLDEBUGPROCKHR" => [ "ptr", "%p" ],
115 "GLVULKANPROCNV" => [ "ptr", "%p" ],
116 "HDC" => [ "long", "%p" ],
117 "HGLRC" => [ "long", "%p" ],
118 "HPBUFFERARB" => [ "long", "%p" ],
119 "HENHMETAFILE" => [ "long", "%p" ],
120 "LPGLYPHMETRICSFLOAT" => [ "ptr", "%p" ],
121 "LPCSTR" => [ "str", "wine_dbgstr_a(%s)" ],
122 "UINT" => [ "long", "%u" ],
123 "DWORD" => [ "long", "%lu" ],
124 "BOOL" => [ "long", "%u" ],
125 "FLOAT" => [ "float", "%f" ],
130 "HGLRC" => "struct wgl_context *",
131 "HPBUFFERARB" => "struct wgl_pbuffer *",
136 "double" => "double DECLSPEC_ALIGN(8)",
137 "khronos_int8_t" => "signed char",
138 "khronos_uint8_t" => "unsigned char",
139 "khronos_int16_t" => "short",
140 "khronos_uint16_t" => "unsigned short",
141 "khronos_int32_t" => "int",
142 "khronos_uint32_t" => "unsigned int",
143 "khronos_float_t" => "float",
146 my %manual_win_functions =
149 "wglChoosePixelFormat" => 1,
150 "wglCreateLayerContext" => 1,
151 "wglDescribeLayerPlane" => 1,
152 "wglGetCurrentContext" => 1,
153 "wglGetCurrentDC" => 1,
154 "wglGetDefaultProcAddress" => 1,
155 "wglGetLayerPaletteEntries" => 1,
156 "wglRealizeLayerPalette" => 1,
157 "wglSetLayerPaletteEntries" => 1,
158 "wglSwapLayerBuffers" => 1,
159 "wglUseFontBitmapsA" => 1,
160 "wglUseFontBitmapsW" => 1,
161 "wglUseFontOutlinesA" => 1,
162 "wglUseFontOutlinesW" => 1,
164 my %manual_win_thunks =
169 "glMapBufferARB" => 1,
170 "glMapBufferRange" => 1,
171 "glMapNamedBuffer" => 1,
172 "glMapNamedBufferEXT" => 1,
173 "glMapNamedBufferRange" => 1,
174 "glMapNamedBufferRangeEXT" => 1,
175 "glUnmapBuffer" => 1,
176 "glUnmapBufferARB" => 1,
177 "glUnmapNamedBuffer" => 1,
178 "glUnmapNamedBufferEXT" => 1,
179 "wglGetCurrentReadDCARB" => 1,
180 "wglGetExtensionsStringARB" => 1,
181 "wglGetExtensionsStringEXT" => 1,
182 "wglGetPixelFormat" => 1,
183 "wglGetProcAddress" => 1,
184 "wglQueryCurrentRendererStringWINE" => 1,
185 "wglQueryRendererStringWINE" => 1,
186 "wglSwapBuffers" => 1,
188 my %manual_wow64_thunks =
190 "glClientWaitSync" => 1,
193 "glGetBufferPointerv" => 1,
194 "glGetBufferPointervARB" => 1,
195 "glGetNamedBufferPointerv" => 1,
196 "glGetNamedBufferPointervEXT" => 1,
202 "glMapBufferARB" => 1,
203 "glMapBufferRange" => 1,
204 "glMapNamedBuffer" => 1,
205 "glMapNamedBufferEXT" => 1,
206 "glMapNamedBufferRange" => 1,
207 "glMapNamedBufferRangeEXT" => 1,
208 "glPathGlyphIndexRangeNV" => 1,
209 "glUnmapBuffer" => 1,
210 "glUnmapBufferARB" => 1,
211 "glUnmapNamedBuffer" => 1,
212 "glUnmapNamedBufferEXT" => 1,
214 "wglCreateContext" => 1,
215 "wglCreateContextAttribsARB" => 1,
216 "wglCreatePbufferARB" => 1,
217 "wglDeleteContext" => 1,
218 "wglGetExtensionsStringARB" => 1,
219 "wglGetExtensionsStringEXT" => 1,
220 "wglGetPbufferDCARB" => 1,
221 "wglGetProcAddress" => 1,
222 "wglGetProcAddress" => 1,
223 "wglMakeContextCurrentARB" => 1,
224 "wglMakeCurrent" => 1,
225 "wglQueryCurrentRendererStringWINE" => 1,
226 "wglQueryRendererStringWINE" => 1,
228 my %pointer_array_count =
230 "glCompileShaderIncludeARB" => "count",
231 "glCreateShaderProgramv" => "count",
232 "glGetUniformIndices" => "uniformCount",
233 "glMultiDrawElements" => "drawcount",
234 "glMultiDrawElementsBaseVertex" => "drawcount",
235 "glMultiDrawElementsEXT" => "primcount",
236 "glMultiModeDrawElementsIBM" => "primcount",
237 "glTransformFeedbackVaryings" => "count",
238 "glTransformFeedbackVaryingsEXT" => "count",
239 "glShaderSource" => "count",
240 "glShaderSourceARB" => "count",
241 "glBindBuffersRange" => "count",
242 "glBindVertexBuffers" => "count",
243 "glDrawCommandsNV" => "count",
244 "glVertexArrayVertexBuffers" => "count",
245 "glDrawCommandsStatesNV" => "count",
246 "glListDrawCommandsStatesClientNV" => "count",
248 my %pointer_is_offset =
250 "glGetPointerv" => "params",
251 "glGetPointervEXT" => "params",
252 "glGetVertexAttribPointerv" => "pointer",
253 "glGetVertexAttribPointervARB" => "pointer",
257 # Used to convert some types
262 my $ret = $arg->textContent();
263 my @type = $arg->findnodes("./ptype");
267 my $type = $type[0]->textContent();
268 $ret =~ s/$type/$remap_types{$type}/ if defined $remap_types{$type};
273 sub get_func_trace
($$$)
275 my ($name, $func, $param_names) = @_;
278 foreach my $arg (@
{$func->[1]})
280 my $ptype = get_arg_type
( $arg );
281 my $pname = get_arg_name
( $arg );
282 my $param = $arg->textContent();
283 if ($param =~ /\*/ || $param =~ /\[/)
286 $trace_fmt .= "$pname " if $param_names;
288 $trace_arg .= ", $pname";
290 elsif (defined $arg_types{$ptype})
292 my $format = ${$arg_types{$ptype}}[1];
294 $trace_fmt .= "$pname " if $param_names;
295 $trace_fmt .= ($format =~ /^%/ ?
$format : "%s");
296 $trace_arg .= ", " . (sprintf $format =~ /^%/ ?
"%s" : $format, $pname);
298 else { printf "Unknown type %s in %s\n", $param, $name; }
300 $trace_fmt =~ s/^, //;
301 $trace_fmt = "($trace_fmt)" unless $param_names;
302 return "TRACE( \"$trace_fmt\\n\"$trace_arg );\n";
305 sub get_func_args
($$$$)
307 my ($func, $decl_args, $convert_args, $prefix) = @_;
309 foreach my $arg (@
{$func->[1]})
311 my $ptype = get_arg_type
( $arg );
312 my $pname = get_arg_name
( $arg );
315 $ret .= " " . ($convert_args ? ConvertType
( $arg ) : $arg->textContent()) . ",";
317 elsif ($convert_args && defined $remap_types{$ptype})
319 $ret .= " ($remap_types{$ptype})$prefix$pname,";
323 $ret .= " $prefix$pname,";
327 $ret ||= "void" if $decl_args;
333 my ($func, $convert_args) = @_;
334 my $ret = $convert_args ? ConvertType
( $func->[0] ) : $func->[0]->textContent();
339 sub generate_unix_thunk
($$$)
341 my ($name, $func, $prefix) = @_;
342 my $call_args = get_func_args
( $func, 0, 1, "params->" );
343 my $func_ret = get_func_ret
( $func, 0 );
346 $ret .= "NTSTATUS $prefix\_$name( void *args )\n";
348 $ret .= " struct $name\_params *params = args;\n";
349 # special case for functions that take an HDC as first parameter
350 if (@
{$func->[1]} && get_arg_type
( ${$func->[1]}[0] ) eq "HDC")
352 my $pname = get_arg_name
( ${$func->[1]}[0] );
353 $ret .= " const struct opengl_funcs *funcs = get_dc_funcs( params->$pname );\n";
354 $ret .= " if (!funcs || !funcs->$prefix.p_$name) return STATUS_NOT_IMPLEMENTED;\n";
358 $ret .= " const struct opengl_funcs *funcs = params->teb->glTable;\n";
361 $ret .= "params->ret = " unless is_void_func
( $func );
362 $ret .= "($func_ret)" if defined $remap_types{$func_ret};
363 $ret .= "funcs->$prefix.p_$name($call_args);\n";
364 $ret .= " return STATUS_SUCCESS;\n";
370 sub generate_win_thunk
($$)
372 my ($name, $func) = @_;
373 my $decl_args = get_func_args
( $func, 1, 0, "" );
374 my $func_ret = get_func_ret
( $func, 0 );
378 $ret .= "$func_ret WINAPI $name($decl_args)\n";
380 $ret .= " struct $name\_params args";
381 $params .= " .teb = NtCurrentTeb()";
382 foreach my $arg (@
{$func->[1]})
384 my $pname = get_arg_name
( $arg );
385 $params .= ", .$pname = $pname" unless $arg->textContent() =~ /\[/;
387 $ret .= " = {$params }";
389 $ret .= " NTSTATUS status;\n";
390 foreach my $arg (@
{$func->[1]})
392 my $pname = get_arg_name
( $arg );
393 $ret .= " memcpy( args.$pname, $pname, sizeof(args.$pname) );\n" if $arg->textContent() =~ /\[/;
395 $ret .= " " . get_func_trace
( $name, $func, 1 ) if $gen_traces;
396 $ret .= " if ((status = UNIX_CALL( $name, &args ))) WARN( \"$name returned %#lx\\n\", status );\n";
397 $ret .= " return args.ret;\n" unless is_void_func
($func);
403 sub get_wow64_arg_type
($)
406 my $ptype = get_arg_type
( $arg );
407 return "void" if $ptype =~ /^void$/;
408 return "PTR32" if $arg->textContent() =~ /(PROC|sizeiptr|intptr|\*|\[)/;
409 return $ptype unless defined $arg_types{$ptype};
410 return "PTR32" if ${$arg_types{$ptype}}[0] =~ /(ptr|str)/;
411 return "PTR32" if ${$arg_types{$ptype}}[1] =~ /%p/;
415 sub generate_wow64_thunk
($$$)
417 my ($name, $func, $prefix) = @_;
418 my $call_args = get_func_args
( $func, 0, 1, "params->" );
419 my $func_ret = get_func_ret
( $func, 0 );
420 my $need_manual_thunk = 0;
423 $ret .= "static NTSTATUS wow64_$prefix\_$name( void *args )\n";
425 $ret .= " struct\n {\n";
426 $ret .= " PTR32 teb;\n";
427 foreach my $arg (@
{$func->[1]})
429 my $ptype = get_wow64_arg_type
( $arg );
430 my $pname = get_arg_name
( $arg );
431 $ret .= " $ptype $pname;\n";
432 $need_manual_thunk = 1 if $arg->textContent() =~ /(\*.*\*|\[|(sizei|int)ptr.*\*)/ &&
433 !defined $pointer_array_count{$_} && !defined $pointer_is_offset{$_};
435 if (!is_void_func
($func))
437 my $ptype = get_wow64_arg_type
( $func->[0] );
438 $ret .= " $ptype ret;\n";
440 $ret .= " } *params32 = args;\n";
441 $ret .= " struct $name\_params params =\n";
443 $ret .= " .teb = get_teb64(params32->teb),\n";
444 foreach my $arg (@
{$func->[1]})
446 next if $arg->textContent() =~ /(\*.*\*|\[|(sizei|int)ptr.*\*)/;
447 my $ptype = get_arg_type
( $arg );
448 my $pname = get_arg_name
( $arg );
449 if ($arg->textContent() =~ /(sizei|int)ptr/)
451 $ret .= " .$pname = ($ptype)ULongToPtr(params32->$pname),\n";
453 elsif (get_wow64_arg_type
( $arg ) =~ /PTR32/)
455 $ret .= " .$pname = ULongToPtr(params32->$pname),\n";
459 $ret .= " .$pname = params32->$pname,\n";
464 if ($need_manual_thunk || get_wow64_arg_type
( $func->[0] ) =~ /PTR32/)
466 $ret .= " FIXME( \"params32 %p, params %p stub!\\n\", params32, ¶ms );\n";
467 $ret .= " return STATUS_NOT_IMPLEMENTED;\n";
472 $ret .= " NTSTATUS status;\n";
474 foreach my $arg (@
{$func->[1]})
476 next unless $arg->textContent() =~ /\*.*\*/ || $arg->textContent() =~ /(sizei|int)ptr.*\*/;
477 next unless defined $pointer_array_count{$_};
478 my $pname = get_arg_name
( $arg );
479 $ret .= " params.$pname = copy_wow64_ptr32s( (UINT_PTR)params32->$pname, params32->$pointer_array_count{$_} );\n";
482 $ret .= " status = $prefix\_$name( ¶ms );\n";
483 if (!is_void_func
( $func ))
485 $ret .= " params32->ret = ";
486 $ret .= "(UINT_PTR)" if get_wow64_arg_type
( $func->[0] ) =~ /PTR32/;
487 $ret .= "params.ret;\n";
490 foreach my $arg (@
{$func->[1]})
492 next unless $arg->textContent() =~ /\*.*\*/ || $arg->textContent() =~ /(sizei|int)ptr.*\*/;
493 next unless defined $pointer_array_count{$_};
494 my $pname = get_arg_name
( $arg );
495 $ret .= " free( (void *)params.$pname );\n";
498 foreach my $arg (@
{$func->[1]})
500 next unless defined $pointer_is_offset{$_};
501 my $pname = get_arg_name
( $arg );
502 next unless $pname =~ $pointer_is_offset{$_};
503 $ret .= " params32->$pname = PtrToUlong( params.$pname );\n";
506 $ret .= " return status;\n";
512 sub generate_null_func
($$)
514 my ($name, $func) = @_;
515 my $decl_args = get_func_args
( $func, 1, 1, "" );
516 my $func_ret = get_func_ret
( $func, 1 );
519 return "" if $name eq "glDebugEntry";
521 $ret .= "static $func_ret null_$name($decl_args)";
523 if ($name eq "glGetError")
525 $ret .= " return GL_INVALID_OPERATION;";
527 elsif (!is_void_func
( $func ))
529 $ret .= " return 0;";
535 sub generate_spec_entry
($$)
537 my ($name, $func) = @_;
539 foreach my $arg (@
{$func->[1]})
541 my $ptype = get_arg_type
( $arg );
542 my $param = $arg->textContent();
543 if ($param =~ /[[*]/) {
545 } elsif (defined($arg_types{$ptype})) {
546 $args .= "$@$arg_types{$ptype}[0] ";
548 die "No conversion for func $name type $param\n";
551 $args = substr($args,1,-1);
552 return "@ stdcall $_($args)";
555 sub generate_func_params
($$)
557 my ($name, $func) = @_;
559 $ret .= sprintf "struct %s_params\n{\n", $name;
560 $ret .= " TEB *teb;\n";
561 foreach my $arg (@
{$func->[1]})
563 $ret .= sprintf " %s;\n", $arg->textContent();
565 $ret .= sprintf " %sret;\n", $func->[0]->textContent() unless is_void_func
($func);
573 return 0 if @
{$func->[0]->findnodes("./ptype")};
574 return $func->[0]->textContent() eq "void ";
579 my $p = (shift)->cloneNode(1);
580 my @name = $p->findnodes("./name");
581 $p->removeChild(@name) if @name;
582 my $ret = $p->textContent();
591 my @name = $p->findnodes("./name");
592 return $name[0]->textContent();
596 # Extract and checks the number of arguments
601 die "Usage: $name0 [version]\n";
603 my $version = $ARGV[0] || "1.1";
604 if ($version eq "1.0") {
605 %norm_categories = %cat_1_0;
606 } elsif ($version eq "1.1") {
607 %norm_categories = %cat_1_1;
608 } elsif ($version eq "1.2") {
609 %norm_categories = %cat_1_2;
610 } elsif ($version eq "1.3") {
611 %norm_categories = %cat_1_3;
612 } elsif ($version eq "1.4") {
613 %norm_categories = %cat_1_4;
614 } elsif ($version eq "1.5") {
615 %norm_categories = %cat_1_5;
617 die "Incorrect OpenGL version.\n";
621 # Fetch the registry files
623 my $url="https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry";
624 my $commit="03e1bfb87c4664d34dc7822fb591841eec747094";
626 -f
"gl-$commit.xml" || system "wget", "-O", "gl-$commit.xml", "$url/$commit/xml/gl.xml" || die "cannot download gl.xml";
627 -f
"wgl-$commit.xml" || system "wget", "-O", "wgl-$commit.xml", "$url/$commit/xml/wgl.xml" || die "cannot download wgl.xml";
631 # Then, create the list of all OpenGL functions using the registry
632 # files. This will create two hash-tables, one with all the function
633 # whose category matches the one listed in '@norm_categories', the other
634 # with all other functions.
636 # An element of the hash table is a reference to an array with these
639 # - XML node of the function prototype
641 # - reference to an array of XML nodes giving the list of arguments (an empty array
642 # for a 'void' function).
648 my (%gl_types, @gl_types); # also use an array to preserve declaration order
650 my %remapped_wgl_functions =
652 "ChoosePixelFormat" => "wglChoosePixelFormat",
653 "DescribePixelFormat" => "wglDescribePixelFormat",
654 "GetPixelFormat" => "wglGetPixelFormat",
655 "GetEnhMetaFilePixelFormat" => 0,
656 "SetPixelFormat" => "wglSetPixelFormat",
657 "SwapBuffers" => "wglSwapBuffers",
658 "wglUseFontBitmaps" => 0,
659 "wglUseFontOutlines" => 0,
662 my @extra_wgl_functions = ( "wglGetDefaultProcAddress" );
664 my %supported_wgl_extensions =
666 "WGL_ARB_create_context" => 1,
667 "WGL_ARB_create_context_no_error" => 1,
668 "WGL_ARB_create_context_profile" => 1,
669 "WGL_ARB_extensions_string" => 1,
670 "WGL_ARB_make_current_read" => 1,
671 "WGL_ARB_multisample" => 1,
672 "WGL_ARB_pbuffer" => 1,
673 "WGL_ARB_pixel_format" => 1,
674 "WGL_ARB_framebuffer_sRGB" => 1,
675 "WGL_ARB_pixel_format_float" => 1,
676 "WGL_ARB_render_texture" => 1,
677 "WGL_ATI_pixel_format_float" => 1,
678 "WGL_EXT_create_context_es2_profile" => 1,
679 "WGL_EXT_extensions_string" => 1,
680 "WGL_EXT_framebuffer_sRGB" => 1,
681 "WGL_EXT_pixel_format_packed_float" => 1,
682 "WGL_EXT_swap_control" => 1,
683 "WGL_EXT_swap_control_tear" => 1,
684 "WGL_NV_float_buffer" => 1,
685 "WGL_NV_render_depth_texture" => 1,
686 "WGL_NV_render_texture_rectangle" => 1,
687 "WGL_NV_vertex_array_range" => 1,
688 "WGL_WINE_pixel_format_passthrough" => 1,
689 "WGL_WINE_query_renderer" => 1,
697 sub is_supported_api
($)
700 foreach my $i (split /\|/, $api)
702 return 1 if defined $supported_apis{$i};
707 # some functions need a hand-written wrapper
708 sub needs_wrapper
($$)
710 my ($name, $func) = @_;
712 return 1 if $name =~ /^glDebugMessageCallback|^glGetString|^glGetIntegerv|^wglGetProcAddress/;
714 # check if return value needs special handling
715 (my $type = $func->[0]->textContent()) =~ s/ $//;
716 return 1 if defined $remap_types{$type};
717 # check if one of the arguments needs special handling
718 foreach (@
{$func->[1]})
720 $type = get_arg_type
( $_ );
721 return 1 if defined $remap_types{$type};
729 my $xml = XML
::LibXML
->load_xml( location
=> $file );
734 foreach my $command ($xml->findnodes("/registry/commands/command"))
736 my $proto = @
{$command->findnodes("./proto")}[0];
737 my $name = @
{$command->findnodes("./proto/name")}[0];
738 $proto->removeChild( $name );
739 my @params = $command->findnodes("./param");
740 $functions{$name->textContent()} = [ $proto, \
@params ];
744 foreach my $enum ($xml->findnodes("/registry/enums/enum"))
746 $enums{$enum->{name
}} = $enum->{value
};
750 foreach my $type ($xml->findnodes("/registry/types/type"))
752 next if $type->{api
};
753 my $name = @
{$type->findnodes("./name")}[0];
755 $name = $name->textContent;
756 push @gl_types, $name unless $gl_types{$name};
757 $gl_types{$name} = $type;
760 # generate norm functions
761 foreach my $feature ($xml->findnodes("/registry/feature"))
763 if ($feature->{api
} eq "wgl")
765 foreach my $cmd ($feature->findnodes("./require/command"))
767 my $name = $cmd->{name
};
768 if (defined $remapped_wgl_functions{$name})
770 next unless $remapped_wgl_functions{$name};
771 $name = $remapped_wgl_functions{$name};
773 $wgl_functions{$name} = $functions{$cmd->{name
}};
775 foreach my $name (@extra_wgl_functions)
777 $wgl_functions{$name} = $functions{$name} if defined $functions{$name};
780 next unless defined $norm_categories{$feature->{name
}};
781 foreach my $cmd ($feature->findnodes("./require/command"))
783 $norm_functions{$cmd->{name
}} = $functions{$cmd->{name
}};
785 foreach my $enum ($feature->findnodes("./require/enum"))
787 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
791 # generate extension functions from norm functions, if they are newer than the category
792 foreach my $feature ($xml->findnodes("/registry/feature"))
794 next if defined $norm_categories{$feature->{name
}};
795 next unless is_supported_api
( $feature->{api
} );
796 foreach my $cmd ($feature->findnodes("./require/command"))
798 my $name = $cmd->{name
};
799 next if $norm_functions{$name} || $ext_functions{$name};
800 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $feature->{name
} ] ];
802 foreach my $enum ($feature->findnodes("./require/enum"))
804 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
808 # generate extension functions
809 foreach my $ext ($xml->findnodes("/registry/extensions/extension"))
811 if ($ext->{supported
} eq "wgl")
813 next unless defined $supported_wgl_extensions{$ext->{name
}};
814 foreach my $cmd ($ext->findnodes("./require/command"))
816 my $name = $cmd->{name
};
817 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name
} ] ];
819 foreach my $enum ($ext->findnodes("./require/enum"))
821 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
825 next unless is_supported_api
( $ext->{supported
} );
826 foreach my $req ($ext->findnodes("./require"))
828 next unless !$req->{api
} || $req->{api
} eq "gl";
829 foreach my $cmd ($req->findnodes("./command"))
831 my $name = $cmd->{name
};
832 next if $norm_functions{$name};
833 if (!$ext_functions{$name})
835 $ext_functions{$name} = [ $functions{$name}[0], $functions{$name}[1], [ $ext->{name
} ] ];
839 push @
{$ext_functions{$name}->[2]}, $ext->{name
};
843 foreach my $enum ($ext->findnodes("./require/enum"))
845 $gl_enums{$enum->{name
}} = $enums{$enum->{name
}};
850 parse_file
( "gl-$commit.xml" );
851 parse_file
( "wgl-$commit.xml" );
852 parse_file
( "winegl.xml" );
855 # Get the current wgl_driver.h version
858 open HEADER
, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
861 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
868 # Generate the wgl_driver.h file
870 open HEADER
, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
871 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
872 print HEADER
"#ifndef __WINE_WGL_DRIVER_H\n";
873 print HEADER
"#define __WINE_WGL_DRIVER_H\n\n";
874 print HEADER
"#ifndef WINE_GLAPI\n";
875 print HEADER
"#define WINE_GLAPI\n";
876 print HEADER
"#endif\n\n";
878 printf HEADER
"#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
880 print HEADER
"struct wgl_context;\n";
881 print HEADER
"struct wgl_pbuffer;\n\n";
883 print HEADER
"struct opengl_funcs\n{\n";
884 print HEADER
" struct\n {\n";
885 foreach (sort keys %wgl_functions)
887 next if defined $manual_win_functions{$_};
888 my $decl_args = get_func_args
( $wgl_functions{$_}, 1, 1, "" );
889 my $func_ret = get_func_ret
( $wgl_functions{$_}, 1 );
890 printf HEADER
" %-10s (WINE_GLAPI *p_$_)($decl_args);\n", $func_ret;
892 print HEADER
" } wgl;\n\n";
894 print HEADER
" struct\n {\n";
895 foreach (sort keys %norm_functions)
897 next if defined $manual_win_functions{$_};
898 my $decl_args = get_func_args
( $norm_functions{$_}, 1, 1, "" );
899 my $func_ret = get_func_ret
( $norm_functions{$_}, 1 );
900 printf HEADER
" %-10s (WINE_GLAPI *p_$_)($decl_args);\n", $func_ret;
902 print HEADER
" } gl;\n\n";
904 print HEADER
" struct\n {\n";
905 foreach (sort keys %ext_functions)
907 next if defined $manual_win_functions{$_};
908 my $decl_args = get_func_args
( $ext_functions{$_}, 1, 1, "" );
909 my $func_ret = get_func_ret
( $ext_functions{$_}, 1 );
910 printf HEADER
" %-10s (WINE_GLAPI *p_$_)($decl_args);\n", $func_ret;
912 print HEADER
" } ext;\n";
913 print HEADER
"};\n\n";
915 print HEADER
"#define ALL_WGL_FUNCS";
916 foreach (sort keys %norm_functions)
918 next if defined $manual_win_functions{$_};
919 printf HEADER
" \\\n USE_GL_FUNC(\%s)", $_;
923 print HEADER
"extern struct opengl_funcs *__wine_get_wgl_driver( HDC hdc, UINT version );\n\n";
924 print HEADER
"#endif /* __WINE_WGL_DRIVER_H */\n";
928 # Generate the wgl.h file
930 open HEADER
, ">$wgl_file" or die "cannot create $wgl_file";
931 print HEADER
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
932 print HEADER
"#ifndef __WINE_WGL_H\n";
933 print HEADER
"#define __WINE_WGL_H\n\n";
935 print HEADER
"#ifndef GLAPIENTRY\n";
936 print HEADER
"#define GLAPIENTRY __stdcall\n";
937 print HEADER
"#endif\n\n";
941 my $type = $gl_types{$_}->textContent();
942 foreach my $t (keys %khronos_types) { $type =~ s/\s(\Q$t\E)\s/ $khronos_types{$t} /; }
943 printf HEADER
$type . "\n";
948 foreach (keys %gl_enums) { $maxlen = length($_) if length($_) > $maxlen; }
949 foreach (sort keys %gl_enums)
951 printf HEADER
"#define %-*s %s\n", $maxlen, $_, $gl_enums{$_};
955 foreach (sort keys %norm_functions)
957 my $decl_args = get_func_args
( $norm_functions{$_}, 1, 0, "" );
958 my $func_ret = get_func_ret
( $norm_functions{$_}, 0 );
959 printf HEADER
"%-10s GLAPIENTRY $_($decl_args);\n", $func_ret;
962 print HEADER
"\n#endif /* __WINE_WGL_H */\n";
966 # Now, generate the output files. First, the spec file.
968 open(SPEC
, ">$spec_file") or die "cannot create $spec_file";
970 foreach (sort keys %norm_functions)
972 printf SPEC
"%s\n", generate_spec_entry
( $_, $norm_functions{$_} );
974 foreach (sort keys %wgl_functions)
976 printf SPEC
"%s\n", generate_spec_entry
( $_, $wgl_functions{$_} );
982 # Generate the unixlib.h file
984 open OUT
, ">unixlib.h" or die "cannot create unixlib.h";
985 print OUT
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
986 print OUT
"#ifndef __WINE_OPENGL32_UNIXLIB_H\n";
987 print OUT
"#define __WINE_OPENGL32_UNIXLIB_H\n\n";
989 print OUT
"#include <stdarg.h>\n";
990 print OUT
"#include <stddef.h>\n\n";
992 print OUT
"#include \"ntstatus.h\"\n";
993 print OUT
"#define WIN32_NO_STATUS\n";
994 print OUT
"#include \"windef.h\"\n";
995 print OUT
"#include \"winbase.h\"\n";
996 print OUT
"#include \"winternl.h\"\n";
997 print OUT
"#include \"wingdi.h\"\n\n";
998 print OUT
"#include \"wine/wgl.h\"\n";
999 print OUT
"#include \"wine/unixlib.h\"\n\n";
1001 foreach (sort keys %wgl_functions)
1003 next if defined $manual_win_functions{$_};
1004 print OUT generate_func_params
($_, $wgl_functions{$_});
1006 foreach (sort keys %norm_functions)
1008 next if defined $manual_win_functions{$_};
1009 print OUT generate_func_params
($_, $norm_functions{$_});
1011 foreach (sort keys %ext_functions)
1013 next if defined $manual_win_functions{$_};
1014 print OUT generate_func_params
($_, $ext_functions{$_});
1017 print OUT
"enum unix_funcs\n";
1019 print OUT
" unix_thread_attach,\n";
1020 print OUT
" unix_process_detach,\n";
1021 foreach (sort keys %wgl_functions)
1023 next if defined $manual_win_functions{$_};
1024 printf OUT
" unix_%s,\n", $_;
1026 foreach (sort keys %norm_functions)
1028 next if defined $manual_win_functions{$_};
1029 printf OUT
" unix_%s,\n", $_;
1031 foreach (sort keys %ext_functions)
1033 next if defined $manual_win_functions{$_};
1034 printf OUT
" unix_%s,\n", $_;
1038 print OUT
"typedef void (WINAPI *gl_debug_cb)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar *, const void *);\n";
1039 print OUT
"struct wine_gl_debug_message_params\n";
1041 print OUT
" gl_debug_cb user_callback;\n";
1042 print OUT
" const void *user_data;\n";
1044 print OUT
" GLenum source;\n";
1045 print OUT
" GLenum type;\n";
1046 print OUT
" GLuint id;\n";
1047 print OUT
" GLenum severity;\n";
1048 print OUT
" GLsizei length;\n";
1049 print OUT
" const GLchar *message;\n";
1052 print OUT
"#define UNIX_CALL( func, params ) WINE_UNIX_CALL( unix_ ## func, params )\n\n";
1054 print OUT
"#endif /* __WINE_OPENGL32_UNIXLIB_H */\n";
1058 # Generate the thunks.c file
1060 open OUT
, ">thunks.c" or die "cannot create thunks.c";
1061 print OUT
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
1063 print OUT
"#include <stdarg.h>\n";
1064 print OUT
"#include <stddef.h>\n\n";
1066 print OUT
"#include \"ntstatus.h\"\n";
1067 print OUT
"#define WIN32_NO_STATUS\n";
1068 print OUT
"#include \"windef.h\"\n";
1069 print OUT
"#include \"winbase.h\"\n";
1070 print OUT
"#include \"wingdi.h\"\n\n";
1072 print OUT
"#include \"unixlib.h\"\n";
1073 print OUT
"#include \"private.h\"\n\n";
1074 print OUT
"#include \"wine/debug.h\"\n\n";
1075 print OUT
"WINE_DEFAULT_DEBUG_CHANNEL(opengl);\n";
1077 foreach (sort keys %wgl_functions)
1079 next if defined $manual_win_functions{$_};
1080 next if defined $manual_win_thunks{$_};
1081 print OUT
"\n" . generate_win_thunk
($_, $wgl_functions{$_});
1083 foreach (sort keys %norm_functions)
1085 next if defined $manual_win_functions{$_};
1086 next if defined $manual_win_thunks{$_};
1087 print OUT
"\n" . generate_win_thunk
($_, $norm_functions{$_});
1089 foreach (sort keys %ext_functions)
1091 next if defined $manual_win_functions{$_};
1092 next if defined $manual_win_thunks{$_};
1093 print OUT
"\nstatic " . generate_win_thunk
($_, $ext_functions{$_});
1097 foreach (sort keys %ext_functions)
1099 next unless defined $manual_win_functions{$_} || $manual_win_thunks{$_};
1100 my $decl_args = get_func_args
( $ext_functions{$_}, 1, 0, "" );
1101 my $func_ret = get_func_ret
( $ext_functions{$_}, 0 );
1102 printf OUT
"extern %s WINAPI %s(%s) DECLSPEC_HIDDEN;\n", $func_ret, $_, $decl_args;
1105 print OUT
"const void *extension_procs[] =\n";
1107 foreach (sort keys %ext_functions)
1109 printf OUT
" %s,\n", $_;
1116 # Generate the unix_thunks.c file
1118 open OUT
, ">unix_thunks.c" or die "cannot create unix_thunks.c";
1119 print OUT
"/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
1121 print OUT
"#if 0\n";
1122 print OUT
"#pragma makedep unix\n";
1123 print OUT
"#endif\n\n";
1125 print OUT
"#include <stdarg.h>\n";
1126 print OUT
"#include <stddef.h>\n\n";
1128 print OUT
"#include \"ntstatus.h\"\n";
1129 print OUT
"#define WIN32_NO_STATUS\n";
1130 print OUT
"#include \"windef.h\"\n";
1131 print OUT
"#include \"winbase.h\"\n";
1132 print OUT
"#include \"wingdi.h\"\n\n";
1134 print OUT
"#include \"unixlib.h\"\n";
1135 print OUT
"#include \"unix_private.h\"\n\n";
1136 print OUT
"#include \"wine/debug.h\"\n\n";
1138 print OUT
"#ifdef _WIN64\n";
1139 print OUT
"WINE_DEFAULT_DEBUG_CHANNEL(opengl);\n";
1140 print OUT
"#endif\n\n";
1142 print OUT
"extern NTSTATUS thread_attach( void *args ) DECLSPEC_HIDDEN;\n";
1143 print OUT
"extern NTSTATUS process_detach( void *args ) DECLSPEC_HIDDEN;\n";
1144 foreach (sort keys %wgl_functions)
1146 next if defined $manual_win_functions{$_};
1147 next unless needs_wrapper
( $_, $wgl_functions{$_} );
1148 print OUT
"extern NTSTATUS wgl_$_( void *args ) DECLSPEC_HIDDEN;\n";
1150 foreach (sort keys %norm_functions)
1152 next if defined $manual_win_functions{$_};
1153 next unless needs_wrapper
( $_, $norm_functions{$_} );
1154 print OUT
"extern NTSTATUS gl_$_( void *args ) DECLSPEC_HIDDEN;\n";
1156 foreach (sort keys %ext_functions)
1158 next if defined $manual_win_functions{$_};
1159 next unless needs_wrapper
( $_, $ext_functions{$_} );
1160 print OUT
"extern NTSTATUS ext_$_( void *args ) DECLSPEC_HIDDEN;\n";
1164 foreach (sort keys %wgl_functions)
1166 next if defined $manual_win_functions{$_};
1167 next if needs_wrapper
( $_, $wgl_functions{$_} );
1168 print OUT
"static " unless defined $manual_wow64_thunks{$_};
1169 print OUT generate_unix_thunk
($_, $wgl_functions{$_}, "wgl");
1171 foreach (sort keys %norm_functions)
1173 next if defined $manual_win_functions{$_};
1174 next if needs_wrapper
( $_, $norm_functions{$_} );
1175 print OUT
"static " unless defined $manual_wow64_thunks{$_};
1176 print OUT generate_unix_thunk
($_, $norm_functions{$_}, "gl");
1178 foreach (sort keys %ext_functions)
1180 next if defined $manual_win_functions{$_};
1181 next if needs_wrapper
( $_, $ext_functions{$_} );
1182 print OUT
"static " unless defined $manual_wow64_thunks{$_};
1183 print OUT generate_unix_thunk
($_, $ext_functions{$_}, "ext");
1186 print OUT
"const unixlib_entry_t __wine_unix_call_funcs[] =\n";
1188 print OUT
" &thread_attach,\n";
1189 print OUT
" &process_detach,\n";
1190 foreach (sort keys %wgl_functions)
1192 next if defined $manual_win_functions{$_};
1193 printf OUT
" &wgl_%s,\n", $_;
1195 foreach (sort keys %norm_functions)
1197 next if defined $manual_win_functions{$_};
1198 printf OUT
" &gl_%s,\n", $_;
1200 foreach (sort keys %ext_functions)
1202 next if defined $manual_win_functions{$_};
1203 printf OUT
" &ext_%s,\n", $_;
1208 print OUT
"#ifdef _WIN64\n\n";
1209 print OUT
"typedef ULONG PTR32;\n\n";
1210 print OUT
"extern NTSTATUS wow64_thread_attach( void *args ) DECLSPEC_HIDDEN;\n";
1211 print OUT
"extern NTSTATUS wow64_process_detach( void *args ) DECLSPEC_HIDDEN;\n\n";
1213 foreach (sort keys %wgl_functions)
1215 next if defined $manual_win_functions{$_};
1216 next if defined $manual_wow64_thunks{$_};
1217 print OUT generate_wow64_thunk
($_, $wgl_functions{$_}, "wgl");
1219 foreach (sort keys %norm_functions)
1221 next if defined $manual_win_functions{$_};
1222 next if defined $manual_wow64_thunks{$_};
1223 print OUT generate_wow64_thunk
($_, $norm_functions{$_}, "gl");
1225 foreach (sort keys %ext_functions)
1227 next if defined $manual_win_functions{$_};
1228 next if defined $manual_wow64_thunks{$_};
1229 print OUT generate_wow64_thunk
($_, $ext_functions{$_}, "ext");
1232 foreach (sort keys %wgl_functions)
1234 next if defined $manual_win_functions{$_};
1235 next unless defined $manual_wow64_thunks{$_};
1236 print OUT
"extern NTSTATUS wow64_wgl_$_( void *args ) DECLSPEC_HIDDEN;\n";
1238 foreach (sort keys %norm_functions)
1240 next if defined $manual_win_functions{$_};
1241 next unless defined $manual_wow64_thunks{$_};
1242 print OUT
"extern NTSTATUS wow64_gl_$_( void *args ) DECLSPEC_HIDDEN;\n";
1244 foreach (sort keys %ext_functions)
1246 next if defined $manual_win_functions{$_};
1247 next unless defined $manual_wow64_thunks{$_};
1248 print OUT
"extern NTSTATUS wow64_ext_$_( void *args ) DECLSPEC_HIDDEN;\n";
1251 print OUT
"\nconst unixlib_entry_t __wine_unix_call_wow64_funcs[] =\n";
1253 print OUT
" wow64_thread_attach,\n";
1254 print OUT
" wow64_process_detach,\n";
1255 foreach (sort keys %wgl_functions)
1257 next if defined $manual_win_functions{$_};
1258 printf OUT
" wow64_wgl_%s,\n", $_;
1260 foreach (sort keys %norm_functions)
1262 next if defined $manual_win_functions{$_};
1263 printf OUT
" wow64_gl_%s,\n", $_;
1265 foreach (sort keys %ext_functions)
1267 next if defined $manual_win_functions{$_};
1268 printf OUT
" wow64_ext_%s,\n", $_;
1272 print OUT
"#endif\n\n";
1274 foreach (sort keys %wgl_functions)
1276 next if defined $manual_win_functions{$_};
1277 print OUT generate_null_func
($_, $wgl_functions{$_});
1279 foreach (sort keys %norm_functions)
1281 next if defined $manual_win_functions{$_};
1282 print OUT generate_null_func
($_, $norm_functions{$_});
1284 foreach (sort keys %ext_functions)
1286 next if defined $manual_win_functions{$_};
1287 print OUT generate_null_func
($_, $ext_functions{$_});
1291 print OUT
"struct opengl_funcs null_opengl_funcs =\n";
1294 foreach (sort keys %wgl_functions)
1296 next if defined $manual_win_functions{$_};
1297 print OUT
" null_$_,\n";
1301 foreach (sort keys %norm_functions)
1303 next if defined $manual_win_functions{$_};
1304 print OUT
" null_$_,\n";
1308 foreach (sort keys %ext_functions)
1310 next if defined $manual_win_functions{$_};
1311 print OUT
" null_$_,\n";
1316 # Then the table giving the string <-> function correspondence */
1317 my $count = keys %ext_functions;
1318 print OUT
"\nconst int extension_registry_size = $count;\n";
1319 print OUT
"const struct registry_entry extension_registry[$count] =\n";
1321 foreach (sort keys %ext_functions)
1323 my $func = $ext_functions{$_};
1324 printf OUT
" { \"%s\", \"%s\" },\n", $_, join(" ", sort @
{$func->[2]});