Sweden-Number/dlls/opengl32/make_opengl

1012 lines
35 KiB
Plaintext
Raw Normal View History

2000-06-12 03:21:18 +02:00
#!/usr/bin/perl -w
use strict;
2000-06-12 03:21:18 +02:00
# This script is called thus :
#
# make_opengl [opengl_version]
#
# - It needs files from the OpenGL extension registry:
2000-06-12 03:21:18 +02:00
#
2007-08-17 19:22:12 +02:00
# http://www.opengl.org/registry/api/gl.spec
# http://www.opengl.org/registry/api/gl.tm
# http://www.opengl.org/registry/api/wgl.tm
# http://www.opengl.org/registry/api/wglext.spec
2007-08-17 19:22:12 +02:00
#
# If they are not found in the current directory the script will
# attempt to download them from there.
#
2000-06-12 03:21:18 +02:00
# - opengl_version is the OpenGL version emulated by the library
# (can be 1.0 to 1.5). The default is 1.1.
2000-06-12 03:21:18 +02:00
#
# 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).
#
# - include/wine/wgl_driver.h: definitions for the tables of OpenGL functions.
#
#
# Copyright 2000 Lionel Ulmer
# Copyright 2012 Alexandre Julliard
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
2000-06-12 03:21:18 +02:00
#
# Files to generate
#
my $spec_file = "opengl32.spec";
my $norm_file = "opengl_norm.c";
my $ext_file = "opengl_ext.c";
# Set to 0 for removing the ENTER / LEAVE GL calls
2012-06-26 15:23:05 +02:00
my $gen_thread_safe = 0;
# Prefix used for the local variables
my $ext_prefix = "func_";
# If set to 1, generate TRACEs for each OpenGL function
my $gen_traces = 1;
#
# List of categories to put in the 'opengl_norm.c' file
#
my %cat_1_0 = ( "display-list" => 1,
2002-06-01 04:55:48 +02:00
"drawing" => 1,
"drawing-control" => 1,
"feedback" => 1,
"framebuf" => 1,
"misc" => 1,
"modeling" => 1,
"pixel-op" => 1,
"pixel-rw" => 1,
"state-req" => 1,
"xform" => 1,
"VERSION_1_0" => 1,
"VERSION_1_0_DEPRECATED" => 1 );
my %cat_1_1 = ( %cat_1_0,
"VERSION_1_1" => 1,
"VERSION_1_1_DEPRECATED" => 1 );
my %cat_1_2 = ( %cat_1_1,
"VERSION_1_2" => 1,
"VERSION_1_2_DEPRECATED" => 1 );
my %cat_1_3 = ( %cat_1_2,
"VERSION_1_3" => 1,
"VERSION_1_3_DEPRECATED" => 1 );
my %cat_1_4 = ( %cat_1_3,
"VERSION_1_4" => 1,
"VERSION_1_4_DEPRECATED" => 1 );
my %cat_1_5 = ( %cat_1_4,
"VERSION_1_5" => 1,
"VERSION_1_5_DEPRECATED" => 1 );
my %norm_categories = ();
#
# This hash table gives the conversion between OpenGL types and what
# is used by the TRACE printfs
#
my %debug_conv =
("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",
"GLhalfNV" => "%d",
"GLintptrARB" => "%ld",
"GLsizeiptrARB" => "%ld",
"GLintptr" => "%ld",
"GLsizeiptr" => "%ld",
"GLhandleARB" => "%d",
"GLcharARB" => "%c",
"GLvoid" => "(void)",
"_GLfuncptr" => "%p",
2012-09-07 20:53:06 +02:00
"GLDEBUGPROC" => "%p",
"GLDEBUGPROCARB" => "%p",
"GLDEBUGPROCAMD" => "%p",
"GLvdpauSurfaceNV" => "%ld",
"int" => "%d",
"unsigned int" => "%u",
"UINT" => "%u",
"DWORD" => "%u",
"BOOL" => "%u",
"INT64" => "%s,wine_dbgstr_longlong(%s)",
"UINT64" => "%s,wine_dbgstr_longlong(%s)",
"LPVOID" => "%p",
"HANDLE" => "%p",
"HDC" => "%p",
"HGLRC" => "%p",
"HPBUFFERARB" => "%p",
"HPBUFFEREXT" => "%p",
);
#
# This hash table gives the conversion between OpenGL types and what
# is used in the .spec and header files.
#
my %arg_conv =
("GLbitfield" => [ "long", "unsigned int" ],
"GLboolean" => [ "long", "unsigned char" ],
"GLbyte" => [ "long", "signed char" ],
"GLchar" => [ "long", "char" ],
"GLclampd" => [ "double", "double" ],
"GLclampf" => [ "float", "float" ],
"GLdouble" => [ "double", "double" ],
"GLenum" => [ "long", "unsigned int" ],
"GLfloat" => [ "float", "float" ],
"GLint" => [ "long", "int" ],
"GLint64" => [ "int64", "INT64" ],
"GLintptr" => [ "long", "INT_PTR" ],
"GLshort" => [ "long", "short" ],
"GLsizei" => [ "long", "int" ],
"GLsizeiptr" => [ "long", "INT_PTR" ],
"GLstring" => [ "str", "const unsigned char *" ],
"GLsync" => [ "ptr", "struct __GLsync *" ],
"GLubyte" => [ "long", "unsigned char" ],
"GLuint" => [ "long", "unsigned int" ],
"GLuint64" => [ "int64", "UINT64" ],
"GLushort" => [ "long", "unsigned short" ],
"GLvoid" => [ "void", "void" ],
"GLcharARB" => [ "long", "char" ],
"GLhandleARB" => [ "long", "unsigned int" ],
"GLintptrARB" => [ "long", "INT_PTR" ],
"GLsizeiptrARB" => [ "long", "INT_PTR" ],
"GLhalfNV" => [ "long", "unsigned short" ],
"GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
#
# Used to convert some types
#
sub ConvertType($)
{
my ($type) = @_;
my %hash = (
"struct _cl_context" => "void",
"struct _cl_event" => "void",
"HGLRC" => "struct wgl_context *",
2012-09-07 20:53:06 +02:00
"GLDEBUGPROC" => "void *",
"GLDEBUGPROCARB" => "void *",
"GLDEBUGPROCAMD" => "void *",
"HPBUFFERARB" => "struct wgl_pbuffer *",
"HPBUFFEREXT" => "struct wgl_pbuffer *",
);
foreach my $org (reverse sort keys %hash) {
if ($type =~ /$org/) {
my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
return "$before$hash{$org}$after";
}
}
return $type;
}
#
# Used to convert some variable names
#
sub ConvertVarName($)
{
my ($type) = @_;
my %hash = ( "near" => "nearParam",
"far" => "farParam" );
foreach my $org (keys %hash) {
if ($type =~ /$org/) {
my ($before, $after) = ($type =~ /^(.*)$org(.*)$/);
return "$before$hash{$org}$after";
}
}
return $type;
}
2000-06-12 03:21:18 +02:00
#
# This functions generates the thunk for a given function.
#
sub GenerateThunk($$$$)
{
my ($name, $func_ref, $comment, $prefix) = @_;
my $ret = "";
my $call_arg = "";
my $trace_call_arg = "";
my $trace_arg = "";
return "" if $name eq "glDebugEntry";
return "" if $name eq "glGetString";
return "" if $func_ref->[2] && $func_ref->[2] =~ /WGL_/;
2000-06-12 03:21:18 +02:00
# If for opengl_norm.c, generate a nice heading otherwise Patrik won't be happy :-)
# Patrik says: Well I would be even happier if a (OPENGL32.@) was added as well. Done. :-)
2000-06-12 03:21:18 +02:00
if ($comment eq 1) {
$ret = "$ret/***********************************************************************\n";
$ret = "$ret * $name (OPENGL32.\@)\n";
$ret = "$ret */\n";
2000-06-12 03:21:18 +02:00
}
$ret = $ret . ConvertType($func_ref->[0]) . " WINAPI $name( ";
for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
## Quick debug code :-)
## print $func_ref->[1]->[$i]->[1] . "\n";
my $type = $func_ref->[1]->[$i]->[0];
my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
$ret .= ConvertType($type) . " $name";
$call_arg .= $name;
if ($type =~ /\*/) {
$trace_arg .= "%p";
$trace_call_arg .= $name;
} elsif (defined $debug_conv{$type}) {
if ($debug_conv{$type} =~ /(.*),(.*)/)
{
$trace_arg .= $1;
$trace_call_arg .= sprintf $2, $name;
}
else
{
$trace_arg .= $debug_conv{$type};
$trace_call_arg .= $name;
}
}
else { printf "Unknown type %s\n", $type; }
if ($i+1 < @{$func_ref->[1]}) {
$ret .= ", ";
$call_arg .= ", ";
$trace_call_arg .= ", ";
$trace_arg .= ", ";
2000-06-12 03:21:18 +02:00
} else {
$ret .= " ";
$call_arg .= " ";
$trace_call_arg .= " ";
2000-06-12 03:21:18 +02:00
}
}
$ret .= 'void ' if (!@{$func_ref->[1]});
$ret .= ") {\n";
$ret .= " const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;\n";
if ($func_ref->[0] ne "void" && $gen_thread_safe) {
$ret = "$ret " . ConvertType($func_ref->[0]) . " ret_value;\n";
2000-06-12 03:21:18 +02:00
}
if ($gen_traces) {
$ret = "$ret TRACE(\"($trace_arg)\\n\"";
if ($trace_arg ne "") {
$ret .= ", $trace_call_arg";
}
$ret = "$ret);\n";
}
if ($gen_thread_safe) {
2012-06-26 15:23:05 +02:00
$ret .= " ENTER_GL();\n";
$ret .= " ";
if ($func_ref->[0] ne "void") {
2012-06-26 15:23:05 +02:00
$ret .= "ret_value = ";
}
$ret .= "funcs->$prefix.p_$name( $call_arg);\n";
2012-06-26 15:23:05 +02:00
$ret .= " LEAVE_GL();\n";
if ($func_ref->[0] ne "void") {
2012-06-26 15:23:05 +02:00
$ret .= " return ret_value;\n"
}
2000-06-12 03:21:18 +02:00
}
2012-06-26 15:23:05 +02:00
else {
$ret .= " ";
if ($func_ref->[0] ne "void") {
2012-06-26 15:23:05 +02:00
$ret .= "return ";
}
$ret .= "funcs->$prefix.p_$name( $call_arg);\n";
2000-06-12 03:21:18 +02:00
}
$ret = "$ret}\n";
2000-06-12 03:21:18 +02:00
# Return this string....
return $ret;
2000-06-12 03:21:18 +02:00
}
sub generate_null_func($$)
{
my ($name, $func_ref) = @_;
my $ret;
return "" if $name eq "glDebugEntry";
$ret = "static " . ConvertType($func_ref->[0]) . " null_$name( ";
for (my $i = 0; $i < @{$func_ref->[1]}; $i++) {
my $type = $func_ref->[1]->[$i]->[0];
my $name = ConvertVarName($func_ref->[1]->[$i]->[1]);
$ret .= ConvertType($type) . " $name";
$ret .= "," if ($i+1 < @{$func_ref->[1]});
$ret .= " ";
}
$ret .= 'void ' if (!@{$func_ref->[1]});
$ret .= ") {";
if ($name eq "glGetError")
{
$ret .= " return GL_INVALID_OPERATION;";
}
elsif ($func_ref->[0] ne "void")
{
$ret .= " return 0;";
}
$ret .= " }\n";
return $ret;
}
sub get_func_proto($$$)
{
my ($format, $name, $func) = @_;
my $ret = sprintf "%-10s", ConvertType($func->[0]);
$ret .= " " . sprintf($format,$name) . "(";
for (my $i = 0; $i < @{$func->[1]}; $i++)
{
$ret .= ConvertType($func->[1]->[$i]->[0]);
$ret .= "," if ($i+1 < @{$func->[1]});
}
$ret .= "void" unless @{$func->[1]};
$ret .= ")";
return $ret;
}
2000-06-12 03:21:18 +02:00
#
# Extract and checks the number of arguments
#
if (@ARGV > 1) {
my $name0=$0;
$name0=~s%^.*/%%;
die "Usage: $name0 [version]\n";
2000-06-12 03:21:18 +02:00
}
my $version = $ARGV[0] || "1.1";
2000-06-12 03:21:18 +02:00
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;
} elsif ($version eq "1.3") {
%norm_categories = %cat_1_3;
} elsif ($version eq "1.4") {
%norm_categories = %cat_1_4;
} elsif ($version eq "1.5") {
%norm_categories = %cat_1_5;
2000-06-12 03:21:18 +02:00
} else {
die "Incorrect OpenGL version.\n";
2000-06-12 03:21:18 +02:00
}
#
# Fetch the registry files
#
-f "gl.spec" || system "wget http://www.opengl.org/registry/api/gl.spec" || die "cannot download gl.spec";
-f "gl.tm" || system "wget http://www.opengl.org/registry/api/gl.tm" || die "cannot download gl.tm";
-f "wgl.tm" || system "wget http://www.opengl.org/registry/api/wgl.tm" || die "cannot download wgl.tm";
-f "wglext.spec" || system "wget http://www.opengl.org/registry/api/wglext.spec" || die "cannot download wglext.spec";
-f "enum.spec" || system "wget http://www.opengl.org/registry/api/enum.spec" || die "cannot download enum.spec";
-f "enumext.spec" || system "wget http://www.opengl.org/registry/api/enumext.spec" || die "cannot download enumext.spec";
2000-06-12 03:21:18 +02:00
#
# First, create a mapping between the pseudo types used in the spec file
# and OpenGL types using the 'gl.tm' file.
#
my %pseudo_to_opengl = ();
sub load_types($)
{
my $file = shift;
open TYPES, "<$file" or die "Could not open $file";
while (my $line = <TYPES>) {
if ($line !~ /\w*\#/) {
my ($pseudo, $opengl) = ($line =~ /(\w*),\*,\*,\s*(.*),\*,\*/);
$pseudo_to_opengl{$pseudo} = $opengl;
}
}
close TYPES;
2000-06-12 03:21:18 +02:00
}
load_types( "wgl.tm" );
load_types( "gl.tm" );
2000-06-12 03:21:18 +02:00
# This is to override the 'void' -> '*' bogus conversion
$pseudo_to_opengl{"void"} = "void";
2009-08-04 23:42:41 +02:00
$pseudo_to_opengl{"sync"} = "GLvoid*";
$pseudo_to_opengl{"Int64"} = "INT64";
$pseudo_to_opengl{"UInt64"} = "UINT64";
2007-08-20 18:04:40 +02:00
$pseudo_to_opengl{"Int64EXT"} = "INT64";
$pseudo_to_opengl{"UInt64EXT"} = "UINT64";
2000-06-12 03:21:18 +02:00
#
# 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"] ] ];
#
my %norm_functions = ( "glDebugEntry" => [ "GLint", [[ "GLint", "unknown1" ],
[ "GLint", "unknown2" ]] ] );
#
# This stores various extensions NOT part of the GL extension registry but still
# implemented by most OpenGL libraries out there...
#
my %ext_functions =
(
"glDeleteBufferRegion" => [ "void", [ [ "GLenum", "region" ] ], "GL_KTX_buffer_region" ],
"glReadBufferRegion" => [ "void", [ [ "GLenum", "region" ],
[ "GLint", "x" ],
[ "GLint", "y" ],
[ "GLsizei", "width" ],
[ "GLsizei", "height" ] ], "GL_KTX_buffer_region" ],
"glDrawBufferRegion" => [ "void", [ [ "GLenum", "region" ],
[ "GLint", "x" ],
[ "GLint", "y" ],
[ "GLsizei", "width" ],
[ "GLsizei", "height" ],
[ "GLint", "xDest" ],
[ "GLint", "yDest" ] ], "GL_KTX_buffer_region" ],
"glBufferRegionEnabled" => [ "GLuint", [ ], "GL_KTX_buffer_region" ],
"glNewBufferRegion" => [ "GLuint", [ [ "GLenum", "type" ] ], "GL_KTX_buffer_region" ],
"glMTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat", "s" ],
[ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
"glMTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1dSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble", "s" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1dvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1fSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat", "s" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1fvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "const GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1iSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint", "s" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1ivSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1sSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort", "s" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord1svSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2dSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble", "s"],
[ "GLdouble", "t" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2dvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2fSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat", "s" ],
[ "GLfloat", "t" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2fvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2iSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint", "s" ],
[ "GLint", "t" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2ivSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2sSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort", "s" ],
[ "GLshort", "t" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord2svSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3dSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble", "s" ],
[ "GLdouble", "t" ],
[ "GLdouble", "r" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3dvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3fSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat", "s" ],
[ "GLfloat", "t" ],
[ "GLfloat", "r" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3fvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3iSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint", "s" ],
[ "GLint", "t" ],
[ "GLint", "r" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3ivSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3sSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort", "s" ],
[ "GLshort", "t" ],
[ "GLshort", "r" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord3svSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4dSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble", "s" ],
[ "GLdouble", "t" ],
[ "GLdouble", "r" ],
[ "GLdouble", "q" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4dvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLdouble *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4fSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat", "s" ],
[ "GLfloat", "t" ],
[ "GLfloat", "r" ],
[ "GLfloat", "q" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4fvSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLfloat *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4iSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint", "s" ],
[ "GLint", "t" ],
[ "GLint", "r" ],
[ "GLint", "q" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4ivSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4sSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort", "s" ],
[ "GLshort", "t" ],
[ "GLshort", "r" ],
[ "GLshort", "q" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoord4svSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLshort *", "v" ] ], "GL_SGIS_multitexture" ],
"glMultiTexCoordPointerSGIS" => [ "void", [ [ "GLenum", "target" ],
[ "GLint", "size" ],
[ "GLenum", "type" ],
[ "GLsizei", "stride" ],
[ "GLvoid *", "pointer" ] ], "GL_SGIS_multitexture" ],
"glSelectTextureSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
"glSelectTextureCoordSetSGIS" => [ "void", [ [ "GLenum", "target" ] ], "GL_SGIS_multitexture" ],
"glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], "GL_ATI_vertex_array_object" ],
"wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
[ "int", "format" ] ], "WGL_WINE_pixel_format_passthrough" ],
);
my %wgl_functions =
(
"wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
[ "struct wgl_context *", "dst" ],
[ "UINT", "mask" ] ] ],
"wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
"wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
"wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
[ "INT", "format" ],
[ "UINT", "size" ],
[ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
"wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
"wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
"wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
[ "struct wgl_context *", "context" ] ] ],
"wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
[ "INT", "format" ],
[ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
"wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
[ "struct wgl_context *", "dst" ] ] ],
"wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
);
my %supported_wgl_extensions =
(
"WGL_ARB_create_context" => 1,
"WGL_ARB_extensions_string" => 1,
"WGL_ARB_make_current_read" => 1,
"WGL_ARB_pbuffer" => 1,
"WGL_ARB_pixel_format" => 1,
"WGL_ARB_render_texture" => 1,
"WGL_EXT_extensions_string" => 1,
"WGL_EXT_swap_control" => 1,
"WGL_NV_vertex_array_range" => 1,
"WGL_WINE_pixel_format_passthrough" => 1,
);
sub parse_registry_file($)
{
my $file = shift;
my @arg_names;
my %arg_types;
open REGISTRY, "<$file" or die "cannot open $file";
while (my $line = <REGISTRY>) {
next unless ($line =~ /^\w*\(.*\)/);
2000-06-12 03:21:18 +02:00
# Get the function name (NOTE: the 'gl' prefix needs to be added later)
my ($funcname, $args) = ($line =~ /^(\w*)\((.*)\)/);
2000-06-12 03:21:18 +02:00
# and the argument names
@arg_names = split /\s*,\s*/, $args;
2002-06-01 04:55:48 +02:00
2000-06-12 03:21:18 +02:00
# After get :
# - the return type
# - category (the extension the function is part of)
2000-06-12 03:21:18 +02:00
# - the argument types
# - the category the function belongs
%arg_types = ();
my $category = "";
my $ret_type = "";
2000-06-12 03:21:18 +02:00
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;
2012-06-08 08:18:21 +02:00
} elsif ($line =~ /\t*return\t+(\w*)/) {
2000-06-12 03:21:18 +02:00
($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/) {
my ($name, $base_type, $dir, $ext) = ($line =~ /\t*param\s*(\w*)\s*(\w*) (in|out)\s+(.*)/);
my $ptr = 0;
2002-06-01 04:55:48 +02:00
unless (defined($name)) {
2000-06-12 03:21:18 +02:00
chomp $line;
die "Broken spec file line $line in function $funcname\n";
}
if ($ext =~ /array/) {
# This is a pointer
$ptr = 1;
} elsif ($ext =~ /reference/) {
# This is a pointer
$ptr = 1;
2000-06-12 03:21:18 +02:00
} 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
my $type = $pseudo_to_opengl{$base_type};
2000-06-12 03:21:18 +02:00
unless (defined($type)) {
chomp $line;
die "Unsupported return type in function $funcname for type $base_type (line $line)\n";
}
if ($ptr) {
$type .= "*";
$type = "const $type" if $dir eq "in";
2000-06-12 03:21:18 +02:00
}
2002-06-01 04:55:48 +02:00
2000-06-12 03:21:18 +02:00
$arg_types{$name} = $type;
}
}
# Now, build the argument reference
my $arg_ref = [ ];
for (my $i = 0; $i < @arg_names; $i++) {
2000-06-12 03:21:18 +02:00
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";
}
2002-06-01 04:55:48 +02:00
2000-06-12 03:21:18 +02:00
push @$arg_ref, [ $arg_types{$arg_names[$i]}, $arg_names[$i] ];
}
2002-06-01 04:55:48 +02:00
2000-06-12 03:21:18 +02:00
# Now, put in one or the other hash table
if ($norm_categories{$category}) {
$norm_functions{"gl$funcname"} = [ $ret_type, $arg_ref ];
} elsif ($file =~ /^wgl/) {
if (defined $supported_wgl_extensions{"WGL_$category"}) {
$ext_functions{"wgl$funcname"} = [ $ret_type, $arg_ref, "WGL_$category" ];
}
2000-06-12 03:21:18 +02:00
} else {
$ext_functions{"gl$funcname"} = [ $ret_type, $arg_ref, "GL_$category" ];
2000-06-12 03:21:18 +02:00
}
}
close REGISTRY;
2000-06-12 03:21:18 +02:00
}
sub parse_enum_file($$)
{
my ($file, $enums) = @_;
open FILE, "<$file" or die "cannot open $file";
while (<FILE>)
{
chomp;
next if /^#/;
if (/^\t([0-9A-Z_]+)\s*=\s*(((0x[0-9A-Fa-f]+)|([0-9]+))([uUlL]+)?)/)
{
${$enums}{"GL_$1"} = $2;
next;
}
}
close FILE;
}
parse_registry_file( "gl.spec" );
parse_registry_file( "wglext.spec" );
2000-06-12 03:21:18 +02:00
my %enums = ();
parse_enum_file( "enum.spec", \%enums );
parse_enum_file( "enumext.spec", \%enums );
#
# Get the current wgl_driver.h version
#
my $wgl_version = 0;
open HEADER, "<../../include/wine/wgl_driver.h" or die "cannot open wgl_driver.h";
while (<HEADER>)
{
next unless /^#define WINE_WGL_DRIVER_VERSION (\d+)/;
$wgl_version = $1;
last;
}
close HEADER;
#
# Generate the wgl_driver.h file
#
open HEADER, ">../../include/wine/wgl_driver.h" or die "cannot create wgl_driver.h";
print HEADER "/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
print HEADER "#ifndef __WINE_WGL_DRIVER_H\n";
print HEADER "#define __WINE_WGL_DRIVER_H\n\n";
print HEADER "#ifndef WINE_GLAPI\n";
print HEADER "#define WINE_GLAPI\n";
print HEADER "#endif\n\n";
printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
print HEADER "struct wgl_context;\n";
print HEADER "struct wgl_pbuffer;\n\n";
print HEADER "struct opengl_funcs\n{\n";
print HEADER " struct\n {\n";
foreach (sort keys %wgl_functions)
{
printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
}
print HEADER " } wgl;\n\n";
print HEADER " struct\n {\n";
foreach (sort keys %norm_functions)
{
next if $_ eq "glDebugEntry";
printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $norm_functions{$_});
}
print HEADER " } gl;\n\n";
print HEADER " struct\n {\n";
foreach (sort keys %ext_functions)
{
printf HEADER " %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $ext_functions{$_});
}
print HEADER " } ext;\n";
print HEADER "};\n\n";
print HEADER "#define ALL_WGL_FUNCS";
foreach (sort keys %norm_functions)
{
next if $_ eq "glDebugEntry";
printf HEADER " \\\n USE_GL_FUNC(\%s)", $_;
}
print HEADER "\n\n";
print HEADER "extern struct opengl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version );\n";
print HEADER "extern BOOL CDECL __wine_set_pixel_format( HWND hwnd, int format );\n\n";
print HEADER "#endif /* __WINE_WGL_DRIVER_H */\n";
close HEADER;
#
# Generate the wgl.h file
#
open HEADER, ">../../include/wine/wgl.h" or die "cannot create wgl.h";
print HEADER "/* Automatically generated from http://www.opengl.org/registry/api files; DO NOT EDIT! */\n\n";
print HEADER "#ifndef __WINE_WGL_H\n";
print HEADER "#define __WINE_WGL_H\n\n";
print HEADER "#ifndef GLAPIENTRY\n";
print HEADER "#define GLAPIENTRY __stdcall\n";
print HEADER "#endif\n\n";
foreach (sort keys %arg_conv)
{
printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
}
print HEADER "\n";
my $maxlen = 1;
foreach (keys %enums) { $maxlen = length($_) if length($_) > $maxlen; }
foreach (sort keys %enums)
{
printf HEADER "#define %-*s %s\n", $maxlen, $_, $enums{$_};
}
print HEADER "\n";
foreach (sort keys %norm_functions)
{
printf HEADER "%s;\n", get_func_proto("GLAPIENTRY %s", $_, $norm_functions{$_});
}
print HEADER "\n#endif /* __WINE_WGL_H */\n";
close HEADER;
2000-06-12 03:21:18 +02:00
#
# Now, generate the output files. First, the spec file.
#
open(SPEC, ">$spec_file");
2000-06-12 03:21:18 +02:00
foreach (sort keys %norm_functions) {
my $args=" ";
for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
my $type = $norm_functions{$_}->[1]->[$i]->[0];
2000-06-12 03:21:18 +02:00
if ($type =~ /\*/) {
$args .= "ptr ";
2000-06-12 03:21:18 +02:00
} elsif (defined($arg_conv{$type})) {
$args .= "$@$arg_conv{$type}[0] ";
2000-06-12 03:21:18 +02:00
} else {
2005-05-30 11:56:56 +02:00
die "No conversion for GL type $type...\n";
2000-06-12 03:21:18 +02:00
}
}
$args = substr($args,1,-1);
print SPEC "@ stdcall $_($args)\n";
2000-06-12 03:21:18 +02:00
}
print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
@ stdcall wglCopyContext(long long long)
@ stdcall wglCreateContext(long)
@ stdcall wglCreateLayerContext(long long)
@ stdcall wglDeleteContext(long)
@ stdcall wglDescribeLayerPlane(long long long long ptr)
@ stdcall wglDescribePixelFormat(long long long ptr)
@ stdcall wglGetCurrentContext()
@ stdcall wglGetCurrentDC()
@ stub wglGetDefaultProcAddress
@ stdcall wglGetLayerPaletteEntries(long long long long ptr)
@ stdcall wglGetPixelFormat(long)
@ stdcall wglGetProcAddress(str)
@ stdcall wglMakeCurrent(long long)
@ stdcall wglRealizeLayerPalette(long long long)
@ stdcall wglSetLayerPaletteEntries(long long long long ptr)
@ stdcall wglSetPixelFormat(long long ptr)
@ stdcall wglShareLists(long long)
@ stdcall wglSwapBuffers(long)
@ stdcall wglSwapLayerBuffers(long long)
@ stdcall wglUseFontBitmapsA(long long long long)
@ stdcall wglUseFontBitmapsW(long long long long)
@ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
@ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
";
2000-06-12 03:21:18 +02:00
close(SPEC);
#
# After the spec file, the opengl_norm.c file
#
open(NORM, ">$norm_file");
2000-06-12 03:21:18 +02:00
print NORM "
/* Auto-generated file... Do not edit ! */
#include \"config.h\"
#include <stdarg.h>
#include \"winternl.h\"
#include \"wingdi.h\"
#include \"wine/wgl.h\"
#include \"wine/wgl_driver.h\"
#include \"wine/debug.h\"
2000-06-12 03:21:18 +02:00
WINE_DEFAULT_DEBUG_CHANNEL(opengl);
2000-06-12 03:21:18 +02:00
";
foreach (sort keys %norm_functions) {
my $string = GenerateThunk($_, $norm_functions{$_}, 1, "gl");
print NORM "\n$string" if $string;
2000-06-12 03:21:18 +02:00
}
foreach (sort keys %wgl_functions) {
print NORM generate_null_func($_, $wgl_functions{$_});
}
foreach (sort keys %norm_functions) {
print NORM generate_null_func($_, $norm_functions{$_});
}
foreach (sort keys %ext_functions) {
print NORM generate_null_func($_, $ext_functions{$_});
}
print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n {\n";
foreach (sort keys %wgl_functions) { print NORM " null_$_,\n"; }
print NORM " },\n {\n";
foreach (sort keys %norm_functions) { print NORM " null_$_,\n" unless $_ eq "glDebugEntry"; }
print NORM " },\n {\n";
foreach (sort keys %ext_functions) { print NORM " null_$_,\n"; }
print NORM " }\n};\n";
2000-06-12 03:21:18 +02:00
close(NORM);
#
# Finally, more complex, the opengl_ext.c file
#
open(EXT, ">$ext_file");
2000-06-12 03:21:18 +02:00
print EXT "
/* Auto-generated file... Do not edit ! */
#include \"config.h\"
#include <stdarg.h>
#include \"opengl_ext.h\"
#include \"winternl.h\"
#include \"wingdi.h\"
#include \"wine/wgl.h\"
#define WGL_WGLEXT_PROTOTYPES
#include \"wine/wglext.h\"
#include \"wine/wgl_driver.h\"
#include \"wine/debug.h\"
2000-06-12 03:21:18 +02:00
WINE_DEFAULT_DEBUG_CHANNEL(opengl);
2000-06-12 03:21:18 +02:00
";
# The thunks themselves....
my $count = keys %ext_functions;
print EXT "const int extension_registry_size = $count;\n";
2000-06-12 03:21:18 +02:00
foreach (sort keys %ext_functions) {
my $string = GenerateThunk($_, $ext_functions{$_}, 0, "ext");
print EXT "\nstatic $string" if $string;
2000-06-12 03:21:18 +02:00
}
2007-12-07 21:01:34 +01:00
# Then the table giving the string <-> function correspondence */
print EXT "\nconst OpenGL_extension extension_registry[$count] = {\n";
my $i = 0;
2000-06-12 03:21:18 +02:00
foreach (sort keys %ext_functions) {
my $func_ref = $ext_functions{$_};
print EXT " { \"$_\", \"$func_ref->[2]\", $_ }";
if ($i != $count-1) {
2000-06-12 03:21:18 +02:00
print EXT ",";
}
$i++;
print EXT "\n";
}
print EXT "};\n";
close(EXT);