make_opengl 23.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/perl -w

# This script is called thus :
#
#   make_opengl path_to_spec_file opengl_version
#
#     - path_to_spec_file is the path to the directory where the OpenGL
#       spec files are located. These files are part of the OpenGL
#       sample implementation CVS tree and are located in
#       CVS_ROOT/projects/ogl-sample/main/doc/registry/specs.
11 12
#       You can find them on the web at the following URL :
#         http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/doc/registry/specs/
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#
#     - opengl_version is the OpenGL version emulated by the library
#       (can be 1.0 to 1.2).
#
# This script generates the three following files :
#
#     - opengl32.spec : the spec file giving all the exported functions
#       of the OpenGL32.DLL library. These functions are the one an
#       application can directly link to (and are all the functions
#       defined in the OpenGL core for the version defined by
#       'opengl_version').
#
#     - opengl_norm.c : this file contains the thunks for all OpenGL
#       functions that are defined in 'opengl32.spec'. The corresponding
#       functions NEED to be defined in Linux's libGL or the library
#       won't be able to be linked in.
#
#     - opengl_ext.c : in this file are stored thunks for ALL possible
#       OpenGL extensions (at least, all the extensions that are defined
#       in the OpenGL extension registry). Contrary to 'opengl_norm.c',
#       you do not need to have these extensions in your libGL to have
#       OpenGL work (as they are resolved at run-time using
#       glXGetProcAddressARB).
#
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# Copyright 2000 Lionel Ulmer
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#
# Files to generate
#
$spec_file = "opengl32.spec";
$norm_file = "opengl_norm.c";
$ext_file  = "opengl_ext.c";

# Set to 0 for removing the ENTER / LEAVE GL calls
$gen_thread_safe = 1;
# Prefix used for the local variables
$ext_prefix = "func_";
# If set to 1, generate TRACEs for each OpenGL function
$gen_traces = 1;

#
# List of categories to put in the 'opengl_norm.c' file
#
71 72 73 74 75 76 77 78 79 80
%cat_1_0 = ( "display-list" => 1,
	     "drawing" => 1,
	     "drawing-control" => 1,
	     "feedback" => 1,
	     "framebuf" => 1,
	     "misc" => 1,
	     "modeling" => 1,
	     "pixel-op" => 1,
	     "pixel-rw" => 1,
	     "state-req" => 1,
81
	     "xform" => 1 );
82
%cat_1_1 = ( %cat_1_0,
83
	     "1_1" => 1 );
84
%cat_1_2 = ( %cat_1_1,
85
	     "VERSION_1_2" => 1 );
86 87 88 89 90 91 92

%norm_categories = ();

#
# This hash table gives the conversion between OpenGL types and what
# is used by the TRACE printfs
#
93
%debug_conv =
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    ("GLbitfield" => "%d",
     "GLboolean" => "%d",
     "GLbyte" => "%d",
     "GLclampd" => "%f",
     "GLclampf" => "%f",
     "GLdouble" => "%f",
     "GLenum" => "%d",
     "GLfloat" => "%f",
     "GLint" => "%d",
     "GLshort" => "%d",
     "GLsizei" => "%d",
     "GLstring" => "%s",
     "GLubyte" => "%d",
     "GLuint" => "%d",
     "GLushort" => "%d",
109 110 111
     "GLhalfNV" => "%d",
     "GLintptrARB" => "%d",
     "GLsizeiptrARB" => "%d",
112 113 114 115 116 117 118
     "GLvoid" => "(void)",
     "_GLfuncptr" => "%p");

#
# This hash table gives the conversion between OpenGL types and what
# is used in the .spec file
#
119
%arg_conv =
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    ("GLbitfield" => [ "long", 4 ],
     "GLboolean" => [ "long", 4 ],
     "GLbyte" => [ "long", 4 ],
     "GLclampd" => [ "double", 8 ],
     "GLclampf" => [ "long", 4 ],
     "GLdouble" => [ "double", 8 ],
     "GLenum" => [ "long", 4 ],
     "GLfloat" => [ "long", 4 ],
     "GLint" => [ "long", 4 ],
     "GLshort" => [ "long", 4 ],
     "GLsizei" => [ "long", 4 ],
     "GLstring" => [ "str", 4 ],
     "GLubyte" => [ "long", 4 ],
     "GLuint" => [ "long", 4 ],
     "GLushort" => [ "long", 4 ],
135 136 137
     "GLhalfNV" => [ "long", 4 ],
     "GLintptrARB" => [ "long", 4 ],
     "GLsizeiptrARB" => [ "long", 4 ],
138 139 140
     "GLvoid" => [ "void", 4 ],
     "_GLfuncptr" => [ "ptr", 4 ]);

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
#
# Used to convert some types
#
sub ConvertType {
    my ($type) = @_;

    %hash = ( "GLstring" => "const GLubyte *",
	      "GLintptrARB" => "ptrdiff_t",
	      "GLsizeiptrARB" => "ptrdiff_t",
	      "GLhalfNV" => "unsigned short" );

    foreach $org (keys %hash) {
	if ($type =~ /$org/) {
	    ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
	    return "$before$hash{$org}$after";
	}
    }
    return $type;
}

161 162 163 164 165 166 167
#
# This functions generates the thunk for a given function.
#
sub GenerateThunk {
    my ($func_ref, $comment, $prefix, $thread_safe) = @_;
    my ($ret) = ("");
    my ($call_arg) = ("");
168
    my ($trace_arg) = ("");
169 170

    # If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
171
    # Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
172 173
    if ($comment eq 1) {
	$ret = $ret . "/***********************************************************************\n";
174
	$ret = $ret . " *              " . $func_ref->[0] . " (OPENGL32.@)\n";
175 176
	$ret = $ret . " */\n";
    }
177
    $ret = $ret . ConvertType($func_ref->[1]) . " WINAPI wine_" . $func_ref->[0] . "( ";
178 179 180
    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
	$type = $func_ref->[2]->[$i]->[0];
	$name = $func_ref->[2]->[$i]->[1];
181
	$ret = $ret . ConvertType($type) . " $name";
182
	$call_arg = $call_arg . "$name";
183 184 185 186 187
	if ($type =~ /\*/) {
	    $trace_arg = $trace_arg . "%p";
	} else {
	    $trace_arg = $trace_arg . $debug_conv{$type};
	}
188 189 190
	if ($i != $#{@{$func_ref->[2]}}) {
	    $ret = $ret . ", ";
	    $call_arg = $call_arg . ", ";
191
	    $trace_arg = $trace_arg . ", ";
192 193 194 195 196 197 198
	} else {
	    $ret = $ret . " ";
	    $call_arg = $call_arg . " ";
	}
    }
    $ret = $ret . ") {\n";
    if ($func_ref->[1] ne "void") {
199
	$ret = $ret . "  " . ConvertType($func_ref->[1]) . " ret_value;\n";
200
    }
201 202 203 204 205 206 207
    if ($gen_traces) {
	$ret = $ret . "  TRACE(\"(" . $trace_arg . ")\\n\"";
	if ($trace_arg ne "") {
	    $ret = $ret . ", " . $call_arg;
	}
	$ret = $ret . ");\n";
    }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
    if ($thread_safe) {
	$ret = $ret . "  ENTER_GL();\n";
    }
    $ret = $ret . "  ";
    if ($func_ref->[1] ne "void") {
	$ret = $ret . "ret_value = ";
    }
    $ret = $ret . $prefix . $func_ref->[0] . "( " . $call_arg . ");\n";
    if ($thread_safe) {
	$ret = $ret . "  LEAVE_GL();\n";
    }
    if ($func_ref->[1] ne "void") {
	$ret = $ret . "  return ret_value;\n"
    }
    $ret = $ret . "}\n";

    # Return this string....
    $ret;
}

#
# Extract and checks the number of arguments
#
if ($#ARGV != 1) {
    die "Usage : make_opengl OpenGL_registry_location OpenGL_version.\n";
}
$registry_path = shift @ARGV;
$version       = shift @ARGV;
if ($version eq "1.0") {
    %norm_categories = %cat_1_0;
} elsif ($version eq "1.1") {
    %norm_categories = %cat_1_1;
} elsif ($version eq "1.2") {
    %norm_categories = %cat_1_2;
} else {
    die "OpenGL version incorrect. Should be one of '1.0', '1.1' or '1.2'.\n";
}

#
# Open the registry files
#
open(TYPES,    $registry_path . "/gl.tm")   || die "Could not open 'gl.tm'. Please check your path the the registry files.\n";
open(REGISTRY, $registry_path . "/gl.spec") || die "Could not open 'gl.spec'. Please check your path the the registry files.\n";

#
# First, create a mapping between the pseudo types used in the spec file
# and OpenGL types using the 'gl.tm' file.
#
%pseudo_to_opengl = ();
while ($line = <TYPES>) {
258 259 260 261
    if ($line !~ /\w*\#/) {
	($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
	$pseudo_to_opengl{$pseudo} = $opengl;
    }
262 263 264
}
# This is to override the 'void' -> '*' bogus conversion
$pseudo_to_opengl{"void"} = "void";
265 266 267 268 269
# This is a bug in the spec file...
$pseudo_to_opengl{"FfdTargetSGIX"} = "GLint";
$pseudo_to_opengl{"FfdMaskSGIX"} = "GLint";
$pseudo_to_opengl{"IglooFunctionSelectSGIX"} = "GLint";
$pseudo_to_opengl{"IglooParameterSGIX"} = "GLint";
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

#
# Then, create the list of all OpenGL functions using the 'gl.spec'
# file. This will create two hash-tables, one with all the function
# whose category matches the one listed in '@norm_categories', the other
# with all other functions.
#
# An element of the hash table is a reference to an array with these
# elements :
#
#  - function name
#
#  - return type
#
#  - reference to an array giving the list of arguments (an empty array
#    for a 'void' function).
#
# The list of arguments is itself an array of reference to arrays. Each
# of these arrays represents the argument type and the argument name.
#
# An example :
#
# void glBitmap( GLsizei width, GLsizei height,
#                GLfloat xorig, GLfloat yorig,
#                GLfloat xmove, GLfloat ymove,
#                const GLubyte *bitmap );
#
# Would give something like that :
#
# [ "glBitmap",
#   "void",
#   [ [ "GLsizei", "width" ],
#     [ "GLsizei", "height" ],
#     [ "GLfloat", "xorig" ],
#     [ "GLfloat", "yorig" ],
#     [ "GLfloat", "xmove" ],
#     [ "GLfloat", "ymove" ],
#     [ "GLubyte *", "bitmap"] ] ];
#
%norm_functions = ();
310 311 312 313 314

#
# This stores various extensions NOT part of the GL extension registry but still
# implemented by most OpenGL libraries out there...
#
315
%ext_functions  =
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    ( "glDeleteBufferRegion" => [ "glDeleteBufferRegion", "void", [ [ "GLenum", "region" ] ], "glDeleteBufferRegion" ],
      "glReadBufferRegion" => [ "glReadBufferRegion", "void", [ [ "GLenum", "region" ],
								[ "GLint", "x" ],
								[ "GLint", "y" ],
								[ "GLsizei", "width" ],
								[ "GLsizei", "height" ] ], "glReadBufferRegion" ],
      "glDrawBufferRegion" => [ "glDrawBufferRegion", "void", [ [ "GLenum", "region" ],
								[ "GLint", "x" ],
								[ "GLint", "y" ],
								[ "GLsizei", "width" ],
								[ "GLsizei", "height" ],
								[ "GLint", "xDest" ],
								[ "GLint", "yDest" ] ], "glDrawBufferRegion" ],
      "glBufferRegionEnabled" => [ "glBufferRegionEnabled", "GLuint", [ ], "glBufferRegionEnabled" ],
      "glNewBufferRegion" => [ "glNewBufferRegion", "GLuint", [ [ "GLenum", "type" ] ], "glNewBufferRegion" ],
      "glMTexCoord2fSGIS" => [ "glMTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
332 333
							      [ "GLfloat", "s" ],
							      [ "GLfloat", "t" ] ], "glMTexCoord2fSGIS" ],
334
      "glMTexCoord2fvSGIS" => [ "glMTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
335
								[ "GLfloat *", "v" ] ], "glMTexCoord2fvSGIS" ],
336
      "glMultiTexCoord1dSGIS" => [ "glMultiTexCoord1dSGIS", "void", [ [ "GLenum", "target" ],
337
								      [ "GLdouble", "s" ] ],  "glMultiTexCoord1dSGIS" ],
338
      "glMultiTexCoord1dvSGIS" => [ "glMultiTexCoord1dvSGIS", "void", [ [ "GLenum", "target" ],
339
									[ "GLdouble *", "v" ] ], "glMultiTexCoord1dvSGIS" ],
340
      "glMultiTexCoord1fSGIS" => [ "glMultiTexCoord1fSGIS", "void", [ [ "GLenum", "target" ],
341
								      [ "GLfloat", "s" ] ], "glMultiTexCoord1fSGIS" ],
342
      "glMultiTexCoord1fvSGIS" => [ "glMultiTexCoord1fvSGIS", "void", [ [ "GLenum", "target" ],
343
									[ "const GLfloat *", "v" ] ], "glMultiTexCoord1fvSGIS" ],
344
      "glMultiTexCoord1iSGIS" => [ "glMultiTexCoord1iSGIS", "void", [ [ "GLenum", "target" ],
345
								      [ "GLint", "s" ] ], "glMultiTexCoord1iSGIS" ],
346
      "glMultiTexCoord1ivSGIS" => [ "glMultiTexCoord1ivSGIS", "void", [ [ "GLenum", "target" ],
347
									[ "GLint *", "v" ] ], "glMultiTexCoord1ivSGIS" ],
348
      "glMultiTexCoord1sSGIS" => [ "glMultiTexCoord1sSGIS", "void", [ [ "GLenum", "target" ],
349
								      [ "GLshort", "s" ] ], "glMultiTexCoord1sSGIS" ],
350
      "glMultiTexCoord1svSGIS" => [ "glMultiTexCoord1svSGIS", "void", [ [ "GLenum", "target" ],
351
									[ "GLshort *", "v" ] ], "glMultiTexCoord1svSGIS" ],
352 353
      "glMultiTexCoord2dSGIS" => [ "glMultiTexCoord2dSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLdouble", "s"],
354
								      [ "GLdouble", "t" ] ], "glMultiTexCoord2dSGIS" ],
355
      "glMultiTexCoord2dvSGIS" => [ "glMultiTexCoord2dvSGIS", "void", [ [ "GLenum", "target" ],
356
									[ "GLdouble *", "v" ] ], "glMultiTexCoord2dvSGIS" ],
357 358
      "glMultiTexCoord2fSGIS" => [ "glMultiTexCoord2fSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLfloat", "s" ],
359
								      [ "GLfloat", "t" ] ], "glMultiTexCoord2fSGIS" ],
360
      "glMultiTexCoord2fvSGIS" => [ "glMultiTexCoord2fvSGIS", "void", [ [ "GLenum", "target" ],
361
									[ "GLfloat *", "v" ] ], "glMultiTexCoord2fvSGIS" ],
362 363
      "glMultiTexCoord2iSGIS" => [ "glMultiTexCoord2iSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLint", "s" ],
