3 # This script is called thus :
5 # make_opengl path_to_spec_file opengl_version
7 # - path_to_spec_file is the path to the directory where the OpenGL
8 # spec files are located. These files are part of the OpenGL
9 # sample implementation CVS tree and are located in
10 # CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
11 # You can find them on the web at the following URL :
12 # http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
14 # - opengl_version is the OpenGL version emulated by the library
15 # (can be 1.0 to 1.2).
17 # This script generates the three following files :
19 # - opengl32.spec : the spec file giving all the exported functions
20 # of the OpenGL32.DLL library. These functions are the one an
21 # application can directly link to (and are all the functions
22 # defined in the OpenGL core for the version defined by
25 # - opengl_norm.c : this file contains the thunks for all OpenGL
26 # functions that are defined in 'opengl32.spec'. The corresponding
27 # functions NEED to be defined in Linux's libGL or the library
28 # won't be able to be linked in.
30 # - opengl_ext.c : in this file are stored thunks for ALL possible
31 # OpenGL extensions (at least, all the extensions that are defined
32 # in the OpenGL extension registry). Contrary to 'opengl_norm.c',
33 # you do not need to have these extensions in your libGL to have
34 # OpenGL work (as they are resolved at run-time using
35 # glXGetProcAddressARB).
41 $spec_file = "opengl32.spec";
42 $norm_file = "opengl_norm.c";
43 $ext_file = "opengl_ext.c";
45 # Set to 0 for removing the ENTER / LEAVE GL calls
47 # Prefix used for the local variables
48 $ext_prefix = "func_";
49 # If set to 1, generate TRACEs for each OpenGL function
53 # List of categories to put in the 'opengl_norm.c' file
55 %cat_1_0 = ( "display-list" => 1,
57 "drawing-control" => 1,
66 %cat_1_1 = ( %cat_1_0,
68 %cat_1_2 = ( %cat_1_1,
70 "ARB_multitexture" => 1 );
72 %norm_categories = ();
75 # This hash table gives the conversion between OpenGL types and what
76 # is used by the TRACE printfs
79 ("GLbitfield" => "%d",
95 "_GLfuncptr" => "%p");
98 # This hash table gives the conversion between OpenGL types and what
99 # is used in the .spec file
102 ("GLbitfield" => [ "long", 4 ],
103 "GLboolean" => [ "long", 4 ],
104 "GLbyte" => [ "long", 4 ],
105 "GLclampd" => [ "double", 8 ],
106 "GLclampf" => [ "long", 4 ],
107 "GLdouble" => [ "double", 8 ],
108 "GLenum" => [ "long", 4 ],
109 "GLfloat" => [ "long", 4 ],
110 "GLint" => [ "long", 4 ],
111 "GLshort" => [ "long", 4 ],
112 "GLsizei" => [ "long", 4 ],
113 "GLstring" => [ "str", 4 ],
114 "GLubyte" => [ "long", 4 ],
115 "GLuint" => [ "long", 4 ],
116 "GLushort" => [ "long", 4 ],
117 "GLvoid" => [ "void", 4 ],
118 "_GLfuncptr" => [ "ptr", 4 ]);
121 # This functions generates the thunk for a given function.
124 my ($func_ref, $comment, $prefix, $thread_safe) = @_;
126 my ($call_arg) = ("");
127 my ($trace_arg) = ("");
129 # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
130 # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
132 $ret = $ret . "/***********************************************************************\n";
133 $ret = $ret . " * " . $func_ref->[0] . " (OPENGL32.@)\n";
134 $ret = $ret . " */\n";
136 $ret = $ret . $func_ref->[1] . " WINAPI wine_" . $func_ref->[0] . "( ";
137 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
138 $type = $func_ref->[2]->[$i]->[0];
139 $name = $func_ref->[2]->[$i]->[1];
140 $ret = $ret . "$type $name";
141 $call_arg = $call_arg . "$name";
143 $trace_arg = $trace_arg . "%p";
145 $trace_arg = $trace_arg . $debug_conv{$type};
147 if ($i != $#{@{$func_ref->[2]}}) {
149 $call_arg = $call_arg . ", ";
150 $trace_arg = $trace_arg . ", ";
153 $call_arg = $call_arg . " ";
156 $ret = $ret . ") {\n";
157 if ($func_ref->[1] ne "void") {
158 $ret = $ret . " " . $func_ref->[1] . " ret_value;\n";
161 $ret = $ret . " TRACE(\"(" . $trace_arg . ")\\n\"";
162 if ($trace_arg ne "") {
163 $ret = $ret . ", " . $call_arg;
165 $ret = $ret . ");\n";
168 $ret = $ret . " ENTER_GL();\n";
171 if ($func_ref->[1] ne "void") {
172 $ret = $ret . "ret_value = ";
174 $ret = $ret . $prefix . $func_ref->[0] . "( " . $call_arg . ");\n";
176 $ret = $ret . " LEAVE_GL();\n";
178 if ($func_ref->[1] ne "void") {
179 $ret = $ret . " return ret_value;\n"
183 # Return this string....
188 # Extract and checks the number of arguments
191 die "Usage : make_opengl OpenGL_registry_location OpenGL_version.\n";
193 $registry_path = shift @ARGV;
194 $version = shift @ARGV;
195 if ($version eq "1.0") {
196 %norm_categories = %cat_1_0;
197 } elsif ($version eq "1.1") {
198 %norm_categories = %cat_1_1;
199 } elsif ($version eq "1.2") {
200 %norm_categories = %cat_1_2;
202 die "OpenGL version incorrect. Should be one of '1.0', '1.1' or '1.2'.\n";
206 # Open the registry files
208 open(TYPES, $registry_path . "/gl.tm") || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
209 open(REGISTRY, $registry_path . "/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";
212 # First, create a mapping between the pseudo types used in the spec file
213 # and OpenGL types using the 'gl.tm' file.
215 %pseudo_to_opengl = ();
216 while ($line = <TYPES>) {
217 ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
218 $pseudo_to_opengl{$pseudo} = $opengl;
220 # This is to override the 'void' -> '*' bogus conversion
221 $pseudo_to_opengl{"void"} = "void";
222 # This is a bug in the spec file...
223 $pseudo_to_opengl{"FfdTargetSGIX"} = "GLint";
224 $pseudo_to_opengl{"FfdMaskSGIX"} = "GLint";
225 $pseudo_to_opengl{"IglooFunctionSelectSGIX"} = "GLint";
226 $pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
229 # Then, create the list of all OpenGL functions using the 'gl.spec'
230 # file. This will create two hash-tables, one with all the function
231 # whose category matches the one listed in '@norm_categories', the other
232 # with all other functions.
234 # An element of the hash table is a reference to an array with these
241 # - reference to an array giving the list of arguments (an empty array
242 # for a 'void' function).
244 # The list of arguments is itself an array of reference to arrays. Each
245 # of these arrays represents the argument type and the argument name.
249 # void glBitmap( GLsizei width, GLsizei height,
250 # GLfloat xorig, GLfloat yorig,
251 # GLfloat xmove, GLfloat ymove,
252 # const GLubyte *bitmap );
254 # Would give something like that :
258 # [ [ "GLsizei", "width" ],
259 # [ "GLsizei", "height" ],
260 # [ "GLfloat", "xorig" ],
261 # [ "GLfloat", "yorig" ],
262 # [ "GLfloat", "xmove" ],
263 # [ "GLfloat", "ymove" ],
264 # [ "GLubyte *", "bitmap"] ] ];
266 %norm_functions = ();
268 ( "MultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
269 [ "GLdouble", "s" ] ] ],
270 "MultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
271 [ "GLdouble *", "v" ] ] ],
272 "MultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
273 [ "GLfloat", "s" ] ] ],
274 "MultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
275 [ "const GLfloat *", "v" ] ] ],
276 "MultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
277 [ "GLint", "s" ] ] ],
278 "MultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
279 [ "GLint *", "v" ] ] ],
280 "MultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
281 [ "GLshort", "s" ] ] ],
282 "MultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
283 [ "GLshort *", "v" ] ] ],
284 "MultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
286 [ "GLdouble", "t" ] ] ],
287 "MultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
288 [ "GLdouble *", "v" ] ] ],
289 "MultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
291 [ "GLfloat", "t" ] ] ],
292 "MultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
293 [ "GLfloat *", "v" ] ] ],
294 "MultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
296 [ "GLint", "t" ] ] ],
297 "MultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
298 [ "GLint *", "v" ] ] ],
299 "MultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
301 [ "GLshort", "t" ] ] ],
302 "MultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
303 [ "GLshort *", "v" ] ] ],
304 "MultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
307 [ "GLdouble", "r" ] ] ],
308 "MultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
309 [ "GLdouble *", "v" ] ] ],
310 "MultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
313 [ "GLfloat", "r" ] ] ],
314 "MultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
315 [ "GLfloat *", "v" ] ] ],
316 "MultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
319 [ "GLint", "r" ] ] ],
320 "MultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
321 [ "GLint *", "v" ] ] ],
322 "MultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
325 [ "GLshort", "r" ] ] ],
326 "MultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
327 [ "GLshort *", "v" ] ] ],
328 "MultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
332 [ "GLdouble", "q" ] ] ],
333 "MultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
334 [ "GLdouble *", "v" ] ] ],
335 "MultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
339 [ "GLfloat", "q" ] ] ],
340 "MultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
341 [ "GLfloat *", "v" ] ] ],
342 "MultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
346 [ "GLint", "q" ] ] ],
347 "MultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
348 [ "GLint *", "v" ] ] ],
349 "MultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
353 [ "GLshort", "q" ] ] ],
354 "MultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
355 [ "GLshort *", "v" ] ] ],
356 "MultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
358 [ "GLenum", "type" ],
359 [ "GLsizei", "stride" ],
360 [ "GLvoid *", "pointer" ] ] ],
361 "SelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ] ],
362 "SelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ] ] );
365 while ($line = <REGISTRY>) {
366 if ($line =~ /^\w*\(.*\)/) {
367 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
368 ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
369 # and the argument names
370 @arg_names = split /\s*,\s*/, $args;
374 # - the argument types
375 # - the category the function belongs
381 unless (defined($line)) {
383 } elsif ($line =~ /^\s*$/) {
384 if (($category eq "") || ($ret_type eq "")) {
385 die "Missing 'category' line in function $funcname.\n";
388 } elsif ($line =~ /\t*return\t*(\w*)/) {
389 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
390 $ret_type = $pseudo_to_opengl{$ret_type};
391 unless (defined($ret_type)) {
392 die "Unsupported return type in function $funcname\n";
394 } elsif ($line =~ /^\t*category/) {
395 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
396 } elsif ($line =~ /^\t*param/) {
397 ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
399 unless (defined($name)) {
401 die "Broken spec file line $line in function $funcname\n";
404 if ($ext =~ /array/) {
407 } elsif ($ext =~ /value/) {
408 # And this a 'normal' value
412 die "Unsupported type : $line in function $funcname\n";
414 # Get the 'real' type and append a '*' in case of a pointer
415 $type = $pseudo_to_opengl{$base_type};
416 unless (defined($type)) {
418 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
424 $arg_types{$name} = $type;
428 # Now, build the argument reference
430 for ($i = 0; $i <= $#arg_names; $i++) {
431 unless (defined($arg_types{$arg_names[$i]})) {
432 print "@arg_names\n";
433 foreach (sort keys %arg_types) {
434 print "$_ => $arg_types{$_}\n";
436 die "Undefined type for $arg_names[$i] in function $funcname\n";
439 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
441 $func_ref = [ "gl" . $funcname,
445 # Now, put in one or the other hash table
446 if ($norm_categories{$category}) {
447 $norm_functions{$funcname} = $func_ref;
449 $ext_functions{$funcname} = $func_ref;
455 # Clean up the input files
461 # Now, generate the output files. First, the spec file.
463 open(SPEC, ">" . $spec_file);
465 print SPEC "name opengl32
474 debug_channels (opengl)
476 @ stdcall wglCreateContext(long) wglCreateContext
477 @ stdcall wglCreateLayerContext(long long) wglCreateLayerContext
478 @ stdcall wglCopyContext(long long long) wglCopyContext
479 @ stdcall wglDeleteContext(long) wglDeleteContext
480 @ stdcall wglDescribeLayerPlane(long long long long ptr) wglDescribeLayerPlane
481 @ stdcall wglGetCurrentContext() wglGetCurrentContext
482 @ stdcall wglGetCurrentDC() wglGetCurrentDC
483 @ stdcall wglGetLayerPaletteEntries(long long long long ptr) wglGetLayerPaletteEntries
484 @ stdcall wglGetProcAddress(str) wglGetProcAddress
485 @ stdcall wglMakeCurrent(long long) wglMakeCurrent
486 @ stdcall wglRealizeLayerPalette(long long long) wglRealizeLayerPalette
487 @ stdcall wglSetLayerPaletteEntries(long long long long ptr) wglSetLayerPaletteEntries
488 @ stdcall wglShareLists(long long) wglShareLists
489 @ stdcall wglSwapLayerBuffers(long long) wglSwapLayerBuffers
490 @ stdcall wglUseFontBitmapsA(long long long long) wglUseFontBitmapsA
491 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr) wglUseFontOutlinesA
492 @ stub glGetLevelParameterfv
493 @ stub glGetLevelParameteriv
494 @ stub wglUseFontBitmapsW
495 @ stub wglUseFontOutlinesW
496 @ forward wglChoosePixelFormat GDI32.ChoosePixelFormat
497 @ forward wglDescribePixelFormat GDI32.DescribePixelFormat
498 @ forward wglGetPixelFormat GDI32.GetPixelFormat
499 @ forward wglSetPixelFormat GDI32.SetPixelFormat
500 @ forward wglSwapBuffers GDI32.SwapBuffers
503 foreach (sort keys %norm_functions) {
504 $func_name = $norm_functions{$_}->[0];
505 print SPEC "@ stdcall $func_name( ";
506 for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
507 $type = $norm_functions{$_}->[2]->[$i]->[0];
510 } elsif (defined($arg_conv{$type})) {
511 print SPEC "$@$arg_conv{$type}[0] ";
513 die "No convertion for GL type $type...\n";
516 print SPEC ") wine_$func_name\n";
521 # After the spec file, the opengl_norm.c file
523 open(NORM, ">" . $norm_file);
525 /* Auto-generated file... Do not edit ! */
527 #include \"config.h\"
528 #include \"wine_gl.h\"
529 #include \"debugtools.h\"
531 typedef const GLubyte * GLstring;
533 DEFAULT_DEBUG_CHANNEL(opengl);
536 foreach (sort keys %norm_functions) {
537 $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
539 print NORM "$string\n";
544 # Finally, more complex, the opengl_ext.c file
546 open(EXT, ">" . $ext_file);
548 /* Auto-generated file... Do not edit ! */
550 #include \"config.h\"
551 #include \"wine_gl.h\"
552 #include \"debugtools.h\"
554 typedef const GLubyte * GLstring;
556 #include \"opengl_ext.h\"
558 DEFAULT_DEBUG_CHANNEL(opengl);
562 # First, generate the function pointers
563 foreach (sort keys %ext_functions) {
564 $func_ref = $ext_functions{$_};
565 print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
566 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
567 $type = $func_ref->[2]->[$i]->[0];
569 if ($i != $#{@{$func_ref->[2]}}) {
575 print EXT ") = (void *) 0xdeadbeef;\n";
578 # Then, the function prototypes
579 print EXT "\n\n/* The function prototypes */\n";
580 foreach (sort keys %ext_functions) {
581 $func_ref = $ext_functions{$_};
582 print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
583 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
584 $type = $func_ref->[2]->[$i]->[0];
586 if ($i != $#{@{$func_ref->[2]}}) {
595 # Then the table giving the string <-> function correspondance */
596 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
597 @tmp = keys %ext_functions;
598 print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
599 print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
601 foreach (sort keys %ext_functions) {
602 $func_ref = $ext_functions{$_};
603 print EXT " { \"" . $func_ref->[0] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
612 # And, finally, the thunks themselves....
613 print EXT "\n/* The thunks themselves....*/\n";
614 foreach (sort keys %ext_functions) {
615 $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
617 print EXT "$string\n";