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 ( "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
269 [ "GLdouble", "s" ] ], "glMultiTexCoord1dSGIS" ],
270 "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
271 [ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
272 "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
273 [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
274 "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
275 [ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
276 "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
277 [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
278 "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
279 [ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
280 "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
281 [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
282 "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
283 [ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
284 "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
286 [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
287 "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
288 [ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
289 "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
291 [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
292 "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
293 [ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
294 "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
296 [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
297 "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
298 [ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
299 "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
301 [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
302 "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
303 [ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
304 "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
307 [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
308 "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
309 [ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
310 "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
313 [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
314 "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
315 [ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
316 "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
319 [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
320 "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
321 [ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
322 "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
325 [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
326 "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
327 [ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
328 "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
332 [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
333 "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
334 [ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
335 "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
339 [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
340 "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
341 [ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
342 "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
346 [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
347 "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
348 [ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
349 "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
353 [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
354 "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
355 [ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
356 "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
358 [ "GLenum", "type" ],
359 [ "GLsizei", "stride" ],
360 [ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
361 "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
362 "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
363 "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
364 [ "GLfloat", "readfreq" ],
365 [ "GLfloat", "writefreq"],
366 [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
367 "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ]
371 while ($line = <REGISTRY>) {
372 if ($line =~ /^\w*\(.*\)/) {
373 # Get the function name (NOTE: the 'gl' prefix needs to be added later)
374 ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
375 # and the argument names
376 @arg_names = split /\s*,\s*/, $args;
380 # - the argument types
381 # - the category the function belongs
387 unless (defined($line)) {
389 } elsif ($line =~ /^\s*$/) {
390 if (($category eq "") || ($ret_type eq "")) {
391 die "Missing 'category' line in function $funcname.\n";
394 } elsif ($line =~ /\t*return\t*(\w*)/) {
395 ($ret_type) = ($line =~ /\t*return\s*(\w*)/);
396 $ret_type = $pseudo_to_opengl{$ret_type};
397 unless (defined($ret_type)) {
398 die "Unsupported return type in function $funcname\n";
400 } elsif ($line =~ /^\t*category/) {
401 ($category) = ($line =~ /^\t*category\s*([\w-]*)/);
402 } elsif ($line =~ /^\t*param/) {
403 ($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
405 unless (defined($name)) {
407 die "Broken spec file line $line in function $funcname\n";
410 if ($ext =~ /array/) {
413 } elsif ($ext =~ /value/) {
414 # And this a 'normal' value
418 die "Unsupported type : $line in function $funcname\n";
420 # Get the 'real' type and append a '*' in case of a pointer
421 $type = $pseudo_to_opengl{$base_type};
422 unless (defined($type)) {
424 die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
430 $arg_types{$name} = $type;
434 # Now, build the argument reference
436 for ($i = 0; $i <= $#arg_names; $i++) {
437 unless (defined($arg_types{$arg_names[$i]})) {
438 print "@arg_names\n";
439 foreach (sort keys %arg_types) {
440 print "$_ => $arg_types{$_}\n";
442 die "Undefined type for $arg_names[$i] in function $funcname\n";
445 push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
447 $func_ref = [ "gl" . $funcname,
452 # Now, put in one or the other hash table
453 if ($norm_categories{$category}) {
454 $norm_functions{"gl" . $funcname} = $func_ref;
456 $ext_functions{"gl" . $funcname} = $func_ref;
462 # Clean up the input files
468 # Now, generate the output files. First, the spec file.
470 open(SPEC, ">" . $spec_file);
472 print SPEC "name opengl32
481 debug_channels (opengl)
483 @ stdcall wglCreateContext(long) wglCreateContext
484 @ stdcall wglCreateLayerContext(long long) wglCreateLayerContext
485 @ stdcall wglCopyContext(long long long) wglCopyContext
486 @ stdcall wglDeleteContext(long) wglDeleteContext
487 @ stdcall wglDescribeLayerPlane(long long long long ptr) wglDescribeLayerPlane
488 @ stdcall wglGetCurrentContext() wglGetCurrentContext
489 @ stdcall wglGetCurrentDC() wglGetCurrentDC
490 @ stdcall wglGetLayerPaletteEntries(long long long long ptr) wglGetLayerPaletteEntries
491 @ stdcall wglGetProcAddress(str) wglGetProcAddress
492 @ stdcall wglMakeCurrent(long long) wglMakeCurrent
493 @ stdcall wglRealizeLayerPalette(long long long) wglRealizeLayerPalette
494 @ stdcall wglSetLayerPaletteEntries(long long long long ptr) wglSetLayerPaletteEntries
495 @ stdcall wglShareLists(long long) wglShareLists
496 @ stdcall wglSwapLayerBuffers(long long) wglSwapLayerBuffers
497 @ stdcall wglUseFontBitmapsA(long long long long) wglUseFontBitmapsA
498 @ stdcall wglUseFontOutlinesA(long long long long long long long ptr) wglUseFontOutlinesA
499 @ stub glGetLevelParameterfv
500 @ stub glGetLevelParameteriv
501 @ stub wglUseFontBitmapsW
502 @ stub wglUseFontOutlinesW
503 @ forward wglChoosePixelFormat GDI32.ChoosePixelFormat
504 @ forward wglDescribePixelFormat GDI32.DescribePixelFormat
505 @ forward wglGetPixelFormat GDI32.GetPixelFormat
506 @ forward wglSetPixelFormat GDI32.SetPixelFormat
507 @ forward wglSwapBuffers GDI32.SwapBuffers
510 foreach (sort keys %norm_functions) {
511 $func_name = $norm_functions{$_}->[0];
512 print SPEC "@ stdcall $func_name( ";
513 for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
514 $type = $norm_functions{$_}->[2]->[$i]->[0];
517 } elsif (defined($arg_conv{$type})) {
518 print SPEC "$@$arg_conv{$type}[0] ";
520 die "No convertion for GL type $type...\n";
523 print SPEC ") wine_$func_name\n";
528 # After the spec file, the opengl_norm.c file
530 open(NORM, ">" . $norm_file);
532 /* Auto-generated file... Do not edit ! */
534 #include \"config.h\"
535 #include \"wine_gl.h\"
536 #include \"debugtools.h\"
538 typedef const GLubyte * GLstring;
540 DEFAULT_DEBUG_CHANNEL(opengl);
543 foreach (sort keys %norm_functions) {
544 $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);
546 print NORM "$string\n";
551 # Finally, more complex, the opengl_ext.c file
553 open(EXT, ">" . $ext_file);
555 /* Auto-generated file... Do not edit ! */
557 #include \"config.h\"
558 #include \"wine_gl.h\"
559 #include \"debugtools.h\"
561 typedef const GLubyte * GLstring;
563 #include \"opengl_ext.h\"
565 DEFAULT_DEBUG_CHANNEL(opengl);
569 # First, generate the function pointers
570 foreach (sort keys %ext_functions) {
571 $func_ref = $ext_functions{$_};
572 print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
573 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
574 $type = $func_ref->[2]->[$i]->[0];
576 if ($i != $#{@{$func_ref->[2]}}) {
582 print EXT ") = (void *) 0xdeadbeef;\n";
585 # Then, the function prototypes
586 print EXT "\n\n/* The function prototypes */\n";
587 foreach (sort keys %ext_functions) {
588 $func_ref = $ext_functions{$_};
589 print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
590 for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
591 $type = $func_ref->[2]->[$i]->[0];
593 if ($i != $#{@{$func_ref->[2]}}) {
602 # Then the table giving the string <-> function correspondance */
603 print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
604 @tmp = keys %ext_functions;
605 print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
606 print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
608 foreach (sort keys %ext_functions) {
609 $func_ref = $ext_functions{$_};
610 print EXT " { \"" . $func_ref->[0] . "\", \"" . $func_ref->[3] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
619 # And, finally, the thunks themselves....
620 print EXT "\n/* The thunks themselves....*/\n";
621 foreach (sort keys %ext_functions) {
622 $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);
624 print EXT "$string\n";