added ARRAY expansion support to the generator, more fixes
svn path=/trunk/tsunami-bindings/; revision=24809
This commit is contained in:
Родитель
79b8624fac
Коммит
8a9f8a8e78
|
@ -25,7 +25,7 @@ namespace Tsunami.Bindings {
|
|||
// public const CallingConvention GL_NATIVE_CALLCONV = CallingConvention.Cdecl;
|
||||
#else
|
||||
public const string GL_NATIVE_LIBRARY = "libGL.so";
|
||||
public const string GL_EXTENSION_QUERY_PROC = "glXGetProcAddress";
|
||||
public const string GL_EXTENSION_QUERY_PROC = "glXGetProcAddressARB";
|
||||
public const CallingConvention GL_NATIVE_CALLCONV = CallingConvention.Cdecl;
|
||||
#endif
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace Tsunami.Bindings {
|
|||
private static GlExtensionLoader loaderInst;
|
||||
|
||||
private Hashtable loadedExtensions;
|
||||
private Hashtable loadedFunctions;
|
||||
|
||||
public static GlExtensionLoader GetInstance() {
|
||||
if (loaderInst == null) {
|
||||
|
@ -59,6 +60,7 @@ namespace Tsunami.Bindings {
|
|||
|
||||
protected GlExtensionLoader () {
|
||||
loadedExtensions = new Hashtable();
|
||||
loadedFunctions = new Hashtable();
|
||||
}
|
||||
|
||||
public bool LoadExtension (string extname) {
|
||||
|
@ -92,9 +94,13 @@ namespace Tsunami.Bindings {
|
|||
|
||||
OpenGLExtensionImport oglext = (OpenGLExtensionImport) atts[0];
|
||||
if (oglext.ExtensionName == extname) {
|
||||
Console.WriteLine ("Loading " + oglext.EntryPoint + " for " + extname);
|
||||
string fieldname = "ext__" + extname + "__" + oglext.EntryPoint;
|
||||
if (loadedFunctions.ContainsKey (fieldname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FieldInfo fi = glt.GetField ("ext__" + extname + "__" + oglext.EntryPoint,
|
||||
Console.WriteLine ("Loading " + oglext.EntryPoint + " for " + extname);
|
||||
FieldInfo fi = glt.GetField (fieldname,
|
||||
BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
|
||||
if (fi == null) {
|
||||
Console.WriteLine ("Can't get extension field!");
|
||||
|
@ -109,6 +115,7 @@ namespace Tsunami.Bindings {
|
|||
}
|
||||
|
||||
fi.SetValue (glt, procaddr);
|
||||
loadedFunctions[fieldname] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
38
csgen.pl
38
csgen.pl
|
@ -53,6 +53,17 @@ my %typemap = ('GLenum' => 'unsigned int',
|
|||
'GLXPbufferSGIX' => 'int',
|
||||
);
|
||||
|
||||
# List of things that an ARRAY in a function expands out to
|
||||
my @ARRAY_expansions = ('bool []',
|
||||
'byte []',
|
||||
'short []',
|
||||
'ushort []',
|
||||
'int []',
|
||||
'uint []',
|
||||
'float []',
|
||||
'double []',
|
||||
'IntPtr');
|
||||
|
||||
sub parse_ext($)
|
||||
{
|
||||
my $filename = shift;
|
||||
|
@ -153,6 +164,7 @@ sub output_func ($$)
|
|||
$usefname = $fname;
|
||||
$frtype = $fdata->{'rtype'};
|
||||
$fallparms = $fdata->{'parms'};
|
||||
$arrayexpand = 0;
|
||||
$unsafe = "";
|
||||
|
||||
# fix up some things that are keywords, argh
|
||||
|
@ -201,6 +213,10 @@ sub output_func ($$)
|
|||
$unsafe = "unsafe";
|
||||
}
|
||||
|
||||
if ($fallparms =~ m/ARRAY/) {
|
||||
$arrayexpand = 1;
|
||||
}
|
||||
|
||||
## The idea here is to automatically take things like
|
||||
## "GLfloat *f" and spit out bindings for
|
||||
## "GLfloat *f" and "GLfloat [] f"; also
|
||||
|
@ -229,12 +245,18 @@ sub output_func ($$)
|
|||
}
|
||||
}
|
||||
|
||||
my $outfunc;
|
||||
|
||||
# if extname is 0, it means it's a core GL function
|
||||
# and shouldn't get ExtensionAttribute info, but instead
|
||||
# a straight DllImport
|
||||
if ($extname eq "CORE") {
|
||||
$outfunc = sub
|
||||
{
|
||||
$paramargs = shift;
|
||||
print " [DllImport(GlDetails.GL_NATIVE_LIBRARY, EntryPoint=\"$fname\", CallingConvention=$cconv, ExactSpelling=true)]\n";
|
||||
print " public static extern $unsafe $frtype $usefname ($fallparms);\n";
|
||||
print " public static extern $unsafe $frtype $usefname ($paramargs);\n";
|
||||
}
|
||||
} else {
|
||||
# else this is an extension, so we need to not have a DllImport, but an attribute here
|
||||
$extfield = "ext__" . $extname . "__" . $fname;
|
||||
|
@ -243,12 +265,24 @@ sub output_func ($$)
|
|||
$seenextfields{$extfield} = 1;
|
||||
}
|
||||
|
||||
$outfunc = sub
|
||||
{
|
||||
$paramargs = shift;
|
||||
print " [OpenGLExtensionImport(\"$extname\", \"$fname\")]\n";
|
||||
print " public static $unsafe $frtype $usefname ($fallparms) {\n";
|
||||
print " public static $unsafe $frtype $usefname ($paramargs) {\n";
|
||||
print " throw new InvalidOperationException(\"binding error\");\n";
|
||||
print " }\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($arrayexpand) {
|
||||
foreach my $expansion (@ARRAY_expansions) {
|
||||
($newparms = $fallparms) =~ s/ARRAY/$expansion/;
|
||||
&$outfunc ($newparms);
|
||||
}
|
||||
} else {
|
||||
&$outfunc ($fallparms);
|
||||
}
|
||||
|
||||
print "\n";
|
||||
}
|
||||
|
|
|
@ -548,7 +548,7 @@ GL_VERSION_1_1
|
|||
void glBlendFunc (GLenum sfactor, GLenum dfactor)
|
||||
void glCallList (GLuint list)
|
||||
void glCallLists (GLsizei n, GLenum type, const GLvoid *lists)
|
||||
void glCallLists (GLsizei n, GLenum type, System.Array lists)
|
||||
void glCallLists (GLsizei n, GLenum type, ARRAY lists)
|
||||
void glClear (GLbitfield mask)
|
||||
void glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
|
||||
void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
|
||||
|
@ -622,8 +622,7 @@ GL_VERSION_1_1
|
|||
void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
|
||||
void glColorMaterial (GLenum face, GLenum mode)
|
||||
void glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
void glColorPointer (GLint size, GLenum type, GLsizei stride, System.Array pointer)
|
||||
void glColorPointer (GLint size, GLenum type, GLsizei stride, IntPtr pointer)
|
||||
void glColorPointer (GLint size, GLenum type, GLsizei stride, ARRAY pointer)
|
||||
void glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)
|
||||
void glCopyTexImage1D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border)
|
||||
void glCopyTexImage2D (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
|
||||
|
@ -642,12 +641,12 @@ GL_VERSION_1_1
|
|||
void glDrawArrays (GLenum mode, GLint first, GLsizei count)
|
||||
void glDrawBuffer (GLenum mode)
|
||||
void glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
|
||||
void glDrawElements (GLenum mode, GLsizei count, GLenum type, System.Array indices)
|
||||
void glDrawElements (GLenum mode, GLsizei count, GLenum type, ARRAY indices)
|
||||
void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
|
||||
void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, System.Array pixels)
|
||||
void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glEdgeFlag (GLboolean flag)
|
||||
void glEdgeFlagPointer (GLsizei stride, const GLvoid *pointer)
|
||||
void glEdgeFlagPointer (GLsizei stride, System.Array pointer)
|
||||
void glEdgeFlagPointer (GLsizei stride, GLboolean [] pointer)
|
||||
void glEdgeFlagv (const GLboolean *flag)
|
||||
void glEdgeFlagv (GLboolean [] flag)
|
||||
void glEnable (GLenum cap)
|
||||
|
@ -735,7 +734,7 @@ GL_VERSION_1_1
|
|||
void glGetTexGeniv (GLenum coord, GLenum pname, GLint *params)
|
||||
void glGetTexGeniv (GLenum coord, GLenum pname, GLint [] params)
|
||||
void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)
|
||||
void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, System.Array pixels)
|
||||
void glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params)
|
||||
void glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat [] params)
|
||||
void glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params)
|
||||
|
@ -747,8 +746,7 @@ GL_VERSION_1_1
|
|||
void glHint (GLenum target, GLenum mode)
|
||||
void glIndexMask (GLuint mask)
|
||||
void glIndexPointer (GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
void glIndexPointer (GLenum type, GLsizei stride, System.Array pointer)
|
||||
void glIndexPointer (GLenum type, GLsizei stride, IntPtr pointer)
|
||||
void glIndexPointer (GLenum type, GLsizei stride, ARRAY pointer)
|
||||
void glIndexd (GLdouble c)
|
||||
void glIndexdv (const GLdouble *c)
|
||||
void glIndexf (GLfloat c)
|
||||
|
@ -761,8 +759,7 @@ GL_VERSION_1_1
|
|||
void glIndexubv (const GLubyte *c)
|
||||
void glInitNames (void)
|
||||
void glInterleavedArrays (GLenum format, GLsizei stride, const GLvoid *pointer)
|
||||
void glInterleavedArrays (GLenum format, GLsizei stride, IntPtr pointer)
|
||||
void glInterleavedArrays (GLenum format, GLsizei stride, System.Array pointer)
|
||||
void glInterleavedArrays (GLenum format, GLsizei stride, ARRAY pointer)
|
||||
GLboolean glIsEnabled (GLenum cap)
|
||||
GLboolean glIsList (GLuint list)
|
||||
GLboolean glIsTexture (GLuint texture)
|
||||
|
@ -839,6 +836,7 @@ GL_VERSION_1_1
|
|||
void glNormal3sv (const GLshort [] v)
|
||||
void glNormal3 (const GLshort [] v) = glNormal3sv
|
||||
void glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
void glNormalPointer (GLenum type, GLsizei stride, ARRAY pointer)
|
||||
void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
|
||||
void glPassThrough (GLfloat token)
|
||||
void glPixelMapfv (GLenum map, GLsizei mapsize, const GLfloat *values)
|
||||
|
@ -893,8 +891,7 @@ GL_VERSION_1_1
|
|||
void glRasterPos4sv (const GLshort *v)
|
||||
void glReadBuffer (GLenum mode)
|
||||
void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
|
||||
void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, System.Array pixels)
|
||||
void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, IntPtr pixels)
|
||||
void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glRectd (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
|
||||
void glRectdv (const GLdouble *v1, const GLdouble *v2)
|
||||
void glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
|
||||
|
@ -969,11 +966,9 @@ GL_VERSION_1_1
|
|||
void glTexGeniv (GLenum coord, GLenum pname, const GLint [] params)
|
||||
void glTexGen (GLenum coord, GLenum pname, const GLint [] params) = glTexGeniv
|
||||
void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
|
||||
void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, System.Array pixels)
|
||||
void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, IntPtr pixels)
|
||||
void glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
|
||||
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, System.Array pixels)
|
||||
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, IntPtr pixels)
|
||||
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glTexParameterf (GLenum target, GLenum pname, GLfloat param)
|
||||
void glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params)
|
||||
void glTexParameterfv (GLenum target, GLenum pname, const GLfloat [] params)
|
||||
|
@ -983,11 +978,9 @@ GL_VERSION_1_1
|
|||
void glTexParameteriv (GLenum target, GLenum pname, const GLint [] params)
|
||||
void glTexParameter (GLenum target, GLenum pname, const GLint [] params) = glTexParameteriv
|
||||
void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels)
|
||||
void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, System.Array pixels)
|
||||
void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, IntPtr pixels)
|
||||
void glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
|
||||
void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, System.Array pixels)
|
||||
void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, IntPtr pixels)
|
||||
void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, ARRAY pixels)
|
||||
void glTranslated (GLdouble x, GLdouble y, GLdouble z)
|
||||
void glTranslatef (GLfloat x, GLfloat y, GLfloat z)
|
||||
void glVertex2d (GLdouble x, GLdouble y)
|
||||
|
@ -1015,7 +1008,6 @@ GL_VERSION_1_1
|
|||
void glVertex4s (GLshort x, GLshort y, GLshort z, GLshort w)
|
||||
void glVertex4sv (const GLshort *v)
|
||||
void glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
void glVertexPointer (GLint size, GLenum type, GLsizei stride, System.Array pointer)
|
||||
void glVertexPointer (GLint size, GLenum type, GLsizei stride, IntPtr pointer)
|
||||
void glVertexPointer (GLint size, GLenum type, GLsizei stride, ARRAY pointer)
|
||||
void glViewport (GLint x, GLint y, GLsizei width, GLsizei height)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче