Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / opengl32 / make_opengl
blobcf6d4e11c6a802b73300564eb5a6b08f89302a8c
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";
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
74 my $gen_traces = 1;
77 # List of categories to put in the 'opengl_norm.c' file
79 my %cat_1_0 = ( "display-list" => 1,
80 "drawing" => 1,
81 "drawing-control" => 1,
82 "feedback" => 1,
83 "framebuf" => 1,
84 "misc" => 1,
85 "modeling" => 1,
86 "pixel-op" => 1,
87 "pixel-rw" => 1,
88 "state-req" => 1,
89 "xform" => 1,
90 "VERSION_1_0" => 1,
91 "VERSION_1_0_DEPRECATED" => 1 );
92 my %cat_1_1 = ( %cat_1_0,
93 "VERSION_1_1" => 1,
94 "VERSION_1_1_DEPRECATED" => 1 );
95 my %cat_1_2 = ( %cat_1_1,
96 "VERSION_1_2" => 1,
97 "VERSION_1_2_DEPRECATED" => 1 );
98 my %cat_1_3 = ( %cat_1_2,
99 "VERSION_1_3" => 1,
100 "VERSION_1_3_DEPRECATED" => 1 );
101 my %cat_1_4 = ( %cat_1_3,
102 "VERSION_1_4" => 1,
103 "VERSION_1_4_DEPRECATED" => 1 );
104 my %cat_1_5 = ( %cat_1_4,
105 "VERSION_1_5" => 1,
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
114 my %debug_conv =
115 ("GLbitfield" => "%d",
116 "GLboolean" => "%d",
117 "GLbyte" => "%d",
118 "GLclampd" => "%f",
119 "GLclampf" => "%f",
120 "GLdouble" => "%f",
121 "GLenum" => "%d",
122 "GLfloat" => "%f",
123 "GLint" => "%d",
124 "GLshort" => "%d",
125 "GLsizei" => "%d",
126 "GLstring" => "%s",
127 "GLubyte" => "%d",
128 "GLuint" => "%d",
129 "GLushort" => "%d",
130 "GLhalfNV" => "%d",
131 "GLintptrARB" => "%ld",
132 "GLsizeiptrARB" => "%ld",
133 "GLintptr" => "%ld",
134 "GLsizeiptr" => "%ld",
135 "GLhandleARB" => "%d",
136 "GLcharARB" => "%c",
137 "GLvoid" => "(void)",
138 "_GLfuncptr" => "%p",
139 "GLDEBUGPROCARB" => "%p",
140 "GLDEBUGPROCAMD" => "%p",
141 "GLvdpauSurfaceNV" => "%ld",
142 "int" => "%d",
143 "unsigned int" => "%u",
144 "UINT" => "%u",
145 "DWORD" => "%u",
146 "BOOL" => "%u",
147 "INT64" => "%s,wine_dbgstr_longlong(%s)",
148 "UINT64" => "%s,wine_dbgstr_longlong(%s)",
149 "LPVOID" => "%p",
150 "HANDLE" => "%p",
151 "HDC" => "%p",
152 "HGLRC" => "%p",
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
161 my %arg_conv =
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
189 sub ConvertType($)
191 my ($type) = @_;
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",
200 "GLchar" => "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";
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 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";
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 ($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]};
375 $ret .= ")";
376 return $ret;
379 sub get_func_link_name($$)
381 my ($name, $func) = @_;
382 return $name if ($func->[2] =~ /^WGL_/);
383 return "wine_$name";
387 # Extract and checks the number of arguments
389 if (@ARGV > 1) {
390 my $name0=$0;
391 $name0=~s%^.*/%%;
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;
407 } else {
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 = ();
425 sub load_types($)
427 my $file = shift;
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;
435 close TYPES;
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
456 # elements :
458 # - function name
460 # - return type
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.
468 # An example :
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 :
477 # [ "glBitmap",
478 # "void",
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...
495 my %ext_functions =
497 "glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
498 "glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
499 [ "GLint", "x" ],
500 [ "GLint", "y" ],
501 [ "GLsizei", "width" ],
502 [ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
503 "glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
504 [ "GLint", "x" ],
505 [ "GLint", "y" ],
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" ],
513 [ "GLfloat", "s" ],
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" ],
534 [ "GLdouble", "s"],
535 [ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
536 "glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
537 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
538 "glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
539 [ "GLfloat", "s" ],
540 [ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
541 "glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
542 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
543 "glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
544 [ "GLint", "s" ],
545 [ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
546 "glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
547 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
548 "glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
549 [ "GLshort", "s" ],
550 [ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
551 "glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
552 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
553 "glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
554 [ "GLdouble", "s" ],
555 [ "GLdouble", "t" ],
556 [ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
557 "glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
558 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
559 "glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
560 [ "GLfloat", "s" ],
561 [ "GLfloat", "t" ],
562 [ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
563 "glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
564 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
565 "glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
566 [ "GLint", "s" ],
567 [ "GLint", "t" ],
568 [ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
569 "glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
570 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
571 "glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
572 [ "GLshort", "s" ],
573 [ "GLshort", "t" ],
574 [ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
575 "glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
576 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
577 "glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
578 [ "GLdouble", "s" ],
579 [ "GLdouble", "t" ],
580 [ "GLdouble", "r" ],
581 [ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
582 "glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
583 [ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
584 "glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
585 [ "GLfloat", "s" ],
586 [ "GLfloat", "t" ],
587 [ "GLfloat", "r" ],
588 [ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
589 "glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
590 [ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
591 "glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
592 [ "GLint", "s" ],
593 [ "GLint", "t" ],
594 [ "GLint", "r" ],
595 [ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
596 "glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
597 [ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
598 "glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
599 [ "GLshort", "s" ],
600 [ "GLshort", "t" ],
601 [ "GLshort", "r" ],
602 [ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
603 "glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
604 [ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
605 "glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
606 [ "GLint", "size" ],
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" ],
618 my %wgl_functions =
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 "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
626 "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
627 "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
628 [ "struct wgl_context *", "context" ] ] ],
629 "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
630 [ "struct wgl_context *", "dst" ] ] ],
633 my %supported_wgl_extensions =
635 "WGL_ARB_create_context" => 1,
636 "WGL_ARB_extensions_string" => 1,
637 "WGL_ARB_make_current_read" => 1,
638 "WGL_ARB_pbuffer" => 1,
639 "WGL_ARB_pixel_format" => 1,
640 "WGL_ARB_render_texture" => 1,
641 "WGL_EXT_extensions_string" => 1,
642 "WGL_EXT_swap_control" => 1,
643 "WGL_NV_vertex_array_range" => 1,
644 "WGL_WINE_pixel_format_passthrough" => 1,
647 sub parse_registry_file($)
649 my $file = shift;
650 my @arg_names;
651 my %arg_types;
652 open REGISTRY, "<$file" or die "cannot open $file";
653 while (my $line = <REGISTRY>) {
654 next unless ($line =~ /^\w*\(.*\)/);
656 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
657 my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
658 # and the argument names
659 @arg_names = split /\s*,\s*/, $args;
661 # After get :
662 # - the return type
663 # - category (the extension the function is part of)
664 # - the argument types
665 # - the category the function belongs
666 %arg_types = ();
667 my $category = "";
668 my $ret_type = "";
669 while (1) {
670 $line = <REGISTRY>;
671 unless (defined($line)) {
672 last;
673 } elsif ($line =~ /^\s*$/) {
674 if (($category eq "") || ($ret_type eq "")) {
675 die "Missing 'category' line in function $funcname.\n";
677 last;
678 } elsif ($line =~ /\t*return\t+(\w*)/) {
679 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
680 $ret_type = $pseudo_to_opengl{$ret_type};
681 unless (defined($ret_type)) {
682 die "Unsupported return type in function $funcname\n";
684 } elsif ($line =~ /^\t*category/) {
685 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
686 } elsif ($line =~ /^\t*param/) {
687 my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
688 my $ptr = 0;
689 unless (defined($name)) {
690 chomp $line;
691 die "Broken spec file line $line in function $funcname\n";
694 if ($ext =~ /array/) {
695 # This is a pointer
696 $ptr = 1;
697 } elsif ($ext =~ /reference/) {
698 # This is a pointer
699 $ptr = 1;
700 } elsif ($ext =~ /value/) {
701 # And this a 'normal' value
702 $ptr = 0;
703 } else {
704 chomp $line;
705 die "Unsupported type : $line in function $funcname\n";
707 # Get the 'real' type and append a '*' in case of a pointer
708 my $type = $pseudo_to_opengl{$base_type};
709 unless (defined($type)) {
710 chomp $line;
711 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
713 if ($ptr) {
714 $type .= "*";
715 $type = "const $type" if $dir eq "in";
718 $arg_types{$name} = $type;
722 # Now, build the argument reference
723 my $arg_ref = [ ];
724 for (my $i = 0; $i < @arg_names; $i++) {
725 unless (defined($arg_types{$arg_names[$i]})) {
726 print "@arg_names\n";
727 foreach (sort keys %arg_types) {
728 print "$_ => $arg_types{$_}\n";
730 die "Undefined type for $arg_names[$i] in function $funcname\n";
733 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
736 # Now, put in one or the other hash table
737 if ($norm_categories{$category}) {
738 $norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
739 } elsif ($file =~ /^wgl/) {
740 if (defined $supported_wgl_extensions{"WGL_$category"}) {
741 $ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
743 } else {
744 $ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
747 close REGISTRY;
750 parse_registry_file( "gl.spec" );
751 parse_registry_file( "wglext.spec" );
754 # Get the current wgl_driver.h version
756 my $wgl_version = 0;
757 open HEADER, "<../../include/wine/wgl_driver.h" or die "cannot open wgl_driver.h";
758 while (<HEADER>)
760 next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
761 $wgl_version = $1;
762 last;
764 close HEADER;
767 # Generate the wgl_driver.h file
769 open HEADER, ">../../include/wine/wgl_driver.h" or die "cannot create wgl_driver.h";
770 print HEADER "/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
771 print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
772 print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
773 print HEADER "#ifndef WINE_GLAPI\n";
774 print HEADER "#define WINE_GLAPI\n";
775 print HEADER "#endif\n\n";
777 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
779 print HEADER "struct wgl_context;\n";
780 print HEADER "struct wgl_pbuffer;\n\n";
782 print HEADER "struct opengl_funcs\n{\n";
783 print HEADER " struct\n {\n";
784 foreach (sort keys %wgl_functions)
786 printf HEADER " %s;\n", get_func_proto($_, $wgl_functions{$_});
788 print HEADER " } wgl;\n\n";
790 print HEADER " struct\n {\n";
791 foreach (sort keys %norm_functions)
793 next if $_ eq "glDebugEntry";
794 printf HEADER " %s;\n", get_func_proto($_, $norm_functions{$_});
796 print HEADER " } gl;\n\n";
798 print HEADER " struct\n {\n";
799 foreach (sort keys %ext_functions)
801 printf HEADER " %s;\n", get_func_proto($_, $ext_functions{$_});
803 print HEADER " } ext;\n";
804 print HEADER "};\n\n";
806 print HEADER "#define ALL_WGL_FUNCS";
807 foreach (sort keys %norm_functions)
809 next if $_ eq "glDebugEntry";
810 printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
812 print HEADER "\n\n";
814 print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n\n";
815 print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
816 close HEADER;
819 # Now, generate the output files. First, the spec file.
821 open(SPEC, ">$spec_file");
823 foreach (sort keys %norm_functions) {
824 print SPEC "@ stdcall $_( ";
825 for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
826 my $type = $norm_functions{$_}->[1]->[$i]->[0];
827 if ($type =~ /\*/) {
828 print SPEC "ptr ";
829 } elsif (defined($arg_conv{$type})) {
830 print SPEC "$@$arg_conv{$type}[0] ";
831 } else {
832 die "No conversion for GL type $type...\n";
835 print SPEC ") wine_$_\n";
838 print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
839 @ stdcall wglCopyContext(long long long)
840 @ stdcall wglCreateContext(long)
841 @ stdcall wglCreateLayerContext(long long)
842 @ stdcall wglDeleteContext(long)
843 @ stdcall wglDescribeLayerPlane(long long long long ptr)
844 @ stdcall wglDescribePixelFormat(long long long ptr)
845 @ stdcall wglGetCurrentContext()
846 @ stdcall wglGetCurrentDC()
847 @ stub wglGetDefaultProcAddress
848 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
849 @ stdcall wglGetPixelFormat(long)
850 @ stdcall wglGetProcAddress(str)
851 @ stdcall wglMakeCurrent(long long)
852 @ stdcall wglRealizeLayerPalette(long long long)
853 @ stdcall wglSetLayerPaletteEntries(long long long long ptr)
854 @ stdcall wglSetPixelFormat(long long ptr)
855 @ stdcall wglShareLists(long long)
856 @ stdcall wglSwapBuffers(long)
857 @ stdcall wglSwapLayerBuffers(long long)
858 @ stdcall wglUseFontBitmapsA(long long long long)
859 @ stdcall wglUseFontBitmapsW(long long long long)
860 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
861 @ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
864 close(SPEC);
867 # After the spec file, the opengl_norm.c file
869 open(NORM, ">$norm_file");
870 print NORM "
871 /* Auto-generated file... Do not edit ! */
873 #include \"config.h\"
874 #include <stdarg.h>
875 #include \"opengl_ext.h\"
876 #include \"winternl.h\"
877 #include \"wine/wgl_driver.h\"
878 #include \"wine/debug.h\"
880 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
883 foreach (sort keys %norm_functions) {
884 my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
885 print NORM "\n$string" if $string;
888 foreach (sort keys %wgl_functions) {
889 print NORM generate_null_func($_, $wgl_functions{$_});
891 foreach (sort keys %norm_functions) {
892 print NORM generate_null_func($_, $norm_functions{$_});
895 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
896 foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
897 print NORM " },\n";
898 print NORM "#define USE_GL_FUNC(name) null_##name,\n";
899 print NORM " { ALL_WGL_FUNCS }\n";
900 print NORM "#undef USE_GL_FUNC\n";
901 print NORM "};\n";
903 close(NORM);
906 # Finally, more complex, the opengl_ext.c file
908 open(EXT, ">$ext_file");
909 print EXT "
910 /* Auto-generated file... Do not edit ! */
912 #include \"config.h\"
913 #include <stdarg.h>
914 #include \"opengl_ext.h\"
915 #include \"winternl.h\"
916 #define WGL_WGLEXT_PROTOTYPES
917 #include \"wine/wglext.h\"
918 #include \"wine/wgl_driver.h\"
919 #include \"wine/debug.h\"
921 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
925 # The thunks themselves....
926 my $count = keys %ext_functions;
927 print EXT "const int extension_registry_size = $count;\n";
928 foreach (sort keys %ext_functions) {
929 my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
930 print EXT "\nstatic $string" if $string;
933 # Then the table giving the string <-> function correspondence */
934 print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
935 my $i = 0;
936 foreach (sort keys %ext_functions) {
937 my $func_ref = $ext_functions{$_};
938 my $link_name = get_func_link_name( $_, $func_ref );
939 print EXT " { \"$_\", \"$func_ref->[2]\", $link_name }";
940 if ($i != $count-1) {
941 print EXT ",";
943 $i++;
944 print EXT "\n";
946 print EXT "};\n";
948 close(EXT);