364
								      [ "GLint", "t" ] ], "glMultiTexCoord2iSGIS" ],
365
      "glMultiTexCoord2ivSGIS" => [ "glMultiTexCoord2ivSGIS", "void", [ [ "GLenum", "target" ],
366
									[ "GLint *", "v" ] ], "glMultiTexCoord2ivSGIS" ],
367 368
      "glMultiTexCoord2sSGIS" => [ "glMultiTexCoord2sSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLshort", "s" ],
369
								      [ "GLshort", "t" ] ], "glMultiTexCoord2sSGIS" ],
370
      "glMultiTexCoord2svSGIS" => [ "glMultiTexCoord2svSGIS", "void", [ [ "GLenum", "target" ],
371
									[ "GLshort *", "v" ] ], "glMultiTexCoord2svSGIS" ],
372 373 374
      "glMultiTexCoord3dSGIS" => [ "glMultiTexCoord3dSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLdouble", "s" ],
								      [ "GLdouble", "t" ],
375 376 377
								      [ "GLdouble", "r" ] ], "glMultiTexCoord3dSGIS" ],
      "glMultiTexCoord3dvSGIS" => [ "glMultiTexCoord3dvSGIS", "void", [ [ "GLenum", "target" ],
									[ "GLdouble *", "v" ] ], "glMultiTexCoord3dvSGIS" ],
378 379 380
      "glMultiTexCoord3fSGIS" => [ "glMultiTexCoord3fSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLfloat", "s" ],
								      [ "GLfloat", "t" ],
381
								      [ "GLfloat", "r" ] ], "glMultiTexCoord3fSGIS" ],
382
      "glMultiTexCoord3fvSGIS" => [ "glMultiTexCoord3fvSGIS", "void", [ [ "GLenum", "target" ],
383
									[ "GLfloat *", "v" ] ], "glMultiTexCoord3fvSGIS" ],
384 385 386
      "glMultiTexCoord3iSGIS" => [ "glMultiTexCoord3iSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLint", "s" ],
								      [ "GLint", "t" ],
387
								      [ "GLint", "r" ] ], "glMultiTexCoord3iSGIS" ],
388
      "glMultiTexCoord3ivSGIS" => [ "glMultiTexCoord3ivSGIS", "void", [ [ "GLenum", "target" ],
389
									[ "GLint *", "v" ] ], "glMultiTexCoord3ivSGIS" ],
390 391 392
      "glMultiTexCoord3sSGIS" => [ "glMultiTexCoord3sSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLshort", "s" ],
								      [ "GLshort", "t" ],
393
								      [ "GLshort", "r" ] ], "glMultiTexCoord3sSGIS" ],
394
      "glMultiTexCoord3svSGIS" => [ "glMultiTexCoord3svSGIS", "void", [ [ "GLenum", "target" ],
395
									[ "GLshort *", "v" ] ], "glMultiTexCoord3svSGIS" ],
396 397 398 399
      "glMultiTexCoord4dSGIS" => [ "glMultiTexCoord4dSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLdouble", "s" ],
								      [ "GLdouble", "t" ],
								      [ "GLdouble", "r" ],
400
								      [ "GLdouble", "q" ] ], "glMultiTexCoord4dSGIS" ],
401
      "glMultiTexCoord4dvSGIS" => [ "glMultiTexCoord4dvSGIS", "void", [ [ "GLenum", "target" ],
402
									[ "GLdouble *", "v" ] ], "glMultiTexCoord4dvSGIS" ],
403 404 405 406
      "glMultiTexCoord4fSGIS" => [ "glMultiTexCoord4fSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLfloat", "s" ],
								      [ "GLfloat", "t" ],
								      [ "GLfloat", "r" ],
407
								      [ "GLfloat", "q" ] ], "glMultiTexCoord4fSGIS" ],
408
      "glMultiTexCoord4fvSGIS" => [ "glMultiTexCoord4fvSGIS", "void", [ [ "GLenum", "target" ],
409
									[ "GLfloat *", "v" ] ], "glMultiTexCoord4fvSGIS" ],
410 411 412 413
      "glMultiTexCoord4iSGIS" => [ "glMultiTexCoord4iSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLint", "s" ],
								      [ "GLint", "t" ],
								      [ "GLint", "r" ],
414
								      [ "GLint", "q" ] ], "glMultiTexCoord4iSGIS" ],
415
      "glMultiTexCoord4ivSGIS" => [ "glMultiTexCoord4ivSGIS", "void", [ [ "GLenum", "target" ],
416
									[ "GLint *", "v" ] ], "glMultiTexCoord4ivSGIS" ],
417 418 419 420
      "glMultiTexCoord4sSGIS" => [ "glMultiTexCoord4sSGIS", "void", [ [ "GLenum", "target" ],
								      [ "GLshort", "s" ],
								      [ "GLshort", "t" ],
								      [ "GLshort", "r" ],
421
								      [ "GLshort", "q" ] ], "glMultiTexCoord4sSGIS" ],
422
      "glMultiTexCoord4svSGIS" => [ "glMultiTexCoord4svSGIS", "void", [ [ "GLenum", "target" ],
423
									[ "GLshort *", "v" ] ], "glMultiTexCoord4svSGIS" ],
424 425
      "glMultiTexCoordPointerSGIS" => [ "glMultiTexCoordPointerSGIS", "void", [ [ "GLenum", "target" ],
										[ "GLint", "size" ],
426
										[ "GLenum", "type" ],
427
										[ "GLsizei", "stride" ],
428 429 430 431 432
										[ "GLvoid *", "pointer" ] ], "glMultiTexCoordPointerSGIS" ],
      "glSelectTextureSGIS" => [ "glSelectTextureSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureSGIS" ],
      "glSelectTextureCoordSetSGIS" => [ "glSelectTextureCoordSetSGIS", "void", [ [ "GLenum", "target" ] ], "glSelectTextureCoordSetSGIS" ],
      "wglAllocateMemoryNV" => [ "wglAllocateMemoryNV", "void *", [ [ "GLsizei", "size" ],
								    [ "GLfloat", "readfreq" ],
433
								    [ "GLfloat", "writefreq"],
434 435 436
								    [ "GLfloat", "priority" ] ], "glXAllocateMemoryNV" ],
      "wglFreeMemoryNV" => [ "wglFreeMemoryNV", "void", [ [ "GLvoid *", "pointer" ] ], "glXFreeMemoryNV" ]
      );
437

438 439 440 441 442 443 444

while ($line = <REGISTRY>) {
    if ($line =~ /^\w*\(.*\)/) {
	# Get the function name (NOTE: the 'gl' prefix needs to be added later)
	($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
	# and the argument names
	@arg_names = split /\s*,\s*/, $args;
445

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
	# After get :
	#  - the return type
	#  - the argument types
	#  - the category the function belongs
	%arg_types = ();
	$category = "";
	$ret_type = "";
	while (1) {
	    $line = <REGISTRY>;
	    unless (defined($line)) {
		last;
	    } elsif ($line =~ /^\s*$/) {
		if (($category eq "") || ($ret_type eq "")) {
		    die "Missing 'category' line in function $funcname.\n";
		}
		last;
	    } elsif ($line =~ /\t*return\t*(\w*)/) {
		($ret_type) = ($line =~ /\t*return\s*(\w*)/);
		$ret_type = $pseudo_to_opengl{$ret_type};
		unless (defined($ret_type)) {
		    die "Unsupported return type in function $funcname\n";
		}
	    } elsif ($line =~ /^\t*category/) {
		($category) = ($line =~ /^\t*category\s*([\w-]*)/);
	    } elsif ($line =~ /^\t*param/) {
		($name, $base_type, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (.*)/);
		$ptr = 0;
473
		unless (defined($name)) {
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
		    chomp $line;
		    die "Broken spec file line $line in function $funcname\n";
		}

		if ($ext =~ /array/) {
		    # This is a pointer
		    $ptr = 1;
		} elsif ($ext =~ /value/) {
		    # And this a 'normal' value
		    $ptr = 0;
		} else {
		    chomp $line;
		    die "Unsupported type : $line in function $funcname\n";
		}
		# Get the 'real' type and append a '*' in case of a pointer
		$type = $pseudo_to_opengl{$base_type};
		unless (defined($type)) {
		    chomp $line;
		    die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
		}
		if ($ptr) {
		    $type = $type . "*";
		}
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511
		$arg_types{$name} = $type;
	    }
	}

	# Now, build the argument reference
	$arg_ref = [ ];
	for ($i = 0; $i <= $#arg_names; $i++) {
	    unless (defined($arg_types{$arg_names[$i]})) {
		print "@arg_names\n";
		foreach (sort keys %arg_types) {
		    print "$_ => $arg_types{$_}\n";
		}
		die "Undefined type for $arg_names[$i] in function $funcname\n";
	    }
512

513 514
	    push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
	}
515
	$func_ref = [ "gl" . $funcname,
516
		      $ret_type,
517 518
		      $arg_ref,
		      "gl" . $funcname ];
519

520 521
	# Now, put in one or the other hash table
	if ($norm_categories{$category}) {
522
	    $norm_functions{"gl" . $funcname} = $func_ref;
523
	} else {
524
	    $ext_functions{"gl" . $funcname} = $func_ref;
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
	}
    }
}

#
# Clean up the input files
#
close(TYPES);
close(REGISTRY);

#
# Now, generate the output files. First, the spec file.
#
open(SPEC, ">" . $spec_file);

540 541 542 543 544 545 546 547
print SPEC "@  stdcall wglCreateContext(long)
@  stdcall wglCreateLayerContext(long long)
@  stdcall wglCopyContext(long long long)
@  stdcall wglDeleteContext(long)
@  stdcall wglDescribeLayerPlane(long long long long ptr)
@  stdcall wglGetCurrentContext()
@  stdcall wglGetCurrentDC()
@  stdcall wglGetExtensionsStringEXT()
548
@  stdcall wglGetExtensionsStringARB(long)
549 550 551 552 553 554 555 556 557
@  stdcall wglGetLayerPaletteEntries(long long long long ptr)
@  stdcall wglGetProcAddress(str)
@  stdcall wglMakeCurrent(long long)
@  stdcall wglRealizeLayerPalette(long long long)
@  stdcall wglSetLayerPaletteEntries(long long long long ptr)
@  stdcall wglShareLists(long long)
@  stdcall wglSwapLayerBuffers(long long)
@  stdcall wglUseFontBitmapsA(long long long long)
@  stdcall wglUseFontOutlinesA(long long long long long long long ptr)
558 559 560 561
@  stub    glGetLevelParameterfv
@  stub    glGetLevelParameteriv
@  stub    wglUseFontBitmapsW
@  stub    wglUseFontOutlinesW
562
@  stub    wglGetDefaultProcAddress
563 564 565 566 567
@  stdcall wglChoosePixelFormat(long ptr) gdi32.ChoosePixelFormat
@  stdcall wglDescribePixelFormat(long long long ptr) gdi32.DescribePixelFormat
@  stdcall wglGetPixelFormat(long) gdi32.GetPixelFormat
@  stdcall wglSetPixelFormat(long long ptr) gdi32.SetPixelFormat
@  stdcall wglSwapBuffers(long) gdi32.SwapBuffers
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
";

foreach (sort keys %norm_functions) {
    $func_name = $norm_functions{$_}->[0];
    print SPEC "@  stdcall $func_name( ";
    for ($i = 0; $i <= $#{@{$norm_functions{$_}->[2]}}; $i++) {
	$type = $norm_functions{$_}->[2]->[$i]->[0];
	if ($type =~ /\*/) {
	    print SPEC "ptr ";
	} elsif (defined($arg_conv{$type})) {
	    print SPEC "$@$arg_conv{$type}[0] ";
	} else {
	    die "No convertion for GL type $type...\n";
	}
    }
    print SPEC ") wine_$func_name\n";
}
close(SPEC);

#
# After the spec file, the opengl_norm.c file
#
open(NORM, ">" . $norm_file);
print NORM "
/* Auto-generated file... Do not edit ! */

#include \"config.h\"
595
#include \"opengl_ext.h\"
596
#include \"wine/debug.h\"
597

598
WINE_DEFAULT_DEBUG_CHANNEL(opengl);
599 600 601 602
";
foreach (sort keys %norm_functions) {
    $string = GenerateThunk($norm_functions{$_}, 1, "", $gen_thread_safe);

603
    print NORM "\n$string";
604 605 606 607 608 609 610 611 612 613 614
}
close(NORM);

#
# Finally, more complex, the opengl_ext.c file
#
open(EXT, ">" . $ext_file);
print EXT "
/* Auto-generated file... Do not edit ! */

#include \"config.h\"
615
#include \"opengl_ext.h\"
616
#include \"wine/debug.h\"
617

618
WINE_DEFAULT_DEBUG_CHANNEL(opengl);
619

620 621 622 623 624 625 626
";

# First, generate the function pointers
foreach (sort keys %ext_functions) {
    $func_ref = $ext_functions{$_};
    print EXT $func_ref->[1] . " (*" . $ext_prefix . $func_ref->[0] . ")( ";
    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
627
	$type = ConvertType($func_ref->[2]->[$i]->[0]);
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
	print EXT "$type";
	if ($i != $#{@{$func_ref->[2]}}) {
	    print EXT ", ";
	} else {
	    print EXT " ";
	}
    }
    print EXT ") = (void *) 0xdeadbeef;\n";
}

# Then, the function prototypes
print EXT "\n\n/* The function prototypes */\n";
foreach (sort keys %ext_functions) {
    $func_ref = $ext_functions{$_};
    print EXT $func_ref->[1] . " WINAPI " . "wine_" . $func_ref->[0] . "( ";
    for ($i = 0; $i <= $#{@{$func_ref->[2]}}; $i++) {
644
	$type = ConvertType($func_ref->[2]->[$i]->[0]);
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
	print EXT "$type";
	if ($i != $#{@{$func_ref->[2]}}) {
	    print EXT ", ";
	} else {
	    print EXT " ";
	}
    }
    print EXT ");\n";
}

# Then the table giving the string <-> function correspondance */
print EXT "\n\n/* The table giving the correspondance between names and functions */\n";
@tmp = keys %ext_functions;
print EXT "int extension_registry_size = " . ($#tmp + 1) . ";\n";
print EXT "OpenGL_extension extension_registry[" . ($#tmp + 1) . "] = {\n";
$i = 0;
foreach (sort keys %ext_functions) {
    $func_ref = $ext_functions{$_};
663
    print EXT "  { \"" . $func_ref->[0] . "\", \"" . $func_ref->[3] . "\", (void *) wine_" . $func_ref->[0] . ", (void **) (&" . $ext_prefix . $func_ref->[0] . ") }";
664 665 666 667 668 669 670 671 672
    if ($i != $#tmp) {
	print EXT ",";
    }
    $i++;
    print EXT "\n";
}
print EXT "};\n";

# And, finally, the thunks themselves....
673
print EXT "\n/* The thunks themselves....*/";
674 675 676
foreach (sort keys %ext_functions) {
    $string = GenerateThunk($ext_functions{$_}, 0, $ext_prefix, $gen_thread_safe);

677
    print EXT "\n$string";
678 679
}
close(EXT);