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 file
163 ("GLbitfield" => [ "long", 4 ],
164 "GLboolean" => [ "long", 4 ],
165 "GLbyte" => [ "long", 4 ],
166 "GLclampd" => [ "double", 8 ],
167 "GLclampf" => [ "float", 4 ],
168 "GLdouble" => [ "double", 8 ],
169 "GLenum" => [ "long", 4 ],
170 "GLfloat" => [ "float", 4 ],
171 "GLint" => [ "long", 4 ],
172 "GLshort" => [ "long", 4 ],
173 "GLsizei" => [ "long", 4 ],
174 "GLstring" => [ "str", 4 ],
175 "GLubyte" => [ "long", 4 ],
176 "GLuint" => [ "long", 4 ],
177 "GLushort" => [ "long", 4 ],
178 "GLhalfNV" => [ "long", 4 ],
179 "GLintptrARB" => [ "long", 4 ],
180 "GLsizeiptrARB" => [ "long", 4 ],
181 "GLhandleARB" => [ "long", 4 ],
182 "GLcharARB" => [ "long", 4 ],
183 "GLintptr" => [ "long", 4 ],
184 "GLsizeiptr" => [ "long", 4 ],
185 "_GLfuncptr" => [ "ptr", 4 ]);
188 # Used to convert some types
194 my %hash = ( "GLstring" => "const GLubyte *",
195 "GLintptrARB" => "INT_PTR",
196 "GLsizeiptrARB" => "INT_PTR",
197 "GLintptr" => "INT_PTR",
198 "GLsizeiptr" => "INT_PTR",
199 "GLhandleARB" => "unsigned int",
200 "GLcharARB" => "char",
202 "GLhalfNV" => "unsigned short",
203 "GLvdpauSurfaceNV" => "INT_PTR",
204 "struct _cl_context" => "void",
205 "struct _cl_event" => "void",
206 "HGLRC" => "struct wgl_context *",
207 "GLDEBUGPROC" => "void *",
208 "GLDEBUGPROCARB" => "void *",
209 "GLDEBUGPROCAMD" => "void *",
210 "HPBUFFERARB" => "struct wgl_pbuffer *",
211 "HPBUFFEREXT" => "struct wgl_pbuffer *",
214 foreach my $org (reverse sort keys %hash) {
215 if ($type =~ /$org/) {
216 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
217 return "$before$hash{$org}$after";
224 # Used to convert some variable names
226 sub ConvertVarName($)
230 my %hash = ( "near" => "nearParam",
231 "far" => "farParam" );
233 foreach my $org (keys %hash) {
234 if ($type =~ /$org/) {
235 my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
236 return "$before$hash{$org}$after";
243 # This functions generates the thunk for a given function.
245 sub GenerateThunk($$$$)
247 my ($name, $func_ref, $comment, $prefix) = @_;
250 my $trace_call_arg = "";
253 return "" if $name eq "glDebugEntry";
254 return "" if $name eq "glGetString";
255 return "" if $func_ref->[2] && $func_ref->[2] =~ /WGL_/;
257 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
258 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
260 $ret = "$ret/***********************************************************************\n";
261 $ret = "$ret * $name (OPENGL32.\@)\n";
264 $ret = $ret . ConvertType($func_ref->[0]) . " WINAPI wine_$name( ";
265 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
266 ## Quick debug code :-)
267 ## print $func_ref->[1]->[$i]->[1] . "\n";
268 my $type = $func_ref->[1]->[$i]->[0];
269 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
270 $ret .= ConvertType($type) . " $name";
274 $trace_call_arg .= $name;
275 } elsif (defined $debug_conv{$type}) {
276 if ($debug_conv{$type} =~ /(.*),(.*)/)
279 $trace_call_arg .= sprintf $2, $name;
283 $trace_arg .= $debug_conv{$type};
284 $trace_call_arg .= $name;
287 else { printf "Unknown type %s\n", $type; }
288 if ($i+1 < @{$func_ref->[1]}) {
291 $trace_call_arg .= ", ";
296 $trace_call_arg .= " ";
299 $ret .= 'void ' if (!@{$func_ref->[1]});
301 $ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
302 if ($func_ref->[0] ne "void" && $gen_thread_safe) {
303 $ret = "$ret " . ConvertType($func_ref->[0]) . " ret_value;\n";
306 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
307 if ($trace_arg ne "") {
308 $ret .= ", $trace_call_arg";
312 if ($gen_thread_safe) {
313 $ret .= " ENTER_GL();\n";
315 if ($func_ref->[0] ne "void") {
316 $ret .= "ret_value = ";
318 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
319 $ret .= " LEAVE_GL();\n";
320 if ($func_ref->[0] ne "void") {
321 $ret .= " return ret_value;\n"
326 if ($func_ref->[0] ne "void") {
329 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
333 # Return this string....
337 sub generate_null_func($$)
339 my ($name, $func_ref) = @_;
342 return "" if $name eq "glDebugEntry";
344 $ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
345 for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
346 my $type = $func_ref->[1]->[$i]->[0];
347 my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
348 $ret .= ConvertType($type) . " $name";
349 $ret .= "," if ($i+1 < @{$func_ref->[1]});
352 $ret .= 'void ' if (!@{$func_ref->[1]});
354 if ($name eq "glGetError")
356 $ret .= " return GL_INVALID_OPERATION;";
358 elsif ($func_ref->[0] ne "void")
360 $ret .= " return 0;";
366 sub get_func_proto($$)
368 my ($name, $func) = @_;
369 my $ret = sprintf "%-10s", ConvertType($func->[0]);
370 $ret .= " (WINE_GLAPI *p_$name)(";
371 for (my $i = 0; $i < @{$func->[1]}; $i++)
373 $ret .= ConvertType($func->[1]->[$i]->[0]);
374 $ret .= "," if ($i+1 < @{$func->[1]});
376 $ret .= "void" unless @{$func->[1]};
381 sub get_func_link_name($$)
383 my ($name, $func) = @_;
384 return $name if ($func->[2] =~ /^WGL_/);
389 # Extract and checks the number of arguments
394 die "Usage: $name0 [version]\n";
396 my $version = $ARGV[0] || "1.1";
397 if ($version eq "1.0") {
398 %norm_categories = %cat_1_0;
399 } elsif ($version eq "1.1") {
400 %norm_categories = %cat_1_1;
401 } elsif ($version eq "1.2") {
402 %norm_categories = %cat_1_2;
403 } elsif ($version eq "1.3") {
404 %norm_categories = %cat_1_3;
405 } elsif ($version eq "1.4") {
406 %norm_categories = %cat_1_4;
407 } elsif ($version eq "1.5") {
408 %norm_categories = %cat_1_5;
410 die "Incorrect OpenGL version.\n";
414 # Fetch the registry files
416 -f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
417 -f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
418 -f "wgl.tm" || system "wget http://www.opengl.org/registry/api/wgl.tm" || die "cannot download wgl.tm";
419 -f "wglext.spec" || system "wget http://www.opengl.org/registry/api/wglext.spec" || die "cannot download wglext.spec";
422 # First, create a mapping between the pseudo types used in the spec file
423 # and OpenGL types using the 'gl.tm' file.
425 my %pseudo_to_opengl = ();
430 open TYPES, "<$file" or die "Could not open $file";
431 while (my $line = <TYPES>) {
432 if ($line !~ /\w*\#/) {
433 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
434 $pseudo_to_opengl{$pseudo} = $opengl;
440 load_types( "wgl.tm" );
441 load_types( "gl.tm" );
443 # This is to override the 'void' -> '*' bogus conversion
444 $pseudo_to_opengl{"void"} = "void";
445 $pseudo_to_opengl{"sync"} = "GLvoid*";
446 $pseudo_to_opengl{"Int64"} = "INT64";
447 $pseudo_to_opengl{"UInt64"} = "UINT64";
448 $pseudo_to_opengl{"Int64EXT"} = "INT64";
449 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
452 # Then, create the list of all OpenGL functions using the 'gl.spec'
453 # file. This will create two hash-tables, one with all the function
454 # whose category matches the one listed in '@norm_categories', the other
455 # with all other functions.
457 # An element of the hash table is a reference to an array with these
464 # - reference to an array giving the list of arguments (an empty array
465 # for a 'void' function).
467 # The list of arguments is itself an array of reference to arrays. Each
468 # of these arrays represents the argument type and the argument name.
472 # void glBitmap( GLsizei width, GLsizei height,
473 # GLfloat xorig, GLfloat yorig,
474 # GLfloat xmove, GLfloat ymove,
475 # const GLubyte *bitmap );
477 # Would give something like that :
481 # [ [ "GLsizei", "width" ],
482 # [ "GLsizei", "height" ],
483 # [ "GLfloat", "xorig" ],
484 # [ "GLfloat", "yorig" ],
485 # [ "GLfloat", "xmove" ],
486 # [ "GLfloat", "ymove" ],
487 # [ "GLubyte *", "bitmap"] ] ];
489 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
490 [ "GLint", "unknown2" ]] ] );
493 # This stores various extensions NOT part of the GL extension registry but still
494 # implemented by most OpenGL libraries out there...
499 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
500 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
503 [ "GLsizei", "width" ],
504 [ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
505 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
508 [ "GLsizei", "width" ],
509 [ "GLsizei", "height" ],
510 [ "GLint", "xDest" ],
511 [ "GLint", "yDest" ] ], "GL_KTX_buffer_region" ],
512 "glBufferRegionEnabled" => [ "GLuint", [ ], "GL_KTX_buffer_region" ],
513 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], "GL_KTX_buffer_region" ],
514 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
516 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
517 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
518 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
519 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
520 [ "GLdouble", "s" ] ], "GL_SGIS_multitexture" ],
521 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
522 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
523 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
524 [ "GLfloat", "s" ] ], "GL_SGIS_multitexture" ],
525 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
526 [ "const GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
527 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
528 [ "GLint", "s" ] ], "GL_SGIS_multitexture" ],
529 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
530 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
531 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLshort", "s" ] ], "GL_SGIS_multitexture" ],
533 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
534 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
535 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
538 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
539 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
540 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
542 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
543 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
544 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
545 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
548 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
549 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
550 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
552 [ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
553 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
554 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
555 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
558 [ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
559 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
560 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
561 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
564 [ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
565 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
566 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
567 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
570 [ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
571 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
572 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
573 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
576 [ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
577 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
578 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
579 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
583 [ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
584 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
585 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
586 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
590 [ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
591 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
592 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
593 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
597 [ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
598 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
599 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
600 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
604 [ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
605 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
606 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
607 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
609 [ "GLenum", "type" ],
610 [ "GLsizei", "stride" ],
611 [ "GLvoid *", "pointer" ] ], "GL_SGIS_multitexture" ],
612 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
613 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
614 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], "GL_ATI_vertex_array_object" ],
615 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
616 [ "int", "format" ] ], "WGL_WINE_pixel_format_passthrough" ],
622 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
623 [ "struct wgl_context *", "dst" ],
624 [ "UINT", "mask" ] ] ],
625 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
626 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
627 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
630 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
631 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
632 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
633 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
634 [ "struct wgl_context *", "context" ] ] ],
635 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
637 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
638 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
639 [ "struct wgl_context *", "dst" ] ] ],
640 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
643 my %supported_wgl_extensions =
645 "WGL_ARB_create_context" => 1,
646 "WGL_ARB_extensions_string" => 1,
647 "WGL_ARB_make_current_read" => 1,
648 "WGL_ARB_pbuffer" => 1,
649 "WGL_ARB_pixel_format" => 1,
650 "WGL_ARB_render_texture" => 1,
651 "WGL_EXT_extensions_string" => 1,
652 "WGL_EXT_swap_control" => 1,
653 "WGL_NV_vertex_array_range" => 1,
654 "WGL_WINE_pixel_format_passthrough" => 1,
657 sub parse_registry_file($)
662 open REGISTRY, "<$file" or die "cannot open $file";
663 while (my $line = <REGISTRY>) {
664 next unless ($line =~ /^\w*\(.*\)/);
666 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
667 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
668 # and the argument names
669 @arg_names = split /\s*,\s*/, $args;
673 # - category (the extension the function is part of)
674 # - the argument types
675 # - the category the function belongs
681 unless (defined($line)) {
683 } elsif ($line =~ /^\s*$/) {
684 if (($category eq "") || ($ret_type eq "")) {
685 die "Missing 'category' line in function $funcname.\n";
688 } elsif ($line =~ /\t*return\t+(\w*)/) {
689 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
690 $ret_type = $pseudo_to_opengl{$ret_type};
691 unless (defined($ret_type)) {
692 die "Unsupported return type in function $funcname\n";
694 } elsif ($line =~ /^\t*category/) {
695 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
696 } elsif ($line =~ /^\t*param/) {
697 my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
699 unless (defined($name)) {
701 die "Broken spec file line $line in function $funcname\n";
704 if ($ext =~ /array/) {
707 } elsif ($ext =~ /reference/) {
710 } elsif ($ext =~ /value/) {
711 # And this a 'normal' value
715 die "Unsupported type : $line in function $funcname\n";
717 # Get the 'real' type and append a '*' in case of a pointer
718 my $type = $pseudo_to_opengl{$base_type};
719 unless (defined($type)) {
721 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
725 $type = "const $type" if $dir eq "in";
728 $arg_types{$name} = $type;
732 # Now, build the argument reference
734 for (my $i = 0; $i < @arg_names; $i++) {
735 unless (defined($arg_types{$arg_names[$i]})) {
736 print "@arg_names\n";
737 foreach (sort keys %arg_types) {
738 print "$_ => $arg_types{$_}\n";
740 die "Undefined type for $arg_names[$i] in function $funcname\n";
743 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
746 # Now, put in one or the other hash table
747 if ($norm_categories{$category}) {
748 $norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
749 } elsif ($file =~ /^wgl/) {
750 if (defined $supported_wgl_extensions{"WGL_$category"}) {
751 $ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
754 $ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
760 parse_registry_file( "gl.spec" );
761 parse_registry_file( "wglext.spec" );
764 # Get the current wgl_driver.h version
767 open HEADER, "<../../include/wine/wgl_driver.h" or die "cannot open wgl_driver.h";
770 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
777 # Generate the wgl_driver.h file
779 open HEADER, ">../../include/wine/wgl_driver.h" or die "cannot create wgl_driver.h";
780 print HEADER "/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
781 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
782 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
783 print HEADER "#ifndef WINE_GLAPI\n";
784 print HEADER "#define WINE_GLAPI\n";
785 print HEADER "#endif\n\n";
787 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
789 print HEADER "struct wgl_context;\n";
790 print HEADER "struct wgl_pbuffer;\n\n";
792 print HEADER "struct opengl_funcs\n{\n";
793 print HEADER " struct\n {\n";
794 foreach (sort keys %wgl_functions)
796 printf HEADER " %s;\n", get_func_proto($_, $wgl_functions{$_});
798 print HEADER " } wgl;\n\n";
800 print HEADER " struct\n {\n";
801 foreach (sort keys %norm_functions)
803 next if $_ eq "glDebugEntry";
804 printf HEADER " %s;\n", get_func_proto($_, $norm_functions{$_});
806 print HEADER " } gl;\n\n";
808 print HEADER " struct\n {\n";
809 foreach (sort keys %ext_functions)
811 printf HEADER " %s;\n", get_func_proto($_, $ext_functions{$_});
813 print HEADER " } ext;\n";
814 print HEADER "};\n\n";
816 print HEADER "#define ALL_WGL_FUNCS";
817 foreach (sort keys %norm_functions)
819 next if $_ eq "glDebugEntry";
820 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
824 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n\n";
825 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
829 # Now, generate the output files. First, the spec file.
831 open(SPEC, ">$spec_file");
833 foreach (sort keys %norm_functions) {
834 print SPEC "@ stdcall $_( ";
835 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
836 my $type = $norm_functions{$_}->[1]->[$i]->[0];
839 } elsif (defined($arg_conv{$type})) {
840 print SPEC "$@$arg_conv{$type}[0] ";
842 die "No conversion for GL type $type...\n";
845 print SPEC ") wine_$_\n";
848 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
849 @ stdcall wglCopyContext(long long long)
850 @ stdcall wglCreateContext(long)
851 @ stdcall wglCreateLayerContext(long long)
852 @ stdcall wglDeleteContext(long)
853 @ stdcall wglDescribeLayerPlane(long long long long ptr)
854 @ stdcall wglDescribePixelFormat(long long long ptr)
855 @ stdcall wglGetCurrentContext()
856 @ stdcall wglGetCurrentDC()
857 @ stub wglGetDefaultProcAddress
858 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
859 @ stdcall wglGetPixelFormat(long)
860 @ stdcall wglGetProcAddress(str)
861 @ stdcall wglMakeCurrent(long long)
862 @ stdcall wglRealizeLayerPalette(long long long)
863 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
864 @ stdcall wglSetPixelFormat(long long ptr)
865 @ stdcall wglShareLists(long long)
866 @ stdcall wglSwapBuffers(long)
867 @ stdcall wglSwapLayerBuffers(long long)
868 @ stdcall wglUseFontBitmapsA(long long long long)
869 @ stdcall wglUseFontBitmapsW(long long long long)
870 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
871 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
877 # After the spec file, the opengl_norm.c file
879 open(NORM, ">$norm_file");
881 /* Auto-generated file... Do not edit ! */
883 #include \"config.h\"
885 #include \"opengl_ext.h\"
886 #include \"winternl.h\"
887 #include \"wingdi.h\"
888 #include \"wine/wgl_driver.h\"
889 #include \"wine/debug.h\"
891 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
894 foreach (sort keys %norm_functions) {
895 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
896 print NORM "\n$string" if $string;
899 foreach (sort keys %wgl_functions) {
900 print NORM generate_null_func($_, $wgl_functions{$_});
902 foreach (sort keys %norm_functions) {
903 print NORM generate_null_func($_, $norm_functions{$_});
905 foreach (sort keys %ext_functions) {
906 print NORM generate_null_func($_, $ext_functions{$_});
909 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
910 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
911 print NORM " },\n {\n";
912 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
913 print NORM " },\n {\n";
914 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
915 print NORM " }\n};\n";
920 # Finally, more complex, the opengl_ext.c file
922 open(EXT, ">$ext_file");
924 /* Auto-generated file... Do not edit ! */
926 #include \"config.h\"
928 #include \"opengl_ext.h\"
929 #include \"winternl.h\"
930 #include \"wingdi.h\"
931 #define WGL_WGLEXT_PROTOTYPES
932 #include \"wine/wglext.h\"
933 #include \"wine/wgl_driver.h\"
934 #include \"wine/debug.h\"
936 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
940 # The thunks themselves....
941 my $count = keys %ext_functions;
942 print EXT "const int extension_registry_size = $count;\n";
943 foreach (sort keys %ext_functions) {
944 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
945 print EXT "\nstatic $string" if $string;
948 # Then the table giving the string <-> function correspondence */
949 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
951 foreach (sort keys %ext_functions) {
952 my $func_ref = $ext_functions{$_};
953 my $link_name = get_func_link_name( $_, $func_ref );
954 print EXT " { \"$_\", \"$func_ref->[2]\", $link_name }";
955 if ($i != $count-1) {