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 "GLDEBUGPROCARB" => "%p",
140 "GLDEBUGPROCAMD" => "%p",
141 "GLvdpauSurfaceNV" => "%ld",
143 "unsigned int" => "%u",
147 "INT64" => "%s,wine_dbgstr_longlong(%s)",
148 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
153 "HPBUFFERARB" => "%p",
154 "HPBUFFEREXT" => "%p",
158 # This hash table gives the conversion between OpenGL types and what
159 # is used in the .spec file
162 ("GLbitfield" => [ "long", 4 ],
163 "GLboolean" => [ "long", 4 ],
164 "GLbyte" => [ "long", 4 ],
165 "GLclampd" => [ "double", 8 ],
166 "GLclampf" => [ "float", 4 ],
167 "GLdouble" => [ "double", 8 ],
168 "GLenum" => [ "long", 4 ],
169 "GLfloat" => [ "float", 4 ],
170 "GLint" => [ "long", 4 ],
171 "GLshort" => [ "long", 4 ],
172 "GLsizei" => [ "long", 4 ],
173 "GLstring" => [ "str", 4 ],
174 "GLubyte" => [ "long", 4 ],
175 "GLuint" => [ "long", 4 ],
176 "GLushort" => [ "long", 4 ],
177 "GLhalfNV" => [ "long", 4 ],
178 "GLintptrARB" => [ "long", 4 ],
179 "GLsizeiptrARB" => [ "long", 4 ],
180 "GLhandleARB" => [ "long", 4 ],
181 "GLcharARB" => [ "long", 4 ],
182 "GLintptr" => [ "long", 4 ],
183 "GLsizeiptr" => [ "long", 4 ],
184 "_GLfuncptr" => [ "ptr", 4 ]);
187 # Used to convert some types
193 my %hash = ( "GLstring" => "const GLubyte *",
194 "GLintptrARB" => "INT_PTR",
195 "GLsizeiptrARB" => "INT_PTR",
196 "GLintptr" => "INT_PTR",
197 "GLsizeiptr" => "INT_PTR",
198 "GLhandleARB" => "unsigned int",
199 "GLcharARB" => "char",
201 "GLhalfNV" => "unsigned short",
202 "GLvdpauSurfaceNV" => "INT_PTR",
203 "struct _cl_context" => "void",
204 "struct _cl_event" => "void",
205 "HGLRC" => "struct wgl_context *",
206 "GLDEBUGPROCARB" => "void *",
207 "GLDEBUGPROCAMD" => "void *",
208 "HPBUFFERARB" => "struct wgl_pbuffer *",
209 "HPBUFFEREXT" => "struct wgl_pbuffer *",
212 foreach my $org (reverse sort keys %hash) {
213 if ($type =~ /$org/) {
214 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
215 return "$before$hash{$org}$after";
222 # Used to convert some variable names
224 sub ConvertVarName($)
228 my %hash = ( "near" => "nearParam",
229 "far" => "farParam" );
231 foreach my $org (keys %hash) {
232 if ($type =~ /$org/) {
233 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
234 return "$before$hash{$org}$after";
241 # This functions generates the thunk for a given function.
243 sub GenerateThunk($$$$)
245 my ($name, $func_ref, $comment, $prefix) = @_;
248 my $trace_call_arg = "";
251 return "" if $name eq "glDebugEntry";
252 return "" if $name eq "glGetString";
253 return "" if $func_ref->[2] && $func_ref->[2] =~ /WGL_/;
255 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
256 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
258 $ret = "$ret/***********************************************************************\n";
259 $ret = "$ret * $name (OPENGL32.\@)\n";
262 $ret = $ret . ConvertType($func_ref->[0]) . " WINAPI wine_$name( ";
263 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
264 ## Quick debug code :-)
265 ## print $func_ref->[1]->[$i]->[1] . "\n";
266 my $type = $func_ref->[1]->[$i]->[0];
267 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
268 $ret .= ConvertType($type) . " $name";
272 $trace_call_arg .= $name;
273 } elsif (defined $debug_conv{$type}) {
274 if ($debug_conv{$type} =~ /(.*),(.*)/)
277 $trace_call_arg .= sprintf $2, $name;
281 $trace_arg .= $debug_conv{$type};
282 $trace_call_arg .= $name;
285 else { printf "Unknown type %s\n", $type; }
286 if ($i+1 < @{$func_ref->[1]}) {
289 $trace_call_arg .= ", ";
294 $trace_call_arg .= " ";
297 $ret .= 'void ' if (!@{$func_ref->[1]});
299 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
300 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
301 $ret = "$ret " . ConvertType($func_ref->[0]) . " ret_value;\n";
304 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
305 if ($trace_arg ne "") {
306 $ret .= ", $trace_call_arg";
310 if ($gen_thread_safe) {
311 $ret .= " ENTER_GL();\n";
313 if ($func_ref->[0] ne "void") {
314 $ret .= "ret_value = ";
316 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
317 $ret .= " LEAVE_GL();\n";
318 if ($func_ref->[0] ne "void") {
319 $ret .= " return ret_value;\n"
324 if ($func_ref->[0] ne "void") {
327 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
331 # Return this string....
335 sub generate_null_func($$)
337 my ($name, $func_ref) = @_;
340 return "" if $name eq "glDebugEntry";
342 $ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
343 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
344 my $type = $func_ref->[1]->[$i]->[0];
345 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
346 $ret .= ConvertType($type) . " $name";
347 $ret .= "," if ($i+1 < @{$func_ref->[1]});
350 $ret .= 'void ' if (!@{$func_ref->[1]});
352 if ($name eq "glGetError")
354 $ret .= " return GL_INVALID_OPERATION;";
356 elsif ($func_ref->[0] ne "void")
358 $ret .= " return 0;";
364 sub get_func_proto($$)
366 my ($name, $func) = @_;
367 my $ret = sprintf "%-10s", ConvertType($func->[0]);
368 $ret .= " (WINE_GLAPI *p_$name)(";
369 for (my $i = 0; $i < @{$func->[1]}; $i++)
371 $ret .= ConvertType($func->[1]->[$i]->[0]);
372 $ret .= "," if ($i+1 < @{$func->[1]});
374 $ret .= "void" unless @{$func->[1]};
379 sub get_func_link_name($$)
381 my ($name, $func) = @_;
382 return $name if ($func->[2] =~ /^WGL_/);
387 # Extract and checks the number of arguments
392 die "Usage: $name0 [version]\n";
394 my $version = $ARGV[0] || "1.1";
395 if ($version eq "1.0") {
396 %norm_categories = %cat_1_0;
397 } elsif ($version eq "1.1") {
398 %norm_categories = %cat_1_1;
399 } elsif ($version eq "1.2") {
400 %norm_categories = %cat_1_2;
401 } elsif ($version eq "1.3") {
402 %norm_categories = %cat_1_3;
403 } elsif ($version eq "1.4") {
404 %norm_categories = %cat_1_4;
405 } elsif ($version eq "1.5") {
406 %norm_categories = %cat_1_5;
408 die "Incorrect OpenGL version.\n";
412 # Fetch the registry files
414 -f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
415 -f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
416 -f "wgl.tm" || system "wget http://www.opengl.org/registry/api/wgl.tm" || die "cannot download wgl.tm";
417 -f "wglext.spec" || system "wget http://www.opengl.org/registry/api/wglext.spec" || die "cannot download wglext.spec";
420 # First, create a mapping between the pseudo types used in the spec file
421 # and OpenGL types using the 'gl.tm' file.
423 my %pseudo_to_opengl = ();
428 open TYPES, "<$file" or die "Could not open $file";
429 while (my $line = <TYPES>) {
430 if ($line !~ /\w*\#/) {
431 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
432 $pseudo_to_opengl{$pseudo} = $opengl;
438 load_types( "wgl.tm" );
439 load_types( "gl.tm" );
441 # This is to override the 'void' -> '*' bogus conversion
442 $pseudo_to_opengl{"void"} = "void";
443 $pseudo_to_opengl{"sync"} = "GLvoid*";
444 $pseudo_to_opengl{"Int64"} = "INT64";
445 $pseudo_to_opengl{"UInt64"} = "UINT64";
446 $pseudo_to_opengl{"Int64EXT"} = "INT64";
447 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
450 # Then, create the list of all OpenGL functions using the 'gl.spec'
451 # file. This will create two hash-tables, one with all the function
452 # whose category matches the one listed in '@norm_categories', the other
453 # with all other functions.
455 # An element of the hash table is a reference to an array with these
462 # - reference to an array giving the list of arguments (an empty array
463 # for a 'void' function).
465 # The list of arguments is itself an array of reference to arrays. Each
466 # of these arrays represents the argument type and the argument name.
470 # void glBitmap( GLsizei width, GLsizei height,
471 # GLfloat xorig, GLfloat yorig,
472 # GLfloat xmove, GLfloat ymove,
473 # const GLubyte *bitmap );
475 # Would give something like that :
479 # [ [ "GLsizei", "width" ],
480 # [ "GLsizei", "height" ],
481 # [ "GLfloat", "xorig" ],
482 # [ "GLfloat", "yorig" ],
483 # [ "GLfloat", "xmove" ],
484 # [ "GLfloat", "ymove" ],
485 # [ "GLubyte *", "bitmap"] ] ];
487 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
488 [ "GLint", "unknown2" ]] ] );
491 # This stores various extensions NOT part of the GL extension registry but still
492 # implemented by most OpenGL libraries out there...
497 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
498 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
501 [ "GLsizei", "width" ],
502 [ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
503 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
506 [ "GLsizei", "width" ],
507 [ "GLsizei", "height" ],
508 [ "GLint", "xDest" ],
509 [ "GLint", "yDest" ] ], "GL_KTX_buffer_region" ],
510 "glBufferRegionEnabled" => [ "GLuint", [ ], "GL_KTX_buffer_region" ],
511 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], "GL_KTX_buffer_region" ],
512 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
514 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
515 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
516 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
517 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
518 [ "GLdouble", "s" ] ], "GL_SGIS_multitexture" ],
519 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
520 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
521 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
522 [ "GLfloat", "s" ] ], "GL_SGIS_multitexture" ],
523 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
524 [ "const GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
525 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
526 [ "GLint", "s" ] ], "GL_SGIS_multitexture" ],
527 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
528 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
529 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
530 [ "GLshort", "s" ] ], "GL_SGIS_multitexture" ],
531 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
533 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
535 [ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
536 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
538 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
540 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
541 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
542 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
543 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
545 [ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
546 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
548 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
550 [ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
551 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
552 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
553 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
556 [ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
557 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
558 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
559 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
562 [ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
563 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
564 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
565 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
568 [ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
569 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
570 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
571 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
574 [ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
575 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
576 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
577 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
581 [ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
582 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
583 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
584 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
588 [ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
589 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
590 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
591 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
595 [ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
596 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
597 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
598 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
602 [ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
603 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
604 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
605 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
607 [ "GLenum", "type" ],
608 [ "GLsizei", "stride" ],
609 [ "GLvoid *", "pointer" ] ], "GL_SGIS_multitexture" ],
610 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
611 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
612 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], "GL_ATI_vertex_array_object" ],
613 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
614 [ "int", "format" ] ], "WGL_WINE_pixel_format_passthrough" ],
620 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
621 [ "struct wgl_context *", "dst" ],
622 [ "UINT", "mask" ] ] ],
623 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
624 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
625 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
628 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
629 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
630 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
631 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
632 [ "struct wgl_context *", "context" ] ] ],
633 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
635 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
636 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
637 [ "struct wgl_context *", "dst" ] ] ],
640 my %supported_wgl_extensions =
642 "WGL_ARB_create_context" => 1,
643 "WGL_ARB_extensions_string" => 1,
644 "WGL_ARB_make_current_read" => 1,
645 "WGL_ARB_pbuffer" => 1,
646 "WGL_ARB_pixel_format" => 1,
647 "WGL_ARB_render_texture" => 1,
648 "WGL_EXT_extensions_string" => 1,
649 "WGL_EXT_swap_control" => 1,
650 "WGL_NV_vertex_array_range" => 1,
651 "WGL_WINE_pixel_format_passthrough" => 1,
654 sub parse_registry_file($)
659 open REGISTRY, "<$file" or die "cannot open $file";
660 while (my $line = <REGISTRY>) {
661 next unless ($line =~ /^\w*\(.*\)/);
663 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
664 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
665 # and the argument names
666 @arg_names = split /\s*,\s*/, $args;
670 # - category (the extension the function is part of)
671 # - the argument types
672 # - the category the function belongs
678 unless (defined($line)) {
680 } elsif ($line =~ /^\s*$/) {
681 if (($category eq "") || ($ret_type eq "")) {
682 die "Missing 'category' line in function $funcname.\n";
685 } elsif ($line =~ /\t*return\t+(\w*)/) {
686 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
687 $ret_type = $pseudo_to_opengl{$ret_type};
688 unless (defined($ret_type)) {
689 die "Unsupported return type in function $funcname\n";
691 } elsif ($line =~ /^\t*category/) {
692 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
693 } elsif ($line =~ /^\t*param/) {
694 my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
696 unless (defined($name)) {
698 die "Broken spec file line $line in function $funcname\n";
701 if ($ext =~ /array/) {
704 } elsif ($ext =~ /reference/) {
707 } elsif ($ext =~ /value/) {
708 # And this a 'normal' value
712 die "Unsupported type : $line in function $funcname\n";
714 # Get the 'real' type and append a '*' in case of a pointer
715 my $type = $pseudo_to_opengl{$base_type};
716 unless (defined($type)) {
718 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
722 $type = "const $type" if $dir eq "in";
725 $arg_types{$name} = $type;
729 # Now, build the argument reference
731 for (my $i = 0; $i < @arg_names; $i++) {
732 unless (defined($arg_types{$arg_names[$i]})) {
733 print "@arg_names\n";
734 foreach (sort keys %arg_types) {
735 print "$_ => $arg_types{$_}\n";
737 die "Undefined type for $arg_names[$i] in function $funcname\n";
740 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
743 # Now, put in one or the other hash table
744 if ($norm_categories{$category}) {
745 $norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
746 } elsif ($file =~ /^wgl/) {
747 if (defined $supported_wgl_extensions{"WGL_$category"}) {
748 $ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
751 $ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
757 parse_registry_file( "gl.spec" );
758 parse_registry_file( "wglext.spec" );
761 # Get the current wgl_driver.h version
764 open HEADER, "<../../include/wine/wgl_driver.h" or die "cannot open wgl_driver.h";
767 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
774 # Generate the wgl_driver.h file
776 open HEADER, ">../../include/wine/wgl_driver.h" or die "cannot create wgl_driver.h";
777 print HEADER "/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
778 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
779 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
780 print HEADER "#ifndef WINE_GLAPI\n";
781 print HEADER "#define WINE_GLAPI\n";
782 print HEADER "#endif\n\n";
784 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
786 print HEADER "struct wgl_context;\n";
787 print HEADER "struct wgl_pbuffer;\n\n";
789 print HEADER "struct opengl_funcs\n{\n";
790 print HEADER " struct\n {\n";
791 foreach (sort keys %wgl_functions)
793 printf HEADER " %s;\n", get_func_proto($_, $wgl_functions{$_});
795 print HEADER " } wgl;\n\n";
797 print HEADER " struct\n {\n";
798 foreach (sort keys %norm_functions)
800 next if $_ eq "glDebugEntry";
801 printf HEADER " %s;\n", get_func_proto($_, $norm_functions{$_});
803 print HEADER " } gl;\n\n";
805 print HEADER " struct\n {\n";
806 foreach (sort keys %ext_functions)
808 printf HEADER " %s;\n", get_func_proto($_, $ext_functions{$_});
810 print HEADER " } ext;\n";
811 print HEADER "};\n\n";
813 print HEADER "#define ALL_WGL_FUNCS";
814 foreach (sort keys %norm_functions)
816 next if $_ eq "glDebugEntry";
817 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
821 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n\n";
822 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
826 # Now, generate the output files. First, the spec file.
828 open(SPEC, ">$spec_file");
830 foreach (sort keys %norm_functions) {
831 print SPEC "@ stdcall $_( ";
832 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
833 my $type = $norm_functions{$_}->[1]->[$i]->[0];
836 } elsif (defined($arg_conv{$type})) {
837 print SPEC "$@$arg_conv{$type}[0] ";
839 die "No conversion for GL type $type...\n";
842 print SPEC ") wine_$_\n";
845 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
846 @ stdcall wglCopyContext(long long long)
847 @ stdcall wglCreateContext(long)
848 @ stdcall wglCreateLayerContext(long long)
849 @ stdcall wglDeleteContext(long)
850 @ stdcall wglDescribeLayerPlane(long long long long ptr)
851 @ stdcall wglDescribePixelFormat(long long long ptr)
852 @ stdcall wglGetCurrentContext()
853 @ stdcall wglGetCurrentDC()
854 @ stub wglGetDefaultProcAddress
855 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
856 @ stdcall wglGetPixelFormat(long)
857 @ stdcall wglGetProcAddress(str)
858 @ stdcall wglMakeCurrent(long long)
859 @ stdcall wglRealizeLayerPalette(long long long)
860 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
861 @ stdcall wglSetPixelFormat(long long ptr)
862 @ stdcall wglShareLists(long long)
863 @ stdcall wglSwapBuffers(long)
864 @ stdcall wglSwapLayerBuffers(long long)
865 @ stdcall wglUseFontBitmapsA(long long long long)
866 @ stdcall wglUseFontBitmapsW(long long long long)
867 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
868 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
874 # After the spec file, the opengl_norm.c file
876 open(NORM, ">$norm_file");
878 /* Auto-generated file... Do not edit ! */
880 #include \"config.h\"
882 #include \"opengl_ext.h\"
883 #include \"winternl.h\"
884 #include \"wingdi.h\"
885 #include \"wine/wgl_driver.h\"
886 #include \"wine/debug.h\"
888 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
891 foreach (sort keys %norm_functions) {
892 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
893 print NORM "\n$string" if $string;
896 foreach (sort keys %wgl_functions) {
897 print NORM generate_null_func($_, $wgl_functions{$_});
899 foreach (sort keys %norm_functions) {
900 print NORM generate_null_func($_, $norm_functions{$_});
903 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
904 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
906 print NORM "#define USE_GL_FUNC(name) null_##name,\n";
907 print NORM " { ALL_WGL_FUNCS }\n";
908 print NORM "#undef USE_GL_FUNC\n";
914 # Finally, more complex, the opengl_ext.c file
916 open(EXT, ">$ext_file");
918 /* Auto-generated file... Do not edit ! */
920 #include \"config.h\"
922 #include \"opengl_ext.h\"
923 #include \"winternl.h\"
924 #include \"wingdi.h\"
925 #define WGL_WGLEXT_PROTOTYPES
926 #include \"wine/wglext.h\"
927 #include \"wine/wgl_driver.h\"
928 #include \"wine/debug.h\"
930 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
934 # The thunks themselves....
935 my $count = keys %ext_functions;
936 print EXT "const int extension_registry_size = $count;\n";
937 foreach (sort keys %ext_functions) {
938 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
939 print EXT "\nstatic $string" if $string;
942 # Then the table giving the string <-> function correspondence */
943 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
945 foreach (sort keys %ext_functions) {
946 my $func_ref = $ext_functions{$_};
947 my $link_name = get_func_link_name( $_, $func_ref );
948 print EXT " { \"$_\", \"$func_ref->[2]\", $link_name }";
949 if ($i != $count-1) {