4 # This script is called thus :
6 # make_opengl [opengl_version]
8 # - It needs files from the OpenGL extension registry:
10 # http://www.opengl.org/registry/api/gl.spec
11 # http://www.opengl.org/registry/api/gl.tm
12 # http://www.opengl.org/registry/api/wgl.tm
13 # http://www.opengl.org/registry/api/wglext.spec
15 # If they are not found in the current directory the script will
16 # attempt to download them from there.
18 # - opengl_version is the OpenGL version emulated by the library
19 # (can be 1.0 to 1.5). The default is 1.1.
21 # This script generates the three following files :
23 # - opengl32.spec : the spec file giving all the exported functions
24 # of the OpenGL32.DLL library. These functions are the one an
25 # application can directly link to (and are all the functions
26 # defined in the OpenGL core for the version defined by
29 # - opengl_norm.c : this file contains the thunks for all OpenGL
30 # functions that are defined in 'opengl32.spec'. The corresponding
31 # functions NEED to be defined in Linux's libGL or the library
32 # won't be able to be linked in.
34 # - opengl_ext.c : in this file are stored thunks for ALL possible
35 # OpenGL extensions (at least, all the extensions that are defined
36 # in the OpenGL extension registry). Contrary to 'opengl_norm.c',
37 # you do not need to have these extensions in your libGL to have
38 # OpenGL work (as they are resolved at run-time using
39 # glXGetProcAddressARB).
41 # - include/wine/wgl_driver.h: definitions for the tables of OpenGL functions.
44 # Copyright 2000 Lionel Ulmer
45 # Copyright 2012 Alexandre Julliard
47 # This library is free software; you can redistribute it and/or
48 # modify it under the terms of the GNU Lesser General Public
49 # License as published by the Free Software Foundation; either
50 # version 2.1 of the License, or (at your option) any later version.
52 # This library is distributed in the hope that it will be useful,
53 # but WITHOUT ANY WARRANTY; without even the implied warranty of
54 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55 # Lesser General Public License for more details.
57 # You should have received a copy of the GNU Lesser General Public
58 # License along with this library; if not, write to the Free Software
59 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
65 my $spec_file = "opengl32.spec";
66 my $norm_file = "opengl_norm.c";
67 my $ext_file = "opengl_ext.c";
69 # Set to 0 for removing the ENTER / LEAVE GL calls
70 my $gen_thread_safe = 0;
71 # Prefix used for the local variables
72 my $ext_prefix = "func_";
73 # If set to 1, generate TRACEs for each OpenGL function
77 # List of categories to put in the 'opengl_norm.c' file
79 my %cat_1_0 = ( "display-list" => 1,
81 "drawing-control" => 1,
91 "VERSION_1_0_DEPRECATED" => 1 );
92 my %cat_1_1 = ( %cat_1_0,
94 "VERSION_1_1_DEPRECATED" => 1 );
95 my %cat_1_2 = ( %cat_1_1,
97 "VERSION_1_2_DEPRECATED" => 1 );
98 my %cat_1_3 = ( %cat_1_2,
100 "VERSION_1_3_DEPRECATED" => 1 );
101 my %cat_1_4 = ( %cat_1_3,
103 "VERSION_1_4_DEPRECATED" => 1 );
104 my %cat_1_5 = ( %cat_1_4,
106 "VERSION_1_5_DEPRECATED" => 1 );
108 my %norm_categories = ();
111 # This hash table gives the conversion between OpenGL types and what
112 # is used by the TRACE printfs
115 ("GLbitfield" => "%d",
131 "GLintptrARB" => "%ld",
132 "GLsizeiptrARB" => "%ld",
134 "GLsizeiptr" => "%ld",
135 "GLhandleARB" => "%d",
137 "GLvoid" => "(void)",
138 "_GLfuncptr" => "%p",
139 "GLDEBUGPROC" => "%p",
140 "GLDEBUGPROCARB" => "%p",
141 "GLDEBUGPROCAMD" => "%p",
142 "GLvdpauSurfaceNV" => "%ld",
144 "unsigned int" => "%u",
148 "INT64" => "%s,wine_dbgstr_longlong(%s)",
149 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
154 "HPBUFFERARB" => "%p",
155 "HPBUFFEREXT" => "%p",
159 # This hash table gives the conversion between OpenGL types and what
160 # is used in the .spec and header files.
163 ("GLbitfield" => [ "long", "unsigned int" ],
164 "GLboolean" => [ "long", "unsigned char" ],
165 "GLbyte" => [ "long", "signed char" ],
166 "GLchar" => [ "long", "char" ],
167 "GLclampd" => [ "double", "double" ],
168 "GLclampf" => [ "float", "float" ],
169 "GLdouble" => [ "double", "double" ],
170 "GLenum" => [ "long", "unsigned int" ],
171 "GLfloat" => [ "float", "float" ],
172 "GLint" => [ "long", "int" ],
173 "GLint64" => [ "int64", "INT64" ],
174 "GLintptr" => [ "long", "INT_PTR" ],
175 "GLshort" => [ "long", "short" ],
176 "GLsizei" => [ "long", "int" ],
177 "GLsizeiptr" => [ "long", "INT_PTR" ],
178 "GLstring" => [ "str", "const unsigned char *" ],
179 "GLsync" => [ "ptr", "struct __GLsync *" ],
180 "GLubyte" => [ "long", "unsigned char" ],
181 "GLuint" => [ "long", "unsigned int" ],
182 "GLuint64" => [ "int64", "UINT64" ],
183 "GLushort" => [ "long", "unsigned short" ],
184 "GLvoid" => [ "void", "void" ],
185 "GLcharARB" => [ "long", "char" ],
186 "GLhandleARB" => [ "long", "unsigned int" ],
187 "GLintptrARB" => [ "long", "INT_PTR" ],
188 "GLsizeiptrARB" => [ "long", "INT_PTR" ],
189 "GLhalfNV" => [ "long", "unsigned short" ],
190 "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
193 # Used to convert some types
200 "struct _cl_context" => "void",
201 "struct _cl_event" => "void",
202 "HGLRC" => "struct wgl_context *",
203 "GLDEBUGPROC" => "void *",
204 "GLDEBUGPROCARB" => "void *",
205 "GLDEBUGPROCAMD" => "void *",
206 "HPBUFFERARB" => "struct wgl_pbuffer *",
207 "HPBUFFEREXT" => "struct wgl_pbuffer *",
210 foreach my $org (reverse sort keys %hash) {
211 if ($type =~ /$org/) {
212 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
213 return "$before$hash{$org}$after";
220 # Used to convert some variable names
222 sub ConvertVarName
($)
226 my %hash = ( "near" => "nearParam",
227 "far" => "farParam" );
229 foreach my $org (keys %hash) {
230 if ($type =~ /$org/) {
231 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
232 return "$before$hash{$org}$after";
239 # This functions generates the thunk for a given function.
241 sub GenerateThunk
($$$$)
243 my ($name, $func_ref, $comment, $prefix) = @_;
246 my $trace_call_arg = "";
249 return "" if $name eq "glDebugEntry";
250 return "" if $name eq "glGetString";
251 return "" if $func_ref->[2] && $func_ref->[2] =~ /WGL_/;
253 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
254 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
256 $ret = "$ret/***********************************************************************\n";
257 $ret = "$ret * $name (OPENGL32.\@)\n";
260 $ret = $ret . ConvertType
($func_ref->[0]) . " WINAPI $name( ";
261 for (my $i = 0; $i < @
{$func_ref->[1]}; $i++) {
262 ## Quick debug code :-)
263 ## print $func_ref->[1]->[$i]->[1] . "\n";
264 my $type = $func_ref->[1]->[$i]->[0];
265 my $name = ConvertVarName
($func_ref->[1]->[$i]->[1]);
266 $ret .= ConvertType
($type) . " $name";
270 $trace_call_arg .= $name;
271 } elsif (defined $debug_conv{$type}) {
272 if ($debug_conv{$type} =~ /(.*),(.*)/)
275 $trace_call_arg .= sprintf $2, $name;
279 $trace_arg .= $debug_conv{$type};
280 $trace_call_arg .= $name;
283 else { printf "Unknown type %s\n", $type; }
284 if ($i+1 < @
{$func_ref->[1]}) {
287 $trace_call_arg .= ", ";
292 $trace_call_arg .= " ";
295 $ret .= 'void ' if (!@
{$func_ref->[1]});
297 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
298 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
299 $ret = "$ret " . ConvertType
($func_ref->[0]) . " ret_value;\n";
302 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
303 if ($trace_arg ne "") {
304 $ret .= ", $trace_call_arg";
308 if ($gen_thread_safe) {
309 $ret .= " ENTER_GL();\n";
311 if ($func_ref->[0] ne "void") {
312 $ret .= "ret_value = ";
314 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
315 $ret .= " LEAVE_GL();\n";
316 if ($func_ref->[0] ne "void") {
317 $ret .= " return ret_value;\n"
322 if ($func_ref->[0] ne "void") {
325 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
329 # Return this string....
333 sub generate_null_func
($$)
335 my ($name, $func_ref) = @_;
338 return "" if $name eq "glDebugEntry";
340 $ret = "static " . ConvertType
($func_ref->[0]) . " null_$name( ";
341 for (my $i = 0; $i < @
{$func_ref->[1]}; $i++) {
342 my $type = $func_ref->[1]->[$i]->[0];
343 my $name = ConvertVarName
($func_ref->[1]->[$i]->[1]);
344 $ret .= ConvertType
($type) . " $name";
345 $ret .= "," if ($i+1 < @
{$func_ref->[1]});
348 $ret .= 'void ' if (!@
{$func_ref->[1]});
350 if ($name eq "glGetError")
352 $ret .= " return GL_INVALID_OPERATION;";
354 elsif ($func_ref->[0] ne "void")
356 $ret .= " return 0;";
362 sub get_func_proto
($$$)
364 my ($format, $name, $func) = @_;
365 my $ret = sprintf "%-10s", ConvertType
($func->[0]);
366 $ret .= " " . sprintf($format,$name) . "(";
367 for (my $i = 0; $i < @
{$func->[1]}; $i++)
369 $ret .= ConvertType
($func->[1]->[$i]->[0]);
370 $ret .= "," if ($i+1 < @
{$func->[1]});
372 $ret .= "void" unless @
{$func->[1]};
378 # Extract and checks the number of arguments
383 die "Usage: $name0 [version]\n";
385 my $version = $ARGV[0] || "1.1";
386 if ($version eq "1.0") {
387 %norm_categories = %cat_1_0;
388 } elsif ($version eq "1.1") {
389 %norm_categories = %cat_1_1;
390 } elsif ($version eq "1.2") {
391 %norm_categories = %cat_1_2;
392 } elsif ($version eq "1.3") {
393 %norm_categories = %cat_1_3;
394 } elsif ($version eq "1.4") {
395 %norm_categories = %cat_1_4;
396 } elsif ($version eq "1.5") {
397 %norm_categories = %cat_1_5;
399 die "Incorrect OpenGL version.\n";
403 # Fetch the registry files
405 -f
"gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
406 -f
"gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
407 -f
"wgl.tm" || system "wget http://www.opengl.org/registry/api/wgl.tm" || die "cannot download wgl.tm";
408 -f
"wglext.spec" || system "wget http://www.opengl.org/registry/api/wglext.spec" || die "cannot download wglext.spec";
409 -f
"enum.spec" || system "wget http://www.opengl.org/registry/api/enum.spec" || die "cannot download enum.spec";
410 -f
"enumext.spec" || system "wget http://www.opengl.org/registry/api/enumext.spec" || die "cannot download enumext.spec";
413 # First, create a mapping between the pseudo types used in the spec file
414 # and OpenGL types using the 'gl.tm' file.
416 my %pseudo_to_opengl = ();
421 open TYPES
, "<$file" or die "Could not open $file";
422 while (my $line = <TYPES
>) {
423 if ($line !~ /\w*\#/) {
424 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
425 $pseudo_to_opengl{$pseudo} = $opengl;
431 load_types
( "wgl.tm" );
432 load_types
( "gl.tm" );
434 # This is to override the 'void' -> '*' bogus conversion
435 $pseudo_to_opengl{"void"} = "void";
436 $pseudo_to_opengl{"sync"} = "GLvoid*";
437 $pseudo_to_opengl{"Int64"} = "INT64";
438 $pseudo_to_opengl{"UInt64"} = "UINT64";
439 $pseudo_to_opengl{"Int64EXT"} = "INT64";
440 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
443 # Then, create the list of all OpenGL functions using the 'gl.spec'
444 # file. This will create two hash-tables, one with all the function
445 # whose category matches the one listed in '@norm_categories', the other
446 # with all other functions.
448 # An element of the hash table is a reference to an array with these
455 # - reference to an array giving the list of arguments (an empty array
456 # for a 'void' function).
458 # The list of arguments is itself an array of reference to arrays. Each
459 # of these arrays represents the argument type and the argument name.
463 # void glBitmap( GLsizei width, GLsizei height,
464 # GLfloat xorig, GLfloat yorig,
465 # GLfloat xmove, GLfloat ymove,
466 # const GLubyte *bitmap );
468 # Would give something like that :
472 # [ [ "GLsizei", "width" ],
473 # [ "GLsizei", "height" ],
474 # [ "GLfloat", "xorig" ],
475 # [ "GLfloat", "yorig" ],
476 # [ "GLfloat", "xmove" ],
477 # [ "GLfloat", "ymove" ],
478 # [ "GLubyte *", "bitmap"] ] ];
480 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
481 [ "GLint", "unknown2" ]] ] );
484 # This stores various extensions NOT part of the GL extension registry but still
485 # implemented by most OpenGL libraries out there...
490 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
491 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
494 [ "GLsizei", "width" ],
495 [ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
496 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
499 [ "GLsizei", "width" ],
500 [ "GLsizei", "height" ],
501 [ "GLint", "xDest" ],
502 [ "GLint", "yDest" ] ], "GL_KTX_buffer_region" ],
503 "glBufferRegionEnabled" => [ "GLuint", [ ], "GL_KTX_buffer_region" ],
504 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], "GL_KTX_buffer_region" ],
505 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
507 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
508 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
509 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
510 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
511 [ "GLdouble", "s" ] ], "GL_SGIS_multitexture" ],
512 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
513 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
514 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
515 [ "GLfloat", "s" ] ], "GL_SGIS_multitexture" ],
516 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
517 [ "const GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
518 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
519 [ "GLint", "s" ] ], "GL_SGIS_multitexture" ],
520 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
521 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
522 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
523 [ "GLshort", "s" ] ], "GL_SGIS_multitexture" ],
524 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
525 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
526 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
528 [ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
529 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
530 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
531 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
533 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
534 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
535 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
536 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
538 [ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
539 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
540 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
541 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
543 [ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
544 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
545 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
546 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
549 [ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
550 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
551 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
552 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
555 [ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
556 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
557 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
558 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
561 [ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
562 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
563 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
564 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
567 [ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
568 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
569 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
570 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
574 [ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
575 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
576 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
577 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
581 [ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
582 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
583 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
584 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
588 [ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
589 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
590 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
591 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
595 [ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
596 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
597 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
598 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
600 [ "GLenum", "type" ],
601 [ "GLsizei", "stride" ],
602 [ "GLvoid *", "pointer" ] ], "GL_SGIS_multitexture" ],
603 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
604 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
605 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], "GL_ATI_vertex_array_object" ],
606 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
607 [ "int", "format" ] ], "WGL_WINE_pixel_format_passthrough" ],
613 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
614 [ "struct wgl_context *", "dst" ],
615 [ "UINT", "mask" ] ] ],
616 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
617 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
618 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
621 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
622 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
623 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
624 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
625 [ "struct wgl_context *", "context" ] ] ],
626 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
628 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
629 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
630 [ "struct wgl_context *", "dst" ] ] ],
631 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
634 my %supported_wgl_extensions =
636 "WGL_ARB_create_context" => 1,
637 "WGL_ARB_extensions_string" => 1,
638 "WGL_ARB_make_current_read" => 1,
639 "WGL_ARB_pbuffer" => 1,
640 "WGL_ARB_pixel_format" => 1,
641 "WGL_ARB_render_texture" => 1,
642 "WGL_EXT_extensions_string" => 1,
643 "WGL_EXT_swap_control" => 1,
644 "WGL_NV_vertex_array_range" => 1,
645 "WGL_WINE_pixel_format_passthrough" => 1,
648 sub parse_registry_file
($)
653 open REGISTRY
, "<$file" or die "cannot open $file";
654 while (my $line = <REGISTRY
>) {
655 next unless ($line =~ /^\w*\(.*\)/);
657 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
658 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
659 # and the argument names
660 @arg_names = split /\s*,\s*/, $args;
664 # - category (the extension the function is part of)
665 # - the argument types
666 # - the category the function belongs
672 unless (defined($line)) {
674 } elsif ($line =~ /^\s*$/) {
675 if (($category eq "") || ($ret_type eq "")) {
676 die "Missing 'category' line in function $funcname.\n";
679 } elsif ($line =~ /\t*return\t+(\w*)/) {
680 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
681 $ret_type = $pseudo_to_opengl{$ret_type};
682 unless (defined($ret_type)) {
683 die "Unsupported return type in function $funcname\n";
685 } elsif ($line =~ /^\t*category/) {
686 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
687 } elsif ($line =~ /^\t*param/) {
688 my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
690 unless (defined($name)) {
692 die "Broken spec file line $line in function $funcname\n";
695 if ($ext =~ /array/) {
698 } elsif ($ext =~ /reference/) {
701 } elsif ($ext =~ /value/) {
702 # And this a 'normal' value
706 die "Unsupported type : $line in function $funcname\n";
708 # Get the 'real' type and append a '*' in case of a pointer
709 my $type = $pseudo_to_opengl{$base_type};
710 unless (defined($type)) {
712 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
716 $type = "const $type" if $dir eq "in";
719 $arg_types{$name} = $type;
723 # Now, build the argument reference
725 for (my $i = 0; $i < @arg_names; $i++) {
726 unless (defined($arg_types{$arg_names[$i]})) {
727 print "@arg_names\n";
728 foreach (sort keys %arg_types) {
729 print "$_ => $arg_types{$_}\n";
731 die "Undefined type for $arg_names[$i] in function $funcname\n";
734 push @
$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
737 # Now, put in one or the other hash table
738 if ($norm_categories{$category}) {
739 $norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
740 } elsif ($file =~ /^wgl/) {
741 if (defined $supported_wgl_extensions{"WGL_$category"}) {
742 $ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
745 $ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
751 sub parse_enum_file
($$)
753 my ($file, $enums) = @_;
754 open FILE
, "<$file" or die "cannot open $file";
759 if (/^\t([0-9A-Z_]+)\s*=\s*(((0x[0-9A-Fa-f]+)|([0-9]+))([uUlL]+)?)/)
761 ${$enums}{"GL_$1"} = $2;
768 parse_registry_file
( "gl.spec" );
769 parse_registry_file
( "wglext.spec" );
772 parse_enum_file
( "enum.spec", \
%enums );
773 parse_enum_file
( "enumext.spec", \
%enums );
776 # Get the current wgl_driver.h version
779 open HEADER
, "<../../include/wine/wgl_driver.h" or die "cannot open wgl_driver.h";
782 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
789 # Generate the wgl_driver.h file
791 open HEADER
, ">../../include/wine/wgl_driver.h" or die "cannot create wgl_driver.h";
792 print HEADER
"/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
793 print HEADER
"#ifndef __WINE_WGL_DRIVER_H\n";
794 print HEADER
"#define __WINE_WGL_DRIVER_H\n\n";
795 print HEADER
"#ifndef WINE_GLAPI\n";
796 print HEADER
"#define WINE_GLAPI\n";
797 print HEADER
"#endif\n\n";
799 printf HEADER
"#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
801 print HEADER
"struct wgl_context;\n";
802 print HEADER
"struct wgl_pbuffer;\n\n";
804 print HEADER
"struct opengl_funcs\n{\n";
805 print HEADER
" struct\n {\n";
806 foreach (sort keys %wgl_functions)
808 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
810 print HEADER
" } wgl;\n\n";
812 print HEADER
" struct\n {\n";
813 foreach (sort keys %norm_functions)
815 next if $_ eq "glDebugEntry";
816 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
818 print HEADER
" } gl;\n\n";
820 print HEADER
" struct\n {\n";
821 foreach (sort keys %ext_functions)
823 printf HEADER
" %s;\n", get_func_proto
("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
825 print HEADER
" } ext;\n";
826 print HEADER
"};\n\n";
828 print HEADER
"#define ALL_WGL_FUNCS";
829 foreach (sort keys %norm_functions)
831 next if $_ eq "glDebugEntry";
832 printf HEADER
" \\\n USE_GL_FUNC(\%s)", $_;
836 print HEADER
"extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
837 print HEADER
"extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
838 print HEADER
"#endif /* __WINE_WGL_DRIVER_H */\n";
842 # Generate the wgl.h file
844 open HEADER
, ">../../include/wine/wgl.h" or die "cannot create wgl.h";
845 print HEADER
"/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
846 print HEADER
"#ifndef __WINE_WGL_H\n";
847 print HEADER
"#define __WINE_WGL_H\n\n";
849 print HEADER
"#ifndef GLAPIENTRY\n";
850 print HEADER
"#define GLAPIENTRY __stdcall\n";
851 print HEADER
"#endif\n\n";
853 foreach (sort keys %arg_conv)
855 printf HEADER
"typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
860 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
861 foreach (sort keys %enums)
863 printf HEADER
"#define %-*s %s\n", $maxlen, $_, $enums{$_};
867 foreach (sort keys %norm_functions)
869 printf HEADER
"%s;\n", get_func_proto
("GLAPIENTRY %s", $_, $norm_functions{$_});
872 print HEADER
"\n#endif /* __WINE_WGL_H */\n";
876 # Now, generate the output files. First, the spec file.
878 open(SPEC
, ">$spec_file");
880 foreach (sort keys %norm_functions) {
882 for (my $i = 0; $i < @
{$norm_functions{$_}->[1]}; $i++) {
883 my $type = $norm_functions{$_}->[1]->[$i]->[0];
886 } elsif (defined($arg_conv{$type})) {
887 $args .= "$@$arg_conv{$type}[0] ";
889 die "No conversion for GL type $type...\n";
892 $args = substr($args,1,-1);
893 print SPEC
"@ stdcall $_($args)\n";
896 print SPEC
"@ stdcall wglChoosePixelFormat(long ptr)
897 @ stdcall wglCopyContext(long long long)
898 @ stdcall wglCreateContext(long)
899 @ stdcall wglCreateLayerContext(long long)
900 @ stdcall wglDeleteContext(long)
901 @ stdcall wglDescribeLayerPlane(long long long long ptr)
902 @ stdcall wglDescribePixelFormat(long long long ptr)
903 @ stdcall wglGetCurrentContext()
904 @ stdcall wglGetCurrentDC()
905 @ stub wglGetDefaultProcAddress
906 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
907 @ stdcall wglGetPixelFormat(long)
908 @ stdcall wglGetProcAddress(str)
909 @ stdcall wglMakeCurrent(long long)
910 @ stdcall wglRealizeLayerPalette(long long long)
911 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
912 @ stdcall wglSetPixelFormat(long long ptr)
913 @ stdcall wglShareLists(long long)
914 @ stdcall wglSwapBuffers(long)
915 @ stdcall wglSwapLayerBuffers(long long)
916 @ stdcall wglUseFontBitmapsA(long long long long)
917 @ stdcall wglUseFontBitmapsW(long long long long)
918 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
919 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
925 # After the spec file, the opengl_norm.c file
927 open(NORM
, ">$norm_file");
929 /* Auto-generated file... Do not edit ! */
931 #include \"config.h\"
933 #include \"winternl.h\"
934 #include \"wingdi.h\"
935 #include \"wine/wgl.h\"
936 #include \"wine/wgl_driver.h\"
937 #include \"wine/debug.h\"
939 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
942 foreach (sort keys %norm_functions) {
943 my $string = GenerateThunk
($_, $norm_functions{$_}, 1, "gl");
944 print NORM
"\n$string" if $string;
947 foreach (sort keys %wgl_functions) {
948 print NORM generate_null_func
($_, $wgl_functions{$_});
950 foreach (sort keys %norm_functions) {
951 print NORM generate_null_func
($_, $norm_functions{$_});
953 foreach (sort keys %ext_functions) {
954 print NORM generate_null_func
($_, $ext_functions{$_});
957 print NORM
"\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
958 foreach (sort keys %wgl_functions) { print NORM
" null_$_,\n"; }
959 print NORM
" },\n {\n";
960 foreach (sort keys %norm_functions) { print NORM
" null_$_,\n" unless $_ eq "glDebugEntry"; }
961 print NORM
" },\n {\n";
962 foreach (sort keys %ext_functions) { print NORM
" null_$_,\n"; }
963 print NORM
" }\n};\n";
968 # Finally, more complex, the opengl_ext.c file
970 open(EXT
, ">$ext_file");
972 /* Auto-generated file... Do not edit ! */
974 #include \"config.h\"
976 #include \"opengl_ext.h\"
977 #include \"winternl.h\"
978 #include \"wingdi.h\"
979 #include \"wine/wgl.h\"
980 #define WGL_WGLEXT_PROTOTYPES
981 #include \"wine/wglext.h\"
982 #include \"wine/wgl_driver.h\"
983 #include \"wine/debug.h\"
985 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
989 # The thunks themselves....
990 my $count = keys %ext_functions;
991 print EXT
"const int extension_registry_size = $count;\n";
992 foreach (sort keys %ext_functions) {
993 my $string = GenerateThunk
($_, $ext_functions{$_}, 0, "ext");
994 print EXT
"\nstatic $string" if $string;
997 # Then the table giving the string <-> function correspondence */
998 print EXT
"\nconst OpenGL_extension extension_registry[$count] = {\n";
1000 foreach (sort keys %ext_functions) {
1001 my $func_ref = $ext_functions{$_};
1002 print EXT
" { \"$_\", \"$func_ref->[2]\", $_ }";
1003 if ($i != $count-1) {