opengl32: Use variables for file names.
[wine.git] / dlls / opengl32 / make_opengl
blob9817f8cd1dd64a513a74ded4267edcf24654539a
1 #!/usr/bin/perl -w
2 use strict;
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
27 # 'opengl_version').
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
63 # Files to generate
65 my $spec_file = "opengl32.spec";
66 my $norm_file = "opengl_norm.c";
67 my $ext_file = "opengl_ext.c";
68 my $wgl_driver_file = "../../include/wine/wgl_driver.h";
69 my $wgl_file = "../../include/wine/wgl.h";
71 # Set to 0 for removing the ENTER / LEAVE GL calls
72 my $gen_thread_safe = 0;
73 # Prefix used for the local variables
74 my $ext_prefix = "func_";
75 # If set to 1, generate TRACEs for each OpenGL function
76 my $gen_traces = 1;
79 # List of categories to put in the 'opengl_norm.c' file
81 my %cat_1_0 = ( "display-list" => 1,
82 "drawing" => 1,
83 "drawing-control" => 1,
84 "feedback" => 1,
85 "framebuf" => 1,
86 "misc" => 1,
87 "modeling" => 1,
88 "pixel-op" => 1,
89 "pixel-rw" => 1,
90 "state-req" => 1,
91 "xform" => 1,
92 "VERSION_1_0" => 1,
93 "VERSION_1_0_DEPRECATED" => 1 );
94 my %cat_1_1 = ( %cat_1_0,
95 "VERSION_1_1" => 1,
96 "VERSION_1_1_DEPRECATED" => 1 );
97 my %cat_1_2 = ( %cat_1_1,
98 "VERSION_1_2" => 1,
99 "VERSION_1_2_DEPRECATED" => 1 );
100 my %cat_1_3 = ( %cat_1_2,
101 "VERSION_1_3" => 1,
102 "VERSION_1_3_DEPRECATED" => 1 );
103 my %cat_1_4 = ( %cat_1_3,
104 "VERSION_1_4" => 1,
105 "VERSION_1_4_DEPRECATED" => 1 );
106 my %cat_1_5 = ( %cat_1_4,
107 "VERSION_1_5" => 1,
108 "VERSION_1_5_DEPRECATED" => 1 );
110 my %norm_categories = ();
113 # This hash table gives the conversion between OpenGL types and what
114 # is used by the TRACE printfs
116 my %debug_conv =
117 ("GLbitfield" => "%d",
118 "GLboolean" => "%d",
119 "GLbyte" => "%d",
120 "GLclampd" => "%f",
121 "GLclampf" => "%f",
122 "GLdouble" => "%f",
123 "GLenum" => "%d",
124 "GLfloat" => "%f",
125 "GLint" => "%d",
126 "GLshort" => "%d",
127 "GLsizei" => "%d",
128 "GLstring" => "%s",
129 "GLubyte" => "%d",
130 "GLuint" => "%d",
131 "GLushort" => "%d",
132 "GLhalfNV" => "%d",
133 "GLintptrARB" => "%ld",
134 "GLsizeiptrARB" => "%ld",
135 "GLintptr" => "%ld",
136 "GLsizeiptr" => "%ld",
137 "GLhandleARB" => "%d",
138 "GLcharARB" => "%c",
139 "GLvoid" => "(void)",
140 "_GLfuncptr" => "%p",
141 "GLDEBUGPROC" => "%p",
142 "GLDEBUGPROCARB" => "%p",
143 "GLDEBUGPROCAMD" => "%p",
144 "GLvdpauSurfaceNV" => "%ld",
145 "int" => "%d",
146 "unsigned int" => "%u",
147 "UINT" => "%u",
148 "DWORD" => "%u",
149 "BOOL" => "%u",
150 "INT64" => "%s,wine_dbgstr_longlong(%s)",
151 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
152 "LPVOID" => "%p",
153 "HANDLE" => "%p",
154 "HDC" => "%p",
155 "HGLRC" => "%p",
156 "HPBUFFERARB" => "%p",
157 "HPBUFFEREXT" => "%p",
161 # This hash table gives the conversion between OpenGL types and what
162 # is used in the .spec and header files.
164 my %arg_conv =
165 ("GLbitfield" => [ "long", "unsigned int" ],
166 "GLboolean" => [ "long", "unsigned char" ],
167 "GLbyte" => [ "long", "signed char" ],
168 "GLchar" => [ "long", "char" ],
169 "GLclampd" => [ "double", "double" ],
170 "GLclampf" => [ "float", "float" ],
171 "GLdouble" => [ "double", "double" ],
172 "GLenum" => [ "long", "unsigned int" ],
173 "GLfloat" => [ "float", "float" ],
174 "GLint" => [ "long", "int" ],
175 "GLint64" => [ "int64", "INT64" ],
176 "GLintptr" => [ "long", "INT_PTR" ],
177 "GLshort" => [ "long", "short" ],
178 "GLsizei" => [ "long", "int" ],
179 "GLsizeiptr" => [ "long", "INT_PTR" ],
180 "GLstring" => [ "str", "const unsigned char *" ],
181 "GLsync" => [ "ptr", "struct __GLsync *" ],
182 "GLubyte" => [ "long", "unsigned char" ],
183 "GLuint" => [ "long", "unsigned int" ],
184 "GLuint64" => [ "int64", "UINT64" ],
185 "GLushort" => [ "long", "unsigned short" ],
186 "GLvoid" => [ "void", "void" ],
187 "GLcharARB" => [ "long", "char" ],
188 "GLhandleARB" => [ "long", "unsigned int" ],
189 "GLintptrARB" => [ "long", "INT_PTR" ],
190 "GLsizeiptrARB" => [ "long", "INT_PTR" ],
191 "GLhalfNV" => [ "long", "unsigned short" ],
192 "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
195 # Used to convert some types
197 sub ConvertType($)
199 my ($type) = @_;
201 my %hash = (
202 "struct _cl_context" => "void",
203 "struct _cl_event" => "void",
204 "HGLRC" => "struct wgl_context *",
205 "GLDEBUGPROC" => "void *",
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";
218 return $type;
222 # Used to convert some variable names
224 sub ConvertVarName($)
226 my ($type) = @_;
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";
237 return $type;
241 # This functions generates the thunk for a given function.
243 sub GenerateThunk($$$$)
245 my ($name, $func_ref, $comment, $prefix) = @_;
246 my $ret = "";
247 my $call_arg = "";
248 my $trace_call_arg = "";
249 my $trace_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. :-)
257 if ($comment eq 1) {
258 $ret = "$ret/***********************************************************************\n";
259 $ret = "$ret * $name (OPENGL32.\@)\n";
260 $ret = "$ret */\n";
262 $ret = $ret . ConvertType($func_ref->[0]) . " WINAPI $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";
269 $call_arg .= $name;
270 if ($type =~ /\*/) {
271 $trace_arg .= "%p";
272 $trace_call_arg .= $name;
273 } elsif (defined $debug_conv{$type}) {
274 if ($debug_conv{$type} =~ /(.*),(.*)/)
276 $trace_arg .= $1;
277 $trace_call_arg .= sprintf $2, $name;
279 else
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]}) {
287 $ret .= ", ";
288 $call_arg .= ", ";
289 $trace_call_arg .= ", ";
290 $trace_arg .= ", ";
291 } else {
292 $ret .= " ";
293 $call_arg .= " ";
294 $trace_call_arg .= " ";
297 $ret .= 'void ' if (!@{$func_ref->[1]});
298 $ret .= ") {\n";
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";
303 if ($gen_traces) {
304 $ret = "$ret TRACE(\"($trace_arg)\\n\"";
305 if ($trace_arg ne "") {
306 $ret .= ", $trace_call_arg";
308 $ret = "$ret);\n";
310 if ($gen_thread_safe) {
311 $ret .= " ENTER_GL();\n";
312 $ret .= " ";
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"
322 else {
323 $ret .= " ";
324 if ($func_ref->[0] ne "void") {
325 $ret .= "return ";
327 $ret .= "funcs->$prefix.p_$name( $call_arg);\n";
329 $ret = "$ret}\n";
331 # Return this string....
332 return $ret;
335 sub generate_null_func($$)
337 my ($name, $func_ref) = @_;
338 my $ret;
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]});
348 $ret .= " ";
350 $ret .= 'void ' if (!@{$func_ref->[1]});
351 $ret .= ") {";
352 if ($name eq "glGetError")
354 $ret .= " return GL_INVALID_OPERATION;";
356 elsif ($func_ref->[0] ne "void")
358 $ret .= " return 0;";
360 $ret .= " }\n";
361 return $ret;
364 sub get_func_proto($$$)
366 my ($format, $name, $func) = @_;
367 my $ret = sprintf "%-10s", ConvertType($func->[0]);
368 $ret .= " " . sprintf($format,$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]};
375 $ret .= ")";
376 return $ret;
380 # Extract and checks the number of arguments
382 if (@ARGV > 1) {
383 my $name0=$0;
384 $name0=~s%^.*/%%;
385 die "Usage: $name0 [version]\n";
387 my $version = $ARGV[0] || "1.1";
388 if ($version eq "1.0") {
389 %norm_categories = %cat_1_0;
390 } elsif ($version eq "1.1") {
391 %norm_categories = %cat_1_1;
392 } elsif ($version eq "1.2") {
393 %norm_categories = %cat_1_2;
394 } elsif ($version eq "1.3") {
395 %norm_categories = %cat_1_3;
396 } elsif ($version eq "1.4") {
397 %norm_categories = %cat_1_4;
398 } elsif ($version eq "1.5") {
399 %norm_categories = %cat_1_5;
400 } else {
401 die "Incorrect OpenGL version.\n";
405 # Fetch the registry files
407 -f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
408 -f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
409 -f "wgl.tm" || system "wget http://www.opengl.org/registry/api/wgl.tm" || die "cannot download wgl.tm";
410 -f "wglext.spec" || system "wget http://www.opengl.org/registry/api/wglext.spec" || die "cannot download wglext.spec";
411 -f "enum.spec" || system "wget http://www.opengl.org/registry/api/enum.spec" || die "cannot download enum.spec";
412 -f "enumext.spec" || system "wget http://www.opengl.org/registry/api/enumext.spec" || die "cannot download enumext.spec";
415 # First, create a mapping between the pseudo types used in the spec file
416 # and OpenGL types using the 'gl.tm' file.
418 my %pseudo_to_opengl = ();
420 sub load_types($)
422 my $file = shift;
423 open TYPES, "<$file" or die "Could not open $file";
424 while (my $line = <TYPES>) {
425 if ($line !~ /\w*\#/) {
426 my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
427 $pseudo_to_opengl{$pseudo} = $opengl;
430 close TYPES;
433 load_types( "wgl.tm" );
434 load_types( "gl.tm" );
436 # This is to override the 'void' -> '*' bogus conversion
437 $pseudo_to_opengl{"void"} = "void";
438 $pseudo_to_opengl{"sync"} = "GLvoid*";
439 $pseudo_to_opengl{"Int64"} = "INT64";
440 $pseudo_to_opengl{"UInt64"} = "UINT64";
441 $pseudo_to_opengl{"Int64EXT"} = "INT64";
442 $pseudo_to_opengl{"UInt64EXT"} = "UINT64";
445 # Then, create the list of all OpenGL functions using the 'gl.spec'
446 # file. This will create two hash-tables, one with all the function
447 # whose category matches the one listed in '@norm_categories', the other
448 # with all other functions.
450 # An element of the hash table is a reference to an array with these
451 # elements :
453 # - function name
455 # - return type
457 # - reference to an array giving the list of arguments (an empty array
458 # for a 'void' function).
460 # The list of arguments is itself an array of reference to arrays. Each
461 # of these arrays represents the argument type and the argument name.
463 # An example :
465 # void glBitmap( GLsizei width, GLsizei height,
466 # GLfloat xorig, GLfloat yorig,
467 # GLfloat xmove, GLfloat ymove,
468 # const GLubyte *bitmap );
470 # Would give something like that :
472 # [ "glBitmap",
473 # "void",
474 # [ [ "GLsizei", "width" ],
475 # [ "GLsizei", "height" ],
476 # [ "GLfloat", "xorig" ],
477 # [ "GLfloat", "yorig" ],
478 # [ "GLfloat", "xmove" ],
479 # [ "GLfloat", "ymove" ],
480 # [ "GLubyte *", "bitmap"] ] ];
482 my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
483 [ "GLint", "unknown2" ]] ] );
486 # This stores various extensions NOT part of the GL extension registry but still
487 # implemented by most OpenGL libraries out there...
490 my %ext_functions =
492 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
493 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
494 [ "GLint", "x" ],
495 [ "GLint", "y" ],
496 [ "GLsizei", "width" ],
497 [ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
498 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
499 [ "GLint", "x" ],
500 [ "GLint", "y" ],
501 [ "GLsizei", "width" ],
502 [ "GLsizei", "height" ],
503 [ "GLint", "xDest" ],
504 [ "GLint", "yDest" ] ], "GL_KTX_buffer_region" ],
505 "glBufferRegionEnabled" => [ "GLuint", [ ], "GL_KTX_buffer_region" ],
506 "glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], "GL_KTX_buffer_region" ],
507 "glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
508 [ "GLfloat", "s" ],
509 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
510 "glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
511 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
512 "glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
513 [ "GLdouble", "s" ] ], "GL_SGIS_multitexture" ],
514 "glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
515 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
516 "glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
517 [ "GLfloat", "s" ] ], "GL_SGIS_multitexture" ],
518 "glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
519 [ "const GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
520 "glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
521 [ "GLint", "s" ] ], "GL_SGIS_multitexture" ],
522 "glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
523 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
524 "glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
525 [ "GLshort", "s" ] ], "GL_SGIS_multitexture" ],
526 "glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
527 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
528 "glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
529 [ "GLdouble", "s"],
530 [ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
531 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
532 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
533 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
534 [ "GLfloat", "s" ],
535 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
536 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
538 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
539 [ "GLint", "s" ],
540 [ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
541 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
542 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
543 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
544 [ "GLshort", "s" ],
545 [ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
546 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
548 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
549 [ "GLdouble", "s" ],
550 [ "GLdouble", "t" ],
551 [ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
552 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
553 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
554 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
555 [ "GLfloat", "s" ],
556 [ "GLfloat", "t" ],
557 [ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
558 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
559 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
560 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
561 [ "GLint", "s" ],
562 [ "GLint", "t" ],
563 [ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
564 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
565 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
566 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
567 [ "GLshort", "s" ],
568 [ "GLshort", "t" ],
569 [ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
570 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
571 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
572 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
573 [ "GLdouble", "s" ],
574 [ "GLdouble", "t" ],
575 [ "GLdouble", "r" ],
576 [ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
577 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
578 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
579 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
580 [ "GLfloat", "s" ],
581 [ "GLfloat", "t" ],
582 [ "GLfloat", "r" ],
583 [ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
584 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
585 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
586 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
587 [ "GLint", "s" ],
588 [ "GLint", "t" ],
589 [ "GLint", "r" ],
590 [ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
591 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
592 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
593 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
594 [ "GLshort", "s" ],
595 [ "GLshort", "t" ],
596 [ "GLshort", "r" ],
597 [ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
598 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
599 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
600 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
601 [ "GLint", "size" ],
602 [ "GLenum", "type" ],
603 [ "GLsizei", "stride" ],
604 [ "GLvoid *", "pointer" ] ], "GL_SGIS_multitexture" ],
605 "glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
606 "glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
607 "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], "GL_ATI_vertex_array_object" ],
608 "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
609 [ "int", "format" ] ], "WGL_WINE_pixel_format_passthrough" ],
613 my %wgl_functions =
615 "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
616 [ "struct wgl_context *", "dst" ],
617 [ "UINT", "mask" ] ] ],
618 "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
619 "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
620 "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
621 [ "INT", "format" ],
622 [ "UINT", "size" ],
623 [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
624 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
625 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
626 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
627 [ "struct wgl_context *", "context" ] ] ],
628 "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
629 [ "INT", "format" ],
630 [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
631 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
632 [ "struct wgl_context *", "dst" ] ] ],
633 "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
636 my %supported_wgl_extensions =
638 "WGL_ARB_create_context" => 1,
639 "WGL_ARB_extensions_string" => 1,
640 "WGL_ARB_make_current_read" => 1,
641 "WGL_ARB_pbuffer" => 1,
642 "WGL_ARB_pixel_format" => 1,
643 "WGL_ARB_render_texture" => 1,
644 "WGL_EXT_extensions_string" => 1,
645 "WGL_EXT_swap_control" => 1,
646 "WGL_NV_vertex_array_range" => 1,
647 "WGL_WINE_pixel_format_passthrough" => 1,
650 sub parse_registry_file($)
652 my $file = shift;
653 my @arg_names;
654 my %arg_types;
655 open REGISTRY, "<$file" or die "cannot open $file";
656 while (my $line = <REGISTRY>) {
657 next unless ($line =~ /^\w*\(.*\)/);
659 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
660 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
661 # and the argument names
662 @arg_names = split /\s*,\s*/, $args;
664 # After get :
665 # - the return type
666 # - category (the extension the function is part of)
667 # - the argument types
668 # - the category the function belongs
669 %arg_types = ();
670 my $category = "";
671 my $ret_type = "";
672 while (1) {
673 $line = <REGISTRY>;
674 unless (defined($line)) {
675 last;
676 } elsif ($line =~ /^\s*$/) {
677 if (($category eq "") || ($ret_type eq "")) {
678 die "Missing 'category' line in function $funcname.\n";
680 last;
681 } elsif ($line =~ /\t*return\t+(\w*)/) {
682 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
683 $ret_type = $pseudo_to_opengl{$ret_type};
684 unless (defined($ret_type)) {
685 die "Unsupported return type in function $funcname\n";
687 } elsif ($line =~ /^\t*category/) {
688 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
689 } elsif ($line =~ /^\t*param/) {
690 my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
691 my $ptr = 0;
692 unless (defined($name)) {
693 chomp $line;
694 die "Broken spec file line $line in function $funcname\n";
697 if ($ext =~ /array/) {
698 # This is a pointer
699 $ptr = 1;
700 } elsif ($ext =~ /reference/) {
701 # This is a pointer
702 $ptr = 1;
703 } elsif ($ext =~ /value/) {
704 # And this a 'normal' value
705 $ptr = 0;
706 } else {
707 chomp $line;
708 die "Unsupported type : $line in function $funcname\n";
710 # Get the 'real' type and append a '*' in case of a pointer
711 my $type = $pseudo_to_opengl{$base_type};
712 unless (defined($type)) {
713 chomp $line;
714 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
716 if ($ptr) {
717 $type .= "*";
718 $type = "const $type" if $dir eq "in";
721 $arg_types{$name} = $type;
725 # Now, build the argument reference
726 my $arg_ref = [ ];
727 for (my $i = 0; $i < @arg_names; $i++) {
728 unless (defined($arg_types{$arg_names[$i]})) {
729 print "@arg_names\n";
730 foreach (sort keys %arg_types) {
731 print "$_ => $arg_types{$_}\n";
733 die "Undefined type for $arg_names[$i] in function $funcname\n";
736 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
739 # Now, put in one or the other hash table
740 if ($norm_categories{$category}) {
741 $norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
742 } elsif ($file =~ /^wgl/) {
743 if (defined $supported_wgl_extensions{"WGL_$category"}) {
744 $ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
746 } else {
747 $ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
750 close REGISTRY;
753 sub parse_enum_file($$)
755 my ($file, $enums) = @_;
756 open FILE, "<$file" or die "cannot open $file";
757 while (<FILE>)
759 chomp;
760 next if /^#/;
761 if (/^\t([0-9A-Z_]+)\s*=\s*(((0x[0-9A-Fa-f]+)|([0-9]+))([uUlL]+)?)/)
763 ${$enums}{"GL_$1"} = $2;
764 next;
767 close FILE;
770 parse_registry_file( "gl.spec" );
771 parse_registry_file( "wglext.spec" );
773 my %enums = ();
774 parse_enum_file( "enum.spec", \%enums );
775 parse_enum_file( "enumext.spec", \%enums );
778 # Get the current wgl_driver.h version
780 my $wgl_version = 0;
781 open HEADER, "<$wgl_driver_file" or die "cannot open $wgl_driver_file";
782 while (<HEADER>)
784 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
785 $wgl_version = $1;
786 last;
788 close HEADER;
791 # Generate the wgl_driver.h file
793 open HEADER, ">$wgl_driver_file" or die "cannot create $wgl_driver_file";
794 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
795 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
796 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
797 print HEADER "#ifndef WINE_GLAPI\n";
798 print HEADER "#define WINE_GLAPI\n";
799 print HEADER "#endif\n\n";
801 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
803 print HEADER "struct wgl_context;\n";
804 print HEADER "struct wgl_pbuffer;\n\n";
806 print HEADER "struct opengl_funcs\n{\n";
807 print HEADER " struct\n {\n";
808 foreach (sort keys %wgl_functions)
810 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
812 print HEADER " } wgl;\n\n";
814 print HEADER " struct\n {\n";
815 foreach (sort keys %norm_functions)
817 next if $_ eq "glDebugEntry";
818 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
820 print HEADER " } gl;\n\n";
822 print HEADER " struct\n {\n";
823 foreach (sort keys %ext_functions)
825 printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
827 print HEADER " } ext;\n";
828 print HEADER "};\n\n";
830 print HEADER "#define ALL_WGL_FUNCS";
831 foreach (sort keys %norm_functions)
833 next if $_ eq "glDebugEntry";
834 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
836 print HEADER "\n\n";
838 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
839 print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
840 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
841 close HEADER;
844 # Generate the wgl.h file
846 open HEADER, ">$wgl_file" or die "cannot create $wgl_file";
847 print HEADER "/* Automatically generated from http://www.opengl.org/registry files; DO NOT EDIT! */\n\n";
848 print HEADER "#ifndef __WINE_WGL_H\n";
849 print HEADER "#define __WINE_WGL_H\n\n";
851 print HEADER "#ifndef GLAPIENTRY\n";
852 print HEADER "#define GLAPIENTRY __stdcall\n";
853 print HEADER "#endif\n\n";
855 foreach (sort keys %arg_conv)
857 printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
859 print HEADER "\n";
861 my $maxlen = 1;
862 foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
863 foreach (sort keys %enums)
865 printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
867 print HEADER "\n";
869 foreach (sort keys %norm_functions)
871 printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
874 print HEADER "\n#endif /* __WINE_WGL_H */\n";
875 close HEADER;
878 # Now, generate the output files. First, the spec file.
880 open(SPEC, ">$spec_file");
882 foreach (sort keys %norm_functions) {
883 my $args=" ";
884 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
885 my $type = $norm_functions{$_}->[1]->[$i]->[0];
886 if ($type =~ /\*/) {
887 $args .= "ptr ";
888 } elsif (defined($arg_conv{$type})) {
889 $args .= "$@$arg_conv{$type}[0] ";
890 } else {
891 die "No conversion for GL type $type...\n";
894 $args = substr($args,1,-1);
895 print SPEC "@ stdcall $_($args)\n";
898 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
899 @ stdcall wglCopyContext(long long long)
900 @ stdcall wglCreateContext(long)
901 @ stdcall wglCreateLayerContext(long long)
902 @ stdcall wglDeleteContext(long)
903 @ stdcall wglDescribeLayerPlane(long long long long ptr)
904 @ stdcall wglDescribePixelFormat(long long long ptr)
905 @ stdcall wglGetCurrentContext()
906 @ stdcall wglGetCurrentDC()
907 @ stub wglGetDefaultProcAddress
908 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
909 @ stdcall wglGetPixelFormat(long)
910 @ stdcall wglGetProcAddress(str)
911 @ stdcall wglMakeCurrent(long long)
912 @ stdcall wglRealizeLayerPalette(long long long)
913 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
914 @ stdcall wglSetPixelFormat(long long ptr)
915 @ stdcall wglShareLists(long long)
916 @ stdcall wglSwapBuffers(long)
917 @ stdcall wglSwapLayerBuffers(long long)
918 @ stdcall wglUseFontBitmapsA(long long long long)
919 @ stdcall wglUseFontBitmapsW(long long long long)
920 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
921 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
924 close(SPEC);
927 # After the spec file, the opengl_norm.c file
929 open(NORM, ">$norm_file");
930 print NORM "
931 /* Auto-generated file... Do not edit ! */
933 #include \"config.h\"
934 #include <stdarg.h>
935 #include \"winternl.h\"
936 #include \"wingdi.h\"
937 #include \"wine/wgl.h\"
938 #include \"wine/wgl_driver.h\"
939 #include \"wine/debug.h\"
941 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
944 foreach (sort keys %norm_functions) {
945 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
946 print NORM "\n$string" if $string;
949 foreach (sort keys %wgl_functions) {
950 print NORM generate_null_func($_, $wgl_functions{$_});
952 foreach (sort keys %norm_functions) {
953 print NORM generate_null_func($_, $norm_functions{$_});
955 foreach (sort keys %ext_functions) {
956 print NORM generate_null_func($_, $ext_functions{$_});
959 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
960 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
961 print NORM " },\n {\n";
962 foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
963 print NORM " },\n {\n";
964 foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
965 print NORM " }\n};\n";
967 close(NORM);
970 # Finally, more complex, the opengl_ext.c file
972 open(EXT, ">$ext_file");
973 print EXT "
974 /* Auto-generated file... Do not edit ! */
976 #include \"config.h\"
977 #include <stdarg.h>
978 #include \"opengl_ext.h\"
979 #include \"winternl.h\"
980 #include \"wingdi.h\"
981 #include \"wine/wgl.h\"
982 #define WGL_WGLEXT_PROTOTYPES
983 #include \"wine/wglext.h\"
984 #include \"wine/wgl_driver.h\"
985 #include \"wine/debug.h\"
987 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
991 # The thunks themselves....
992 my $count = keys %ext_functions;
993 print EXT "const int extension_registry_size = $count;\n";
994 foreach (sort keys %ext_functions) {
995 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
996 print EXT "\nstatic $string" if $string;
999 # Then the table giving the string <-> function correspondence */
1000 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
1001 my $i = 0;
1002 foreach (sort keys %ext_functions) {
1003 my $func_ref = $ext_functions{$_};
1004 print EXT " { \"$_\", \"$func_ref->[2]\", $_ }";
1005 if ($i != $count-1) {
1006 print EXT ",";
1008 $i++;
1009 print EXT "\n";
1011 print EXT "};\n";
1013 close(EXT);