Sycned with gl3 branch.

This commit is contained in:
the_fiddler 2007-08-01 21:14:39 +00:00
parent de43ff5f1f
commit 00da3bf3f4
25 changed files with 21365 additions and 35153 deletions

View file

@ -1,3 +1,21 @@
OpenTK 0.3.8 -> 0.3.9
+ Bind
+ Rewrote almost everything. Does not rely on CodeDOM anymore (wasn't flexible enough).
+ Initial work for gl3, wgl, glx, glu compatibility.
+ Implemented almost all pending features:
+ Extensions in different classes (e.g. GL.ARB.ActiveTexture)
+ Fixed statement instead of GCHandle for improved performance
+ Real pointers instead of IntPtrs
+ CLS-Compliant and non CLS-Compliant overloads (e.g. functions with unsigned parameters).
+ Overloads over the 'basic' function (e.g. GL.Vertex3fv -> GL.Vertex3)
+ Enums now in the GL class.
+ New commandline options
+ 'legacy': defines compatibility with Tao ('-legacy:tao')
+ 'mode': defines translation mode (e.g. gl2, gl3, wgl etc)
+ 4 files are now generated: GL.cs, GLCore.cs, GLDelegates.cs, GLEnums.cs
OpenTK 0.3.7 -> 0.3.8 OpenTK 0.3.7 -> 0.3.8
+ New project layout. Only four projects remain under the 'Source' directory: Bind, Build, Examples, OpenTK + New project layout. Only four projects remain under the 'Source' directory: Bind, Build, Examples, OpenTK

View file

@ -9,69 +9,32 @@ namespace Bind.GL2
{ {
class Generator : IBind class Generator : IBind
{ {
private SpecReader specReader = new SpecReader(); internal static SpecReader specReader;
private SpecWriter specWriter = new SpecWriter(); internal static SpecWriter specWriter;
DelegateCollection delegates = new DelegateCollection();
FunctionCollection wrappers = new FunctionCollection();
//List<Bind.Structures.Enum> enums = new List<Bind.Structures.Enum>();
EnumCollection enums = new EnumCollection();
EnumCollection extEnums = new EnumCollection();
Dictionary<string, string> GLTypes = new Dictionary<string, string>();
Dictionary<string, string> CSTypes = new Dictionary<string, string>();
string specFolder; string specFolder;
public Generator(string folder) public Generator(string folder)
{ {
specFolder = folder; specFolder = folder;
specReader = new GL2.SpecReader();
specWriter = new GL2.SpecWriter();
} }
#region IBind Members #region IBind Members
/*
public ISpecReader SpecReader
{
get { return specReader; }
}
*/
#region public void Process() #region public void Process()
public void Process() public void Process()
{ {
// Read Bind.Structures.Type.Initialize();
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\gl.tm")) Bind.Structures.Enum.Initialize();
{ Bind.Structures.Function.Initialize();
GLTypes = specReader.ReadTypeMap(sr); Bind.Structures.Delegate.Initialize();
}
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\csharp.tm"))
{
CSTypes = specReader.ReadCSTypeMap(sr);
}
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\gl.spec"))
{
delegates = specReader.ReadDelegates(sr);
}
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\enum.spec"))
{
enums = specReader.ReadEnums(sr);
}
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\enumext.spec"))
{
extEnums = specReader.ReadEnums(sr);
}
// Merge all opengl enumerants in enums
foreach (Bind.Structures.Enum e in extEnums.Values)
{
//enums.Add(e.Name, e);
Utilities.Merge(enums, e);
}
// Process enums and delegates - create wrappers. // Process enums and delegates - create wrappers.
this.Translate(); this.Translate();
// Write // Write
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, "GLEnums.cs"))) using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, "GLEnums.cs")))
{ {
@ -83,7 +46,7 @@ namespace Bind.GL2
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
specWriter.WriteEnums(sw, enums); specWriter.WriteEnums(sw, Bind.Structures.Enum.GLEnums);
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
@ -97,8 +60,10 @@ namespace Bind.GL2
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
specWriter.WriteTypes(sw, CSTypes); //specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
specWriter.WriteDelegates(sw, delegates); sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;");
specWriter.WriteDelegates(sw, Bind.Structures.Delegate.Delegates);
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
@ -109,8 +74,10 @@ namespace Bind.GL2
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
specWriter.WriteTypes(sw, CSTypes); //specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
specWriter.WriteImports(sw, delegates); sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;");
specWriter.WriteImports(sw, Bind.Structures.Delegate.Delegates);
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
@ -121,8 +88,10 @@ namespace Bind.GL2
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
specWriter.WriteTypes(sw, CSTypes); //specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
specWriter.WriteWrappers(sw, wrappers, CSTypes); sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;");
specWriter.WriteWrappers(sw, Bind.Structures.Function.Wrappers, Bind.Structures.Type.CSTypes);
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
@ -137,184 +106,15 @@ namespace Bind.GL2
private void Translate() private void Translate()
{ {
foreach (Bind.Structures.Enum e in enums.Values) foreach (Bind.Structures.Enum e in Bind.Structures.Enum.GLEnums.Values)
{ {
TranslateEnum(e); TranslateEnum(e);
} }
foreach (Bind.Structures.Delegate d in delegates.Values) foreach (Bind.Structures.Delegate d in Bind.Structures.Delegate.Delegates.Values)
{ {
TranslateReturnType(d);
TranslateParameters(d);
//wrappers.AddRange(d.CreateWrappers()); //wrappers.AddRange(d.CreateWrappers());
foreach (Function f in d.CreateWrappers(CSTypes))
{
if (!f.CLSCompliant)
{
Function clsFunction = f.GetCLSCompliantFunction(CSTypes);
if (clsFunction.Parameters.ToString(true) != f.Parameters.ToString(true))
wrappers.Add(clsFunction);
}
wrappers.Add(f);
}
}
}
#endregion
#region private void TranslateReturnType(Bind.Structures.Delegate d)
/// <summary>
/// Translates the opengl return type to the equivalent C# type.
/// </summary>
/// <param name="d">The opengl function to translate.</param>
/// <remarks>
/// First, we use the official typemap (gl.tm) to get the correct type.
/// Then we override this, when it is:
/// 1) A string (we have to use Marshal.PtrToStringAnsi, to avoid heap corruption)
/// 2) An array (translates to IntPtr)
/// 3) A generic object or void* (translates to IntPtr)
/// 4) A GLenum (translates to int on Legacy.Tao or GL.Enums.GLenum otherwise).
/// Return types must always be CLS-compliant, because .Net does not support overloading on return types.
/// </remarks>
private void TranslateReturnType(Bind.Structures.Delegate d)
{
if (GLTypes.ContainsKey(d.ReturnType.Type))
{
d.ReturnType.Type = GLTypes[d.ReturnType.Type];
}
if (d.ReturnType.Type.ToLower().Contains("void") && d.ReturnType.Pointer)
{
d.ReturnType.WrapperType = WrapperTypes.GenericReturnType;
}
if (d.ReturnType.Type == "GLstring")
{
d.ReturnType.Type = "System.IntPtr";
d.ReturnType.WrapperType = WrapperTypes.StringReturnType;
}
if (d.ReturnType.Type.ToLower().Contains("object"))
{
d.ReturnType.Type = "System.IntPtr";
d.ReturnType.WrapperType |= WrapperTypes.GenericReturnType;
}
if (d.ReturnType.Type == "GLenum")
{
if (Settings.Compatibility == Settings.Legacy.None)
d.ReturnType.Type = Settings.GLClass + ".Enums.GLenum";
else
d.ReturnType.Type = "int";
}
if (d.ReturnType.Type.ToLower().Contains("bool") && Settings.Compatibility == Settings.Legacy.Tao)
{
d.ReturnType.Type = "int";
}
if (d.ReturnType.WrapperType != WrapperTypes.None)
{
d.NeedsWrapper = true;
}
d.ReturnType.Type = d.ReturnType.GetCLSCompliantType(CSTypes);
}
#endregion
#region private void TranslateParameters(Bind.Structures.Delegate d)
private void TranslateParameters(Bind.Structures.Delegate d)
{
string s;
Bind.Structures.Enum @enum;
foreach (Parameter p in d.Parameters)
{
// Translate enum parameters
if (enums.TryGetValue(p.Type, out @enum) && @enum.Name != "GLenum")
{
if (Settings.Compatibility == Settings.Legacy.None)
p.Type = p.Type.Insert(0, Settings.GLClass + ".Enums.");
else
p.Type = "int";
}
else if (GLTypes.TryGetValue(p.Type, out s))
{
// Check if the parameter is a generic GLenum. If yes,
// check if a better match exists:
if (s.Contains("GLenum") && !String.IsNullOrEmpty(d.Category))
{
if (Settings.Compatibility == Settings.Legacy.None)
{
// Better match: enum.Name == function.Category (e.g. GL_VERSION_1_1 etc)
if (enums.ContainsKey(d.Category))
{
p.Type = Settings.GLClass + ".Enums." + d.Category;
}
else
{
p.Type = Settings.GLClass + ".Enums.GLenum";
}
}
else
{
p.Type = "int";
}
}
else
{
// This is not enum, default translation:
p.Type = s;
}
}
// Translate pointer parameters
if (p.Pointer)
{
p.WrapperType = WrapperTypes.ArrayParameter;
if (p.Type.ToLower().Contains("char") || p.Type.ToLower().Contains("string"))
{
// char* or string -> [In] String or [Out] StringBuilder
p.Type =
p.Flow == Parameter.FlowDirection.Out ?
"System.Text.StringBuilder" :
"System.String";
if (d.Name.Contains("ShaderSource"))
{
// Special case: these functions take a string[]
//p.IsPointer = true;
p.Array = 1;
}
p.Pointer = false;
p.WrapperType = WrapperTypes.None;
}
else if (p.Type.ToLower().Contains("void"))
{
p.WrapperType = WrapperTypes.GenericParameter;
}
}
// Check for LineStipple (should be unchecked)
if (p.Type.ToLower().Contains("ushort") && d.Name.Contains("LineStipple"))
{
p.WrapperType = WrapperTypes.UncheckedParameter;
}
if (p.Type.ToLower().Contains("bool"))
{
p.WrapperType = WrapperTypes.BoolParameter;
}
if (p.WrapperType != WrapperTypes.None)
{
d.NeedsWrapper = true;
}
} }
} }
@ -324,7 +124,6 @@ namespace Bind.GL2
private void TranslateEnum(Bind.Structures.Enum e) private void TranslateEnum(Bind.Structures.Enum e)
{ {
foreach (Constant c in e.ConstantCollection.Values) foreach (Constant c in e.ConstantCollection.Values)
{ {
// There are cases when a value is an aliased constant, with no enum specified. // There are cases when a value is an aliased constant, with no enum specified.
@ -332,7 +131,7 @@ namespace Bind.GL2
// In this case try searching all enums for the correct constant to alias (stupid opengl specs). // In this case try searching all enums for the correct constant to alias (stupid opengl specs).
if (String.IsNullOrEmpty(c.Reference) && !Char.IsDigit(c.Value[0])) if (String.IsNullOrEmpty(c.Reference) && !Char.IsDigit(c.Value[0]))
{ {
foreach (Bind.Structures.Enum @enum in enums.Values) foreach (Bind.Structures.Enum @enum in Bind.Structures.Enum.GLEnums.Values)
{ {
// Skip generic GLenum // Skip generic GLenum
if (@enum.Name == "GLenum") if (@enum.Name == "GLenum")
@ -348,5 +147,53 @@ namespace Bind.GL2
} }
#endregion #endregion
#region ISpecReader Members
public DelegateCollection ReadDelegates(StreamReader specFile)
{
return specReader.ReadDelegates(specFile);
}
public EnumCollection ReadEnums(StreamReader specFile)
{
return specReader.ReadEnums(specFile);
}
public Dictionary<string, string> ReadTypeMap(StreamReader specFile)
{
return specReader.ReadTypeMap(specFile);
}
public Dictionary<string, string> ReadCSTypeMap(StreamReader specFile)
{
return specReader.ReadCSTypeMap(specFile);
}
#endregion
#region ISpecWriter Members
public void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
{
specWriter.WriteDelegates(sw, delegates);
}
public void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes)
{
specWriter.WriteWrappers(sw, wrappers, CSTypes);
}
public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
{
specWriter.WriteEnums(sw, enums);
}
public void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes)
{
specWriter.WriteTypes(sw, CSTypes);
}
#endregion
} }
} }

View file

@ -34,7 +34,7 @@ namespace Bind.GL2
// Get function name: // Get function name:
d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0]; d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];
if (d.Name == "CallLists") if (d.Name.Contains("MultiTexCoord1"))
{ {
} }
@ -54,16 +54,14 @@ namespace Bind.GL2
switch (words[0]) switch (words[0])
{ {
case "return": // Line denotes return value case "return": // Line denotes return value
d.ReturnType.Type = words[1]; d.ReturnType.CurrentType = words[1];
break; break;
case "param": // Line denotes parameter case "param": // Line denotes parameter
Parameter p = new Parameter(); Parameter p = new Parameter();
WrapperTypes wrapper;
string type;
p.Name = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1]; p.Name = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
p.Type = words[2]; p.CurrentType = words[2];
p.Pointer = words[4] == "array" ? true : false; p.Pointer = words[4] == "array" ? true : false;
p.Flow = words[3] == "in" ? Parameter.FlowDirection.In : Parameter.FlowDirection.Out; p.Flow = words[3] == "in" ? Parameter.FlowDirection.In : Parameter.FlowDirection.Out;
@ -82,6 +80,8 @@ namespace Bind.GL2
} }
while (!specFile.EndOfStream); while (!specFile.EndOfStream);
d.Translate();
delegates.Add(d); delegates.Add(d);
} }
} }

View file

@ -114,13 +114,6 @@ namespace Bind.GL2
foreach (Function f in wrappers[key]) foreach (Function f in wrappers[key])
{ {
if (Settings.Compatibility != Settings.Legacy.Tao)
Utilities.StripGL2Extension(f);
if (f.Name == "ActiveTexture")
{
}
if (!f.CLSCompliant) if (!f.CLSCompliant)
{ {
sw.WriteLine("[System.CLSCompliant(false)]"); sw.WriteLine("[System.CLSCompliant(false)]");

View file

@ -4,7 +4,7 @@ using System.Text;
namespace Bind namespace Bind
{ {
interface IBind interface IBind : ISpecReader, ISpecWriter
{ {
//ISpecReader SpecReader { get; } //ISpecReader SpecReader { get; }
void Process(); void Process();

View file

@ -50,6 +50,8 @@ namespace Bind
{ {
static GeneratorMode mode; static GeneratorMode mode;
static internal IBind Generator;
static void Main(string[] arguments) static void Main(string[] arguments)
{ {
Debug.Listeners.Clear(); Debug.Listeners.Clear();
@ -65,8 +67,6 @@ namespace Bind
//Console.WriteLine(" - the OpenTK team ;-)"); //Console.WriteLine(" - the OpenTK team ;-)");
Console.WriteLine(); Console.WriteLine();
IBind bind;
#region Handle Arguments #region Handle Arguments
try try
@ -141,14 +141,14 @@ namespace Bind
switch (mode) switch (mode)
{ {
case GeneratorMode.GL2: case GeneratorMode.GL2:
bind = new Bind.GL2.Generator(Settings.InputPath); Generator = new Bind.GL2.Generator(Settings.InputPath);
break; break;
default: default:
throw new NotImplementedException(String.Format("Mode {0} not implemented.", mode)); throw new NotImplementedException(String.Format("Mode {0} not implemented.", mode));
} }
bind.Process(); Generator.Process();
ticks = System.DateTime.Now.Ticks - ticks; ticks = System.DateTime.Now.Ticks - ticks;

View file

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("0.9.5.1")] [assembly: AssemblyVersion("0.9.7.1")]
[assembly: AssemblyFileVersion("0.9.5.1")] [assembly: AssemblyFileVersion("0.9.7.1")]

View file

@ -15,6 +15,13 @@ namespace Bind
public static string OutputPath = "..\\..\\..\\Source\\OpenTK\\OpenGL\\Bindings"; public static string OutputPath = "..\\..\\..\\Source\\OpenTK\\OpenGL\\Bindings";
public static string OutputNamespace = "OpenTK.OpenGL"; public static string OutputNamespace = "OpenTK.OpenGL";
public static string GLClass = "GL"; public static string GLClass = "GL";
private static string enumsClass = "Enums";
public static string GLEnumsClass
{
get { return GLClass + "." + enumsClass; }
set { enumsClass = value; }
}
public static string DelegatesClass = "Delegates"; public static string DelegatesClass = "Delegates";
public static string ImportsClass = "Imports"; public static string ImportsClass = "Imports";
public static string WglClass = "Wgl"; public static string WglClass = "Wgl";

View file

@ -1,6 +1,7 @@
#region License #region --- License ---
//Copyright (c) 2006 Stefanos Apostolopoulos /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
//See license.txt for license info * See license.txt for license info
*/
#endregion #endregion
using System; using System;
@ -8,6 +9,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
namespace Bind.Structures namespace Bind.Structures
{ {
@ -17,6 +19,22 @@ namespace Bind.Structures
/// </summary> /// </summary>
public class Delegate public class Delegate
{ {
internal static DelegateCollection Delegates;
private static bool delegatesLoaded;
internal static void Initialize()
{
if (!delegatesLoaded)
{
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\gl.spec"))
{
Delegates = Bind.MainClass.Generator.ReadDelegates(sr);
}
delegatesLoaded = true;
}
}
#region --- Constructors --- #region --- Constructors ---
public Delegate() public Delegate()
@ -29,9 +47,9 @@ namespace Bind.Structures
this.Category = new string(d.Category.ToCharArray()); this.Category = new string(d.Category.ToCharArray());
//this.Extension = !String.IsNullOrEmpty(d.Extension) ? new string(d.Extension.ToCharArray()) : ""; //this.Extension = !String.IsNullOrEmpty(d.Extension) ? new string(d.Extension.ToCharArray()) : "";
this.Name = new string(d.Name.ToCharArray()); this.Name = new string(d.Name.ToCharArray());
this.NeedsWrapper = d.NeedsWrapper; //this.NeedsWrapper = d.NeedsWrapper;
this.Parameters = new ParameterCollection(d.Parameters); this.Parameters = new ParameterCollection(d.Parameters);
this.ReturnType = new Parameter(d.ReturnType); this.ReturnType = new Type(d.ReturnType);
this.Version = !String.IsNullOrEmpty(d.Version) ? new string(d.Version.ToCharArray()) : ""; this.Version = !String.IsNullOrEmpty(d.Version) ? new string(d.Version.ToCharArray()) : "";
//this.Unsafe = d.Unsafe; //this.Unsafe = d.Unsafe;
} }
@ -89,8 +107,24 @@ namespace Bind.Structures
/// </summary> /// </summary>
public bool NeedsWrapper public bool NeedsWrapper
{ {
get { return _needs_wrapper; } //get { return _needs_wrapper; }
set { _needs_wrapper = value; } //set { _needs_wrapper = value; }
get
{
// TODO: Add special cases for (Get)ShaderSource.
if (ReturnType.WrapperType != WrapperTypes.None)
return true;
foreach (Parameter p in Parameters)
{
if (p.WrapperType != WrapperTypes.None)
return true;
}
return false;
}
} }
#endregion #endregion
@ -125,28 +159,28 @@ namespace Bind.Structures
#region public Parameter ReturnType #region public Parameter ReturnType
Parameter _return_type = new Parameter(); Type _return_type = new Type();
/// <summary> /// <summary>
/// Gets or sets the return value of the opengl function. /// Gets or sets the return value of the opengl function.
/// </summary> /// </summary>
public Parameter ReturnType public Type ReturnType
{ {
get { return _return_type; } get { return _return_type; }
set set
{ {
_return_type = value; _return_type = Type.Translate(value);
} }
} }
#endregion #endregion
#region public string Name #region public virtual string Name
string _name; string _name;
/// <summary> /// <summary>
/// Gets or sets the name of the opengl function. /// Gets or sets the name of the opengl function.
/// </summary> /// </summary>
public string Name public virtual string Name
{ {
get { return _name; } get { return _name; }
set set
@ -165,7 +199,7 @@ namespace Bind.Structures
public ParameterCollection Parameters public ParameterCollection Parameters
{ {
get { return _parameters; } get { return _parameters; }
set { _parameters = value; } protected set { _parameters = value; }
} }
#endregion #endregion
@ -222,51 +256,7 @@ namespace Bind.Structures
sb.Append(Settings.DelegatesClass); sb.Append(Settings.DelegatesClass);
sb.Append(".gl"); sb.Append(".gl");
sb.Append(Name); sb.Append(Name);
sb.Append("("); sb.Append(Parameters.CallString());
if (this.Name == "CallLists")
{
}
if (Parameters.Count > 0)
{
foreach (Parameter p in Parameters)
{
if (p.Unchecked)
sb.Append("unchecked((" + p.Type + ")");
if (p.Type != "object")
{
if (p.Type.ToLower().Contains("string"))
{
sb.Append(String.Format(
"({0}{1})",
p.Type,
(p.Array > 0) ? "[]" : ""));
}
else
{
sb.Append(String.Format(
"({0}{1})",
p.Type,
(p.Pointer || p.Array > 0 || p.Reference) ? "*" : ""));
}
}
sb.Append(
Utilities.Keywords.Contains(p.Name) ? "@" + p.Name : p.Name
);
if (p.Unchecked)
sb.Append(")");
sb.Append(", ");
}
sb.Replace(", ", ")", sb.Length - 2, 2);
}
else
{
sb.Append(")");
}
return sb.ToString(); return sb.ToString();
} }
@ -312,16 +302,16 @@ namespace Bind.Structures
#endregion #endregion
public Delegate GetCLSCompliantDelegate(Dictionary<string, string> CSTypes) public Delegate GetCLSCompliantDelegate()
{ {
Delegate f = new Delegate(this); Delegate f = new Delegate(this);
for (int i = 0; i < f.Parameters.Count; i++) for (int i = 0; i < f.Parameters.Count; i++)
{ {
f.Parameters[i].Type = f.Parameters[i].GetCLSCompliantType(CSTypes); f.Parameters[i].CurrentType = f.Parameters[i].GetCLSCompliantType();
} }
f.ReturnType.Type = f.ReturnType.GetCLSCompliantType(CSTypes); f.ReturnType.CurrentType = f.ReturnType.GetCLSCompliantType();
return f; return f;
} }
@ -330,11 +320,11 @@ namespace Bind.Structures
#region --- Wrapper Creation --- #region --- Wrapper Creation ---
#region public List<Function> CreateWrappers(Dictionary<string, string> CSTypes) #region public IEnumerable<Function> CreateWrappers()
public List<Function> CreateWrappers(Dictionary<string, string> CSTypes) public IEnumerable<Function> CreateWrappers()
{ {
if (this.Name == "MapBuffer") if (this.Name.Contains("GetString"))
{ {
} }
@ -344,7 +334,7 @@ namespace Bind.Structures
// No special wrapper needed - just call this delegate: // No special wrapper needed - just call this delegate:
Function f = new Function(this); Function f = new Function(this);
if (f.ReturnType.Type.ToLower().Contains("void")) if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", f.CallString())); f.Body.Add(String.Format("{0};", f.CallString()));
else else
f.Body.Add(String.Format("return {0};", f.CallString())); f.Body.Add(String.Format("return {0};", f.CallString()));
@ -353,57 +343,10 @@ namespace Bind.Structures
} }
else else
{ {
// We have to add wrappers for all possible WrapperTypes. Function f = WrapReturnType();
Function f;
// First, check if the return type needs wrapping:
switch (this.ReturnType.WrapperType)
{
// If the function returns a string (glGetString) we must manually marshal it
// using Marshal.PtrToStringXXX. Otherwise, the GC will try to free the memory
// used by the string, resulting in corruption (the memory belongs to the
// unmanaged boundary).
case WrapperTypes.StringReturnType:
f = new Function(this);
f.ReturnType.Type = "System.String";
f.Body.Add( WrapParameters(new Function((Function)f ?? this), wrappers);
String.Format(
"return System.Runtime.InteropServices.Marshal.PtrToStringAnsi({0});",
this.CallString()
)
);
wrappers.Add(f);
return wrappers; // Only occurs in glGetString, there's no need to check parameters.
// If the function returns a void* (GenericReturnValue), we'll have to return an IntPtr.
// The user will unfortunately need to marshal this IntPtr to a data type manually.
case WrapperTypes.GenericReturnType:
ReturnType.Type = "IntPtr";
ReturnType.Pointer = false;
/*
f = new Function(this);
f.ReturnType.Type = "IntPtr";
f.ReturnType.Pointer = false;
if (f.ReturnType.Type.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", f.CallString()));
else
f.Body.Add(String.Format("return {0};", f.CallString()));
wrappers.Add(f);
*/
break;
case WrapperTypes.None:
default:
// No return wrapper needed
break;
}
// Then, create wrappers for each parameter:
WrapParameters(new Function(this), wrappers, CSTypes);
} }
return wrappers; return wrappers;
@ -411,6 +354,52 @@ namespace Bind.Structures
#endregion #endregion
#region protected Function WrapReturnType()
protected Function WrapReturnType()
{
// We have to add wrappers for all possible WrapperTypes.
Function f;
// First, check if the return type needs wrapping:
switch (this.ReturnType.WrapperType)
{
// If the function returns a string (glGetString) we must manually marshal it
// using Marshal.PtrToStringXXX. Otherwise, the GC will try to free the memory
// used by the string, resulting in corruption (the memory belongs to the
// unmanaged boundary).
case WrapperTypes.StringReturnType:
f = new Function(this);
f.ReturnType.CurrentType = "System.String";
f.Body.Add(
String.Format(
"return System.Runtime.InteropServices.Marshal.PtrToStringAnsi({0});",
this.CallString()
)
);
return f; // Only occurs in glGetString, there's no need to check parameters.
// If the function returns a void* (GenericReturnValue), we'll have to return an IntPtr.
// The user will unfortunately need to marshal this IntPtr to a data type manually.
case WrapperTypes.GenericReturnType:
ReturnType.CurrentType = "IntPtr";
ReturnType.Pointer = false;
break;
case WrapperTypes.None:
default:
// No return wrapper needed
break;
}
return null;
}
#endregion
#region protected void WrapParameters(Function function, List<Function> wrappers) #region protected void WrapParameters(Function function, List<Function> wrappers)
protected static int index = 0; protected static int index = 0;
@ -425,9 +414,9 @@ namespace Bind.Structures
/// "void f(object p, IntPtr q)" /// "void f(object p, IntPtr q)"
/// "void f(object p, object q)" /// "void f(object p, object q)"
/// </summary> /// </summary>
protected void WrapParameters(Function function, List<Function> wrappers, Dictionary<string, string> CSTypes) protected void WrapParameters(Function function, List<Function> wrappers)
{ {
if (function.Name == "LineStipple") if (function.Name == "GetString")
{ {
} }
@ -451,7 +440,10 @@ namespace Bind.Structures
} }
else else
{ {
wrappers.Add(DefaultWrapper(function)); if (function.Body.Count == 0)
wrappers.Add(DefaultWrapper(function));
else
wrappers.Add(function);
return; return;
} }
} }
@ -464,7 +456,7 @@ namespace Bind.Structures
{ {
// No wrapper needed, visit the next parameter // No wrapper needed, visit the next parameter
++index; ++index;
WrapParameters(function, wrappers, CSTypes); WrapParameters(function, wrappers);
--index; --index;
} }
else else
@ -474,25 +466,25 @@ namespace Bind.Structures
case WrapperTypes.ArrayParameter: case WrapperTypes.ArrayParameter:
// Recurse to the last parameter // Recurse to the last parameter
++index; ++index;
WrapParameters(function, wrappers, CSTypes); WrapParameters(function, wrappers);
--index; --index;
// On stack rewind, create array wrappers // On stack rewind, create array wrappers
f = ArrayWrapper(new Function(function), index, CSTypes); f = ArrayWrapper(new Function(function), index);
wrappers.Add(f); wrappers.Add(f);
// Recurse to the last parameter again, keeping the Array wrappers // Recurse to the last parameter again, keeping the Array wrappers
++index; ++index;
WrapParameters(f, wrappers, CSTypes); WrapParameters(f, wrappers);
--index; --index;
// On stack rewind, create Ref wrappers. // On stack rewind, create Ref wrappers.
f = ReferenceWrapper(new Function(function), index, CSTypes); f = ReferenceWrapper(new Function(function), index);
wrappers.Add(f); wrappers.Add(f);
// Keeping the current Ref wrapper, visit all other parameters once more // Keeping the current Ref wrapper, visit all other parameters once more
++index; ++index;
WrapParameters(f, wrappers, CSTypes); WrapParameters(f, wrappers);
--index; --index;
break; break;
@ -500,16 +492,16 @@ namespace Bind.Structures
case WrapperTypes.GenericParameter: case WrapperTypes.GenericParameter:
// Recurse to the last parameter // Recurse to the last parameter
++index; ++index;
WrapParameters(function, wrappers, CSTypes); WrapParameters(function, wrappers);
--index; --index;
// On stack rewind, create array wrappers // On stack rewind, create array wrappers
f = GenericWrapper(new Function(function), index, CSTypes); f = GenericWrapper(new Function(function), index);
wrappers.Add(f); wrappers.Add(f);
// Keeping the current Object wrapper, visit all other parameters once more // Keeping the current Object wrapper, visit all other parameters once more
++index; ++index;
WrapParameters(f, wrappers, CSTypes); WrapParameters(f, wrappers);
--index; --index;
break; break;
@ -520,31 +512,31 @@ namespace Bind.Structures
#endregion #endregion
#region protected Function GenericWrapper(Function function, int index, Dictionary<string, string> CSTypes) #region protected Function GenericWrapper(Function function, int index)
protected Function GenericWrapper(Function function, int index, Dictionary<string, string> CSTypes) protected Function GenericWrapper(Function function, int index)
{ {
// Search and replace IntPtr parameters with the known parameter types: // Search and replace IntPtr parameters with the known parameter types:
function.Parameters[index].Reference = false; function.Parameters[index].Reference = false;
function.Parameters[index].Array = 0; function.Parameters[index].Array = 0;
function.Parameters[index].Pointer = false; function.Parameters[index].Pointer = false;
function.Parameters[index].Type = "object"; function.Parameters[index].CurrentType = "object";
function.Parameters[index].Flow = Parameter.FlowDirection.Undefined; function.Parameters[index].Flow = Parameter.FlowDirection.Undefined;
// In the function body we should pin all objects in memory before calling the // In the function body we should pin all objects in memory before calling the
// low-level function. // low-level function.
function.Body.Clear(); function.Body.Clear();
//function.Body.AddRange(GetBodyWithFixedPins(function)); //function.Body.AddRange(GetBodyWithFixedPins(function));
function.Body.AddRange(GetBodyWithPins(function, CSTypes, false)); function.Body.AddRange(function.GetBodyWithPins(false));
return function; return function;
} }
#endregion #endregion
#region protected Function ReferenceWrapper(Function function, int index, Dictionary<string, string> CSTypes) #region protected Function ReferenceWrapper(Function function, int index)
protected Function ReferenceWrapper(Function function, int index, Dictionary<string, string> CSTypes) protected Function ReferenceWrapper(Function function, int index)
{ {
// Search and replace IntPtr parameters with the known parameter types: // Search and replace IntPtr parameters with the known parameter types:
function.Parameters[index].Reference = true; function.Parameters[index].Reference = true;
@ -554,16 +546,16 @@ namespace Bind.Structures
// In the function body we should pin all objects in memory before calling the // In the function body we should pin all objects in memory before calling the
// low-level function. // low-level function.
function.Body.Clear(); function.Body.Clear();
function.Body.AddRange(GetBodyWithPins(function, CSTypes, false)); function.Body.AddRange(function.GetBodyWithPins(false));
return function; return function;
} }
#endregion #endregion
#region protected Function ArrayWrapper(Function function, int index, Dictionary<string, string> CSTypes) #region protected Function ArrayWrapper(Function function, int index)
protected Function ArrayWrapper(Function function, int index, Dictionary<string, string> CSTypes) protected Function ArrayWrapper(Function function, int index)
{ {
// Search and replace IntPtr parameters with the known parameter types: // Search and replace IntPtr parameters with the known parameter types:
function.Parameters[index].Array = 1; function.Parameters[index].Array = 1;
@ -573,7 +565,7 @@ namespace Bind.Structures
// In the function body we should pin all objects in memory before calling the // In the function body we should pin all objects in memory before calling the
// low-level function. // low-level function.
function.Body.Clear(); function.Body.Clear();
function.Body.AddRange(GetBodyWithPins(function, CSTypes, false)); function.Body.AddRange(function.GetBodyWithPins(false));
return function; return function;
} }
@ -584,12 +576,12 @@ namespace Bind.Structures
protected Function DefaultWrapper(Function f) protected Function DefaultWrapper(Function f)
{ {
bool returns = f.ReturnType.Type.ToLower().Contains("void") && !f.ReturnType.Pointer; bool returns = f.ReturnType.CurrentType.ToLower().Contains("void") && !f.ReturnType.Pointer;
string callString = String.Format( string callString = String.Format(
"{0} {1}{2}; {3}", "{0} {1}{2}; {3}",
Unsafe ? "unsafe {" : "", Unsafe ? "unsafe {" : "",
returns ? "" : "return ", returns ? "" : "return ",
f.CallString(), this.CallString(),
Unsafe ? "}" : ""); Unsafe ? "}" : "");
f.Body.Add(callString); f.Body.Add(callString);
@ -599,22 +591,24 @@ namespace Bind.Structures
#endregion #endregion
#region protected static FunctionBody GetBodyWithPins(Function function, Dictionary<string, string> CSTypes, bool wantCLSCompliance) #region protected FunctionBody GetBodyWithPins(bool wantCLSCompliance)
/// <summary> /// <summary>
/// Generates a body which calls the specified function, pinning all needed parameters. /// Generates a body which calls the specified function, pinning all needed parameters.
/// </summary> /// </summary>
/// <param name="function"></param> /// <param name="function"></param>
protected static FunctionBody GetBodyWithPins(Function function, Dictionary<string, string> CSTypes, bool wantCLSCompliance) protected FunctionBody GetBodyWithPins(bool wantCLSCompliance)
{ {
// We'll make changes, but we want the original intact. // We'll make changes, but we want the original intact.
Function f = new Function(function); //Function function = this as Function ?? new Function(this);
//Function f = new Function(function);
Function f = new Function(this);
f.Body.Clear(); f.Body.Clear();
// Unsafe only if // Unsafe only if
//function.Unsafe = false; //function.Unsafe = false;
// Add default initliazers for out parameters: // Add default initliazers for out parameters:
foreach (Parameter p in function.Parameters) foreach (Parameter p in this.Parameters)
{ {
if (p.Flow == Parameter.FlowDirection.Out) if (p.Flow == Parameter.FlowDirection.Out)
{ {
@ -622,7 +616,7 @@ namespace Bind.Structures
String.Format( String.Format(
"{0} = default({1});", "{0} = default({1});",
p.Name, p.Name,
p.GetFullType(CSTypes, wantCLSCompliance) p.GetFullType(Bind.Structures.Type.CSTypes, wantCLSCompliance)
) )
); );
} }
@ -673,7 +667,9 @@ namespace Bind.Structures
f.Body.Add( f.Body.Add(
String.Format( String.Format(
" fixed ({0}* {1} = {2})", " fixed ({0}* {1} = {2})",
wantCLSCompliance && !p.CLSCompliant ? p.GetCLSCompliantType(CSTypes) : p.Type, wantCLSCompliance && !p.CLSCompliant ?
p.GetCLSCompliantType() :
p.CurrentType,
p.Name + "_ptr", p.Name + "_ptr",
p.Array > 0 ? p.Name : "&" + p.Name p.Array > 0 ? p.Name : "&" + p.Name
) )
@ -685,7 +681,7 @@ namespace Bind.Structures
} }
} }
if (!function.Unsafe) if (!this.Unsafe)
{ {
f.Body.Insert(handleEnd, "unsafe"); f.Body.Insert(handleEnd, "unsafe");
f.Body.Insert(handleEnd + 1, "{"); f.Body.Insert(handleEnd + 1, "{");
@ -698,13 +694,13 @@ namespace Bind.Structures
f.Body.Add(" {"); f.Body.Add(" {");
// Add delegate call: // Add delegate call:
if (f.ReturnType.Type.ToLower().Contains("void")) if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format(" {0};", f.CallString())); f.Body.Add(String.Format(" {0};", f.CallString()));
else else
f.Body.Add(String.Format(" {0} {1} = {2};", f.ReturnType.Type, "retval", f.CallString())); f.Body.Add(String.Format(" {0} {1} = {2};", f.ReturnType.CurrentType, "retval", f.CallString()));
// Assign out parameters: // Assign out parameters:
foreach (Parameter p in function.Parameters) foreach (Parameter p in this.Parameters)
{ {
if (p.Flow == Parameter.FlowDirection.Out) if (p.Flow == Parameter.FlowDirection.Out)
{ {
@ -718,7 +714,7 @@ namespace Bind.Structures
String.Format( String.Format(
" {0} = ({1}){2}.Target;", " {0} = ({1}){2}.Target;",
p.Name, p.Name,
p.Type, p.CurrentType,
p.Name + "_ptr" p.Name + "_ptr"
) )
); );
@ -737,7 +733,7 @@ namespace Bind.Structures
} }
// Return: // Return:
if (!f.ReturnType.Type.ToLower().Contains("void")) if (!f.ReturnType.CurrentType.ToLower().Contains("void"))
{ {
f.Body.Add(" return retval;"); f.Body.Add(" return retval;");
} }
@ -747,7 +743,7 @@ namespace Bind.Structures
f.Body.Add(" }"); f.Body.Add(" }");
f.Body.Add(" finally"); f.Body.Add(" finally");
f.Body.Add(" {"); f.Body.Add(" {");
foreach (Parameter p in function.Parameters) foreach (Parameter p in this.Parameters)
{ {
// Free all allocated GCHandles // Free all allocated GCHandles
if (p.NeedsPin) if (p.NeedsPin)
@ -761,7 +757,7 @@ namespace Bind.Structures
} }
f.Body.Add(" }"); f.Body.Add(" }");
if (!function.Unsafe) if (!this.Unsafe)
{ {
f.Body.Add("}"); f.Body.Add("}");
} }
@ -772,8 +768,146 @@ namespace Bind.Structures
#endregion #endregion
#endregion #endregion
/// <summary>
/// Translates the opengl return type to the equivalent C# type.
/// </summary>
/// <param name="d">The opengl function to translate.</param>
/// <remarks>
/// First, we use the official typemap (gl.tm) to get the correct type.
/// Then we override this, when it is:
/// 1) A string (we have to use Marshal.PtrToStringAnsi, to avoid heap corruption)
/// 2) An array (translates to IntPtr)
/// 3) A generic object or void* (translates to IntPtr)
/// 4) A GLenum (translates to int on Legacy.Tao or GL.Enums.GLenum otherwise).
/// Return types must always be CLS-compliant, because .Net does not support overloading on return types.
/// </remarks>
protected virtual void TranslateReturnType()
{
if (Bind.Structures.Type.GLTypes.ContainsKey(ReturnType.CurrentType))
ReturnType.CurrentType = Bind.Structures.Type.GLTypes[ReturnType.CurrentType];
if (Bind.Structures.Type.CSTypes.ContainsKey(ReturnType.CurrentType))
ReturnType.CurrentType = Bind.Structures.Type.CSTypes[ReturnType.CurrentType];
if (ReturnType.CurrentType.ToLower().Contains("void") && ReturnType.Pointer)
{
ReturnType.WrapperType = WrapperTypes.GenericReturnType;
}
if (ReturnType.CurrentType.ToLower().Contains("string"))
{
ReturnType.CurrentType = "IntPtr";
ReturnType.WrapperType = WrapperTypes.StringReturnType;
}
if (ReturnType.CurrentType.ToLower().Contains("object"))
{
ReturnType.CurrentType = "IntPtr";
ReturnType.WrapperType |= WrapperTypes.GenericReturnType;
}
if (ReturnType.CurrentType.Contains("GLenum"))
{
if (Settings.Compatibility == Settings.Legacy.None)
ReturnType.CurrentType = ReturnType.CurrentType.Insert(0, Settings.GLEnumsClass + ".");
else
ReturnType.CurrentType = "int";
}
if (ReturnType.CurrentType.ToLower().Contains("bool"))
{
if (Settings.Compatibility == Settings.Legacy.Tao)
ReturnType.CurrentType = "int";
else
{
}
//ReturnType.WrapperType = WrapperTypes.ReturnsBool;
}
ReturnType.CurrentType = ReturnType.GetCLSCompliantType();
}
protected virtual void TranslateParameters()
{
if (this.Name.Contains("MultiTexCoord1"))
{
}
for (int i = 0; i < Parameters.Count; i++)
{
Parameters[i] = Parameter.Translate(Parameters[i], this.Category);
// Special cases: glLineStipple and gl(Get)ShaderSource:
// Check for LineStipple (should be unchecked)
if (Parameters[i].CurrentType == "UInt16" && Name.Contains("LineStipple"))
{
Parameters[i].WrapperType = WrapperTypes.UncheckedParameter;
}
if (Name.Contains("ShaderSource") && Parameters[i].CurrentType.ToLower().Contains("string"))
{
// Special case: these functions take a string[]
//IsPointer = true;
Parameters[i].Array = 1;
}
}
}
internal void Translate()
{
TranslateReturnType();
TranslateParameters();
List<Function> wrappers = (List<Function>)CreateWrappers();
// If the function is not CLS-compliant (e.g. it contains unsigned parameters)
// we need to create a CLS-Compliant overload. However, we should only do this
// iff the opengl function does not contain unsigned/signed overloads itself
// to avoid redefinitions.
foreach (Function f in wrappers)
{
if (this.Name.Contains("Weightub"))
{
}
bool createCLS = !f.CLSCompliant;
//createCLS &= String.IsNullOrEmpty(f.TrimmedName);
string nameWithoutExtension = Utilities.StripGL2Extension(f.Name).TrimEnd('v');
createCLS &=
String.IsNullOrEmpty(f.TrimmedName) ||
nameWithoutExtension.EndsWith("u") &&
!nameWithoutExtension.EndsWith("b");
if (createCLS)
{
Function clsFunction = f.GetCLSCompliantFunction(Bind.Structures.Type.CSTypes);
// avoid redefinitions
if (clsFunction.Parameters.ToString(true) != f.Parameters.ToString(true))
{
bool defined = false;
if (Bind.Structures.Function.Wrappers.ContainsKey(f.Extension))
{
foreach (Function fun in Bind.Structures.Function.Wrappers[clsFunction.Extension])
{
if (clsFunction.Name == fun.Name &&
clsFunction.Parameters.ToString() == fun.Parameters.ToString())
defined = true;
}
}
if (!defined)
Bind.Structures.Function.Wrappers.Add(clsFunction);
//wrappers.Add(f);
}
}
Bind.Structures.Function.Wrappers.Add(f);
}
}
} }
#region class DelegateCollection : Dictionary<string, Delegate>
class DelegateCollection : Dictionary<string, Delegate> class DelegateCollection : Dictionary<string, Delegate>
{ {
public void Add(Delegate d) public void Add(Delegate d)
@ -790,4 +924,6 @@ namespace Bind.Structures
} }
} }
} }
#endregion
} }

View file

@ -6,6 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO;
namespace Bind.Structures namespace Bind.Structures
{ {
@ -13,6 +14,33 @@ namespace Bind.Structures
public class Enum public class Enum
{ {
internal static EnumCollection GLEnums;
private static bool enumsLoaded;
internal static void Initialize()
{
if (!enumsLoaded)
{
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\enum.spec"))
{
GLEnums = Bind.MainClass.Generator.ReadEnums(sr);
}
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\enumext.spec"))
{
foreach (Bind.Structures.Enum e in Bind.MainClass.Generator.ReadEnums(sr).Values)
{
//enums.Add(e.Name, e);
Utilities.Merge(GLEnums, e);
}
}
enumsLoaded = true;
}
}
public Enum() public Enum()
{ } { }
@ -61,19 +89,40 @@ namespace Bind.Structures
class EnumCollection : Dictionary<string, Enum> class EnumCollection : Dictionary<string, Enum>
{ {
/* internal void AddRange(EnumCollection enums)
public override string ToString()
{ {
StringBuilder sb = new StringBuilder(); foreach (Enum e in enums.Values)
foreach (Bind.Structures.Enum e in this.Values)
{ {
sb.AppendLine(e.ToString()); Utilities.Merge(this, e);
}
}
internal void Translate()
{
foreach (Enum e in this.Values)
{
foreach (Constant c in e.ConstantCollection.Values)
{
// There are cases when a value is an aliased constant, with no enum specified.
// (e.g. FOG_COORD_ARRAY_TYPE = GL_FOG_COORDINATE_ARRAY_TYPE)
// In this case try searching all enums for the correct constant to alias (stupid opengl specs).
if (String.IsNullOrEmpty(c.Reference) && !Char.IsDigit(c.Value[0]))
{
foreach (Enum @enum in this.Values)
{
// Skip generic GLenum
if (@enum.Name == "GLenum")
continue;
if (@enum.ConstantCollection.ContainsKey(c.Value))
{
c.Reference = @enum.Name;
}
}
}
}
} }
return sb.ToString();
} }
*/
} }
#endregion #endregion

View file

@ -1,11 +1,51 @@
using System; #region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace Bind.Structures namespace Bind.Structures
{ {
public class Function : Delegate public class Function : Delegate
{ {
internal static FunctionCollection Wrappers;
private static bool loaded;
internal static void Initialize()
{
if (!loaded)
{
Wrappers = new FunctionCollection();
loaded = true;
}
}
private static List<string> endings = new List<string>(
new string[]
{
"fv",
"f",
"dv",
"d",
"i",
"iv",
"s",
"sv",
"b",
"bv",
"ui",
"uiv",
"us",
"usv",
"ub",
"ubv"
});
#region --- Constructors --- #region --- Constructors ---
public Function() public Function()
@ -13,21 +53,28 @@ namespace Bind.Structures
{ {
Body = new FunctionBody(); Body = new FunctionBody();
} }
/*
public Function(Function f) public Function(Function f)
: base(f) : base(f)
{ {
this.Body = new FunctionBody(f.Body); this.Body = new FunctionBody(f.Body);
this.Name = f.Name;
} }
*/
public Function(Delegate d) public Function(Delegate d)
: base(d) : base(d)
{ {
this.Body = new FunctionBody(); if (d is Function)
this.Body = new FunctionBody((d as Function).Body);
else
this.Body = new FunctionBody();
this.Name = d.Name;
} }
#endregion #endregion
#region public override bool Unsafe
public override bool Unsafe public override bool Unsafe
{ {
get get
@ -39,7 +86,9 @@ namespace Bind.Structures
} }
} }
#region Function body #endregion
#region public FunctionBody Body
FunctionBody _body; FunctionBody _body;
@ -51,6 +100,82 @@ namespace Bind.Structures
#endregion #endregion
#region public string TrimmedName
string trimmedName;
/// <summary>
/// Gets or sets the name of the opengl function, trimming the excess 234dfubsiv endings..
/// </summary>
public string TrimmedName
{
get { return trimmedName; }
set
{
if (!String.IsNullOrEmpty(value))
trimmedName = value.Trim();
}
}
#endregion
#region public override string Name
/// <summary>
/// Gets or sets the name of the opengl function.
/// If no Tao compatibility is set, set TrimmedName to Name, after removing
/// [u][bsifd][v].
/// </summary>
public override string Name
{
get { return base.Name; }
set
{
base.Name = value;
// If we don't need compatibility with Tao,
// remove the Extension and the overload information from the name
// (Extension == "ARB", "EXT", etc, overload == [u][bsidf][v])
// TODO: Use some regex's here, to reduce clutter.
if (Settings.Compatibility != Settings.Legacy.Tao)
{
string ext = Utilities.GetGL2Extension(value);
string trimmedName = value;
// Remove extension
if (!String.IsNullOrEmpty(ext))
{
trimmedName = trimmedName.Substring(0, trimmedName.Length - ext.Length);
}
// Remove overload
if (endings.Contains(trimmedName.Substring(trimmedName.Length - 3)))
{
TrimmedName = trimmedName.Substring(0, trimmedName.Length - 3);
return;
}
if (endings.Contains(trimmedName.Substring(trimmedName.Length - 2)))
{
TrimmedName = trimmedName.Substring(0, trimmedName.Length - 2);
return;
}
if (endings.Contains(trimmedName.Substring(trimmedName.Length - 1)))
{
// An ending 's' may be either a plural form (glCallLists), which we
// do not want to change, or an actual overload (glColor3s). We assume
// (perhaps incorrectly), that an 's' preceeded be a digit indicates an
// overload. If there is no digit, we assume a plural form (no change).
if (Char.IsDigit(trimmedName[trimmedName.Length - 2]))
TrimmedName = trimmedName.Substring(0, trimmedName.Length - 1);
return;
}
}
}
}
#endregion
#region public override string ToString() #region public override string ToString()
public override string ToString() public override string ToString()
@ -64,7 +189,7 @@ namespace Bind.Structures
{ {
sb.Append("gl"); sb.Append("gl");
} }
sb.Append(Name); sb.Append(!String.IsNullOrEmpty(TrimmedName) ? TrimmedName : Name);
sb.Append(Parameters.ToString(true)); sb.Append(Parameters.ToString(true));
if (Body.Count > 0) if (Body.Count > 0)
{ {
@ -85,17 +210,17 @@ namespace Bind.Structures
for (int i = 0; i < f.Parameters.Count; i++) for (int i = 0; i < f.Parameters.Count; i++)
{ {
f.Parameters[i].Type = f.Parameters[i].GetCLSCompliantType(CSTypes); f.Parameters[i].CurrentType = f.Parameters[i].GetCLSCompliantType();
} }
f.Body.Clear(); f.Body.Clear();
if (!f.NeedsWrapper) if (!f.NeedsWrapper)
{ {
f.Body.Add((f.ReturnType.Type != "void" ? "return " + this.CallString() : this.CallString()) + ";"); f.Body.Add((f.ReturnType.CurrentType != "void" ? "return " + this.CallString() : this.CallString()) + ";");
} }
else else
{ {
f.Body.AddRange(Function.GetBodyWithPins(this, CSTypes, true)); f.Body.AddRange(this.GetBodyWithPins(true));
} }
// The type system cannot differentiate between functions with the same parameters // The type system cannot differentiate between functions with the same parameters
@ -144,6 +269,8 @@ namespace Bind.Structures
#endregion #endregion
#region class FunctionCollection : Dictionary<string, List<Function>>
class FunctionCollection : Dictionary<string, List<Function>> class FunctionCollection : Dictionary<string, List<Function>>
{ {
public void Add(Function f) public void Add(Function f)
@ -167,4 +294,6 @@ namespace Bind.Structures
} }
} }
} }
#endregion
} }

View file

@ -15,7 +15,7 @@ namespace Bind.Structures
/// <summary> /// <summary>
/// Represents a single parameter of an opengl function. /// Represents a single parameter of an opengl function.
/// </summary> /// </summary>
public class Parameter public class Parameter : Type
{ {
#region Constructors #region Constructors
@ -23,6 +23,7 @@ namespace Bind.Structures
/// Creates a new Parameter without type and name. /// Creates a new Parameter without type and name.
/// </summary> /// </summary>
public Parameter() public Parameter()
:base()
{ {
} }
@ -31,28 +32,20 @@ namespace Bind.Structures
/// </summary> /// </summary>
/// <param name="p">The parameter to copy from.</param> /// <param name="p">The parameter to copy from.</param>
public Parameter(Parameter p) public Parameter(Parameter p)
: base(p)
{ {
if (p == null) if (p == null)
return; return;
this.Name = !String.IsNullOrEmpty(p.Name) ? new string(p.Name.ToCharArray()) : ""; this.Name = !String.IsNullOrEmpty(p.Name) ? new string(p.Name.ToCharArray()) : "";
//this.NeedsWrapper = p.NeedsWrapper;
this.PreviousType = !String.IsNullOrEmpty(p.PreviousType) ? new string(p.PreviousType.ToCharArray()) : "";
this.Unchecked = p.Unchecked; this.Unchecked = p.Unchecked;
this.UnmanagedType = p.UnmanagedType; this.UnmanagedType = p.UnmanagedType;
this.WrapperType = p.WrapperType;
this.Type = new string(p.Type.ToCharArray());
this.Flow = p.Flow; this.Flow = p.Flow;
this.Array = p.Array;
this.Pointer = p.Pointer;
this.Reference = p.Reference;
} }
#endregion #endregion
#region Name property #region public string Name
string _name; string _name;
/// <summary> /// <summary>
@ -72,7 +65,7 @@ namespace Bind.Structures
/// <summary> /// <summary>
/// Gets or sets the name of the parameter. /// Gets or sets the name of the parameter.
/// </summary> /// </summary>
public UnmanagedType UnmanagedType private UnmanagedType UnmanagedType
{ {
get { return _unmanaged_type; } get { return _unmanaged_type; }
set { _unmanaged_type = value; } set { _unmanaged_type = value; }
@ -80,61 +73,7 @@ namespace Bind.Structures
#endregion #endregion
#region Type property #region public FlowDirection Flow
string _type;
/// <summary>
/// Gets the type of the parameter.
/// </summary>
public string Type
{
//get { return _type; }
get
{
//if (Pointer && Settings.Compatibility == Settings.Legacy.Tao)
// return "IntPtr";
return _type;
}
set
{
if (!String.IsNullOrEmpty(_type))
PreviousType = _type;
if (!String.IsNullOrEmpty(value))
_type = value.Trim();
if (_type.EndsWith("*"))
{
_type = _type.TrimEnd('*');
Pointer = true;
}
clsCompliant =
!(
(Pointer && (Settings.Compatibility != Settings.Legacy.Tao)) ||
(Type.Contains("GLu") && !Type.Contains("GLubyte")) ||
Type == "GLbitfield" ||
Type.Contains("GLhandle") ||
Type.Contains("GLhalf") ||
Type == "GLbyte");
}
}
#endregion
#region Previous type property
private string _previous_type;
public string PreviousType
{
get { return _previous_type; }
set { _previous_type = value; }
}
#endregion
#region Flow property
/// <summary> /// <summary>
/// Enumarates the possible flows of a parameter (ie. is this parameter /// Enumarates the possible flows of a parameter (ie. is this parameter
@ -160,49 +99,14 @@ namespace Bind.Structures
#endregion #endregion
#region public bool Reference
bool reference;
public bool Reference
{
get { return reference; }
set { reference = value; }
}
#endregion
#region public bool Array
int array;
public int Array
{
get { return array; }
set { array = value > 0 ? value : 0; }
}
#endregion
#region public bool Pointer
bool pointer = false;
public bool Pointer
{
get { return pointer; }
set { pointer = value; }
}
#endregion
#region public bool NeedsPin #region public bool NeedsPin
public bool NeedsPin public bool NeedsPin
{ {
get { return get { return
(Array > 0 || Reference || Type == "object") && (Array > 0 || Reference || CurrentType == "object") &&
!Type.ToLower().Contains("string"); } !CurrentType.ToLower().Contains("string");
}
} }
#endregion #endregion
@ -219,33 +123,6 @@ namespace Bind.Structures
#endregion #endregion
#region WrapperType property
private WrapperTypes _wrapper_type = WrapperTypes.None;
public WrapperTypes WrapperType
{
get { return _wrapper_type; }
set { _wrapper_type = value; }
}
#endregion
#region public bool CLSCompliant
private bool clsCompliant;
public bool CLSCompliant
{
get
{
// Checked when setting the Type property.
return clsCompliant || (Pointer && Settings.Compatibility == Settings.Legacy.Tao);
}
}
#endregion
#region public string GetFullType() #region public string GetFullType()
public string GetFullType(Dictionary<string, string> CSTypes, bool compliant) public string GetFullType(Dictionary<string, string> CSTypes, bool compliant)
@ -256,13 +133,13 @@ namespace Bind.Structures
if (!compliant) if (!compliant)
{ {
return return
Type + CurrentType +
(Pointer ? "*" : "") + (Pointer ? "*" : "") +
(Array > 0 ? "[]" : ""); (Array > 0 ? "[]" : "");
} }
return return
GetCLSCompliantType(CSTypes) + GetCLSCompliantType() +
(Pointer ? "*" : "") + (Pointer ? "*" : "") +
(Array > 0 ? "[]" : ""); (Array > 0 ? "[]" : "");
@ -270,36 +147,6 @@ namespace Bind.Structures
#endregion #endregion
#region public string GetCLSCompliantType(Dictionary<string, string> CSTypes)
public string GetCLSCompliantType(Dictionary<string, string> CSTypes)
{
if (!CLSCompliant)
{
if (Pointer && Settings.Compatibility == Settings.Legacy.Tao)
return "IntPtr";
if (CSTypes.ContainsKey(Type))
{
switch (CSTypes[Type])
{
case "UInt16":
return "Int16";
case "UInt32":
return "Int32";
case "UInt64":
return "Int64";
case "SByte":
return "Byte";
}
}
}
return Type;
}
#endregion
#region override public string ToString() #region override public string ToString()
override public string ToString() override public string ToString()
@ -324,6 +171,11 @@ namespace Bind.Structures
//if (Flow == FlowDirection.Out && !Array && !(Type == "IntPtr")) //if (Flow == FlowDirection.Out && !Array && !(Type == "IntPtr"))
// sb.Append("out "); // sb.Append("out ");
if (Flow == FlowDirection.Out)
sb.Append("[Out] ");
else if (Flow == FlowDirection.Undefined)
sb.Append("[In, Out] ");
if (Reference) if (Reference)
{ {
if (Flow == FlowDirection.Out) if (Flow == FlowDirection.Out)
@ -340,14 +192,14 @@ namespace Bind.Structures
} }
else else
{ {
sb.Append(Type); sb.Append(CurrentType);
if (Array > 0) if (Array > 0)
sb.Append("[]"); sb.Append("[]");
} }
} }
else else
{ {
sb.Append(Type); sb.Append(CurrentType);
if (Pointer) if (Pointer)
sb.Append("*"); sb.Append("*");
if (Array > 0) if (Array > 0)
@ -363,6 +215,87 @@ namespace Bind.Structures
} }
#endregion #endregion
internal static Parameter Translate(Parameter par, string Category)
{
Enum @enum;
string s;
Parameter p = new Parameter(par);
// Translate enum types
if (Enum.GLEnums.TryGetValue(p.CurrentType, out @enum) && @enum.Name != "GLenum")
{
if (Settings.Compatibility == Settings.Legacy.Tao)
p.CurrentType = "int";
else
p.CurrentType = p.CurrentType.Insert(0, String.Format("{0}.", Settings.GLEnumsClass));
}
else if (Bind.Structures.Type.GLTypes.TryGetValue(p.CurrentType, out s))
{
// Check if the parameter is a generic GLenum. If yes,
// check if a better match exists:
if (s.Contains("GLenum") && !String.IsNullOrEmpty(Category))
{
if (Settings.Compatibility == Settings.Legacy.None)
{
// Better match: enum.Name == function.Category (e.g. GL_VERSION_1_1 etc)
if (Enum.GLEnums.ContainsKey(Category))
{
p.CurrentType = String.Format("{0}.{1}", Settings.GLEnumsClass, Category);
}
else
{
p.CurrentType = String.Format("{0}.GLenum", Settings.GLEnumsClass);
}
}
else
{
p.CurrentType = "int";
}
}
else
{
// This is not enum, default translation:
p.CurrentType = s;
p.CurrentType =
Bind.Structures.Type.CSTypes.ContainsKey(p.CurrentType) ?
Bind.Structures.Type.CSTypes[p.CurrentType] : p.CurrentType;
}
}
//if (CSTypes.ContainsKey(p.CurrentType))
// p.CurrentType = CSTypes[p.CurrentType];
// Translate pointer parameters
if (p.Pointer)
{
p.WrapperType = WrapperTypes.ArrayParameter;
if (p.CurrentType.ToLower().Contains("char") || p.CurrentType.ToLower().Contains("string"))
{
// char* or string -> [In] String or [Out] StringBuilder
p.CurrentType =
p.Flow == Parameter.FlowDirection.Out ?
"System.Text.StringBuilder" :
"System.String";
p.Pointer = false;
p.WrapperType = WrapperTypes.None;
}
else if (p.CurrentType.ToLower().Contains("void"))
{
p.WrapperType = WrapperTypes.GenericParameter;
}
}
if (p.CurrentType.ToLower().Contains("bool"))
{
// Is this actually used anywhere?
p.WrapperType = WrapperTypes.BoolParameter;
}
return p;
}
} }
#endregion #endregion
@ -398,17 +331,12 @@ namespace Bind.Structures
/// <returns>The parameter list of an opengl function in the form ( [parameters] )</returns> /// <returns>The parameter list of an opengl function in the form ( [parameters] )</returns>
override public string ToString() override public string ToString()
{ {
return ToString(false, null); return ToString(false);
} }
#endregion #endregion
public string ToString(bool taoCompatible) #region public string ToString(bool taoCompatible)
{
return ToString(true, null);
}
#region public string ToString(bool taoCompatible, Dictionary<string, string> CSTypes)
/// <summary> /// <summary>
/// Gets the parameter declaration string. /// Gets the parameter declaration string.
@ -416,7 +344,7 @@ namespace Bind.Structures
/// <param name="getCLSCompliant">If true, all types will be replaced by their CLSCompliant C# equivalents</param> /// <param name="getCLSCompliant">If true, all types will be replaced by their CLSCompliant C# equivalents</param>
/// <param name="CSTypes">The list of C# types equivalent to the OpenGL types.</param> /// <param name="CSTypes">The list of C# types equivalent to the OpenGL types.</param>
/// <returns>The parameter list of an opengl function in the form ( [parameters] )</returns> /// <returns>The parameter list of an opengl function in the form ( [parameters] )</returns>
public string ToString(bool taoCompatible, Dictionary<string, string> CSTypes) public string ToString(bool taoCompatible)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("("); sb.Append("(");
@ -444,10 +372,66 @@ namespace Bind.Structures
#endregion #endregion
public string CallString()
{
return CallString(false);
}
public string CallString(bool taoCompatible)
{
StringBuilder sb = new StringBuilder();
sb.Append("(");
if (this.Count > 0)
{
foreach (Parameter p in this)
{
if (p.Unchecked)
sb.Append("unchecked((" + p.CurrentType + ")");
if (p.CurrentType != "object")
{
if (p.CurrentType.ToLower().Contains("string"))
{
sb.Append(String.Format(
"({0}{1})",
p.CurrentType,
(p.Array > 0) ? "[]" : ""));
}
else
{
sb.Append(String.Format(
"({0}{1})",
p.CurrentType,
(p.Pointer || p.Array > 0 || p.Reference) ? "*" : ""));
}
}
sb.Append(
Utilities.Keywords.Contains(p.Name) ? "@" + p.Name : p.Name
);
if (p.Unchecked)
sb.Append(")");
sb.Append(", ");
}
sb.Replace(", ", ")", sb.Length - 2, 2);
}
else
{
sb.Append(")");
}
return sb.ToString();
}
public bool ContainsType(string type) public bool ContainsType(string type)
{ {
foreach (Parameter p in this) foreach (Parameter p in this)
if (p.Type == type) if (p.CurrentType == type)
return true; return true;
return false; return false;
} }

View file

@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Bind.Structures
{
public class Type
{
internal static Dictionary<string, string> GLTypes;
internal static Dictionary<string, string> CSTypes;
private static bool typesLoaded;
internal static void Initialize()
{
if (!typesLoaded)
{
if (GLTypes == null)
{
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\gl.tm"))
{
GLTypes = Bind.MainClass.Generator.ReadTypeMap(sr);
}
}
if (CSTypes == null)
{
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, "gl2\\csharp.tm"))
{
CSTypes = Bind.MainClass.Generator.ReadCSTypeMap(sr);
}
}
typesLoaded = true;
}
}
public Type()
{
}
public Type(Type t)
{
this.CurrentType = new string(t.CurrentType.ToCharArray());
this.PreviousType = !String.IsNullOrEmpty(t.PreviousType) ? new string(t.PreviousType.ToCharArray()) : "";
this.WrapperType = t.WrapperType;
this.Array = t.Array;
this.Pointer = t.Pointer;
this.Reference = t.Reference;
}
#region public string Type
string type;
/// <summary>
/// Gets the type of the parameter.
/// </summary>
public virtual string CurrentType
{
//get { return _type; }
get
{
//if (Pointer && Settings.Compatibility == Settings.Legacy.Tao)
// return "IntPtr";
return type;
}
set
{
if (!String.IsNullOrEmpty(type))
PreviousType = type;
if (!String.IsNullOrEmpty(value))
type = value.Trim();
//Translate();
if (type.EndsWith("*"))
{
type = type.TrimEnd('*');
Pointer = true;
}
}
}
#endregion
#region public string PreviousType
private string _previous_type;
public string PreviousType
{
get { return _previous_type; }
set { _previous_type = value; }
}
#endregion
#region public bool Reference
bool reference;
public bool Reference
{
get { return reference; }
set { reference = value; }
}
#endregion
#region public bool Array
int array;
public int Array
{
get { return array; }
set { array = value > 0 ? value : 0; }
}
#endregion
#region public bool Pointer
bool pointer = false;
public bool Pointer
{
get { return pointer; }
set { pointer = value; }
}
#endregion
#region public bool CLSCompliant
public bool CLSCompliant
{
get
{
return !(
(Pointer && (Settings.Compatibility != Settings.Legacy.Tao)) ||
CurrentType.Contains("UInt") ||
CurrentType.Contains("SByte"));
/*(Type.Contains("GLu") && !Type.Contains("GLubyte")) ||
Type == "GLbitfield" ||
Type.Contains("GLhandle") ||
Type.Contains("GLhalf") ||
Type == "GLbyte");*/
}
}
#endregion
#region WrapperType property
private WrapperTypes _wrapper_type = WrapperTypes.None;
public WrapperTypes WrapperType
{
get { return _wrapper_type; }
set { _wrapper_type = value; }
}
#endregion
#region public string GetFullType()
public string GetFullType(Dictionary<string, string> CSTypes, bool compliant)
{
if (Pointer && Settings.Compatibility == Settings.Legacy.Tao)
return "IntPtr";
if (!compliant)
{
return
CurrentType +
(Pointer ? "*" : "") +
(Array > 0 ? "[]" : "");
}
return
GetCLSCompliantType() +
(Pointer ? "*" : "") +
(Array > 0 ? "[]" : "");
}
#endregion
#region public string GetCLSCompliantType()
public string GetCLSCompliantType()
{
if (!CLSCompliant)
{
if (Pointer && Settings.Compatibility == Settings.Legacy.Tao)
return "IntPtr";
switch (CurrentType)
{
case "UInt16":
return "Int16";
case "UInt32":
return "Int32";
case "UInt64":
return "Int64";
case "SByte":
return "Byte";
}
}
return CurrentType;
}
#endregion
public override string ToString()
{
return CurrentType;
}
internal static Type Translate(Type type)
{
Type t = new Type(type);
if (GLTypes.ContainsKey(t.CurrentType))
t.CurrentType = GLTypes[t.CurrentType];
if (CSTypes.ContainsKey(t.CurrentType))
t.CurrentType = CSTypes[t.CurrentType];
return t;
}
}
}

View file

@ -157,20 +157,6 @@ namespace Bind
#endregion #endregion
#region internal static string StripGL2Extension(Function f)
internal static string StripGL2Extension(Function f)
{
string ext = GetGL2Extension(f.Name);
if (String.IsNullOrEmpty(ext))
return null;
f.Name = f.Name.Substring(0, f.Name.Length - ext.Length);
return ext;
}
#endregion
#region internal static string GetGL2Extension(string name) #region internal static string GetGL2Extension(string name)
internal static string GetGL2Extension(string name) internal static string GetGL2Extension(string name)
@ -195,7 +181,7 @@ namespace Bind
if (name.EndsWith("APPLE")) { return "APPLE"; } if (name.EndsWith("APPLE")) { return "APPLE"; }
if (name.EndsWith("OML")) { return "OML"; } if (name.EndsWith("OML")) { return "OML"; }
if (name.EndsWith("I3D")) { return "I3D"; } if (name.EndsWith("I3D")) { return "I3D"; }
return null; return "";
} }
#endregion #endregion
@ -227,5 +213,10 @@ namespace Bind
} }
#endregion #endregion
internal static string StripGL2Extension(string p)
{
return p.Substring(0, p.Length - GetGL2Extension(p).Length);
}
} }
} }

View file

@ -148,41 +148,41 @@ namespace Examples.Windowing
{ {
GL.Begin(Enums.BeginMode.QUADS); GL.Begin(Enums.BeginMode.QUADS);
GL.Color3f(1, 0, 0); GL.Color3(1, 0, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Color3f(1, 1, 0); GL.Color3(1, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Color3f(1, 0, 1); GL.Color3(1, 0, 1);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 0); GL.Color3(0, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Color3f(0, 0, 1); GL.Color3(0, 0, 1);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 1); GL.Color3(0, 1, 1);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.End(); GL.End();
} }

View file

@ -81,8 +81,8 @@ namespace Examples.Tests
while (!stop) while (!stop)
{ {
GL.Vertex2f(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f);
//GL.Vertex2fv(v); GL.Vertex2(v);
//GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB); //GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB);
//dummy(); //dummy();
GL.ColorPointer(2, GL.Enums.ColorPointerType.FLOAT, 0, v); GL.ColorPointer(2, GL.Enums.ColorPointerType.FLOAT, 0, v);

View file

@ -131,41 +131,41 @@ namespace Examples.Tutorial
{ {
GL.Begin(Enums.BeginMode.QUADS); GL.Begin(Enums.BeginMode.QUADS);
GL.Color3f(1, 0, 0); GL.Color3(1, 0, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Color3f(1, 1, 0); GL.Color3(1, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Color3f(1, 0, 1); GL.Color3(1, 0, 1);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 0); GL.Color3(0, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Color3f(0, 0, 1); GL.Color3(0, 0, 1);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 1); GL.Color3(0, 1, 1);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.End(); GL.End();
} }

View file

@ -53,7 +53,7 @@ namespace Examples.Tutorial
d.Begin(); d.Begin();
GL.Color3d( GL.Color3(
1.0, 1.0,
c, c,
1 - c 1 - c
@ -61,10 +61,10 @@ namespace Examples.Tutorial
GL.Begin(Enums.BeginMode.QUADS); GL.Begin(Enums.BeginMode.QUADS);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f( 1.0f, -1.0f, 1.0f); GL.Vertex3( 1.0f, -1.0f, 1.0f);
GL.Vertex3f( 1.0f, 1.0f, 1.0f); GL.Vertex3( 1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.End(); GL.End();

View file

@ -103,7 +103,7 @@ namespace Examples.Tutorial
GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo); GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo);
GL.IndexPointer(GL.Enums.IndexPointerType.FLOAT, 0, 0); GL.IndexPointer(GL.Enums.IndexPointerType.FLOAT, 0, 0);
GL.Color3f(1.0f, 1.0f, 1.0f); GL.Color3(1.0f, 1.0f, 1.0f);
GL.DrawElements( GL.DrawElements(
GL.Enums.BeginMode.QUADS, GL.Enums.BeginMode.QUADS,
idata.Length, idata.Length,
@ -183,7 +183,7 @@ namespace Examples.Tutorial
(IntPtr)(vdata.Length * 4), (IntPtr)(vdata.Length * 4),
vdata, vdata,
GL.Enums.VERSION_1_5.STATIC_DRAW); GL.Enums.VERSION_1_5.STATIC_DRAW);
GL.GetBufferParameteriv( GL.GetBufferParameter(
GL.Enums.VERSION_1_5.ARRAY_BUFFER, GL.Enums.VERSION_1_5.ARRAY_BUFFER,
GL.Enums.VERSION_1_5.BUFFER_SIZE, GL.Enums.VERSION_1_5.BUFFER_SIZE,
out size); out size);
@ -200,7 +200,7 @@ namespace Examples.Tutorial
idata, idata,
GL.Enums.VERSION_1_5.STATIC_DRAW GL.Enums.VERSION_1_5.STATIC_DRAW
); );
GL.GetBufferParameteriv( GL.GetBufferParameter(
GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER,
GL.Enums.VERSION_1_5.BUFFER_SIZE, GL.Enums.VERSION_1_5.BUFFER_SIZE,
out size); out size);

View file

@ -71,7 +71,7 @@ namespace Examples.Tutorial
GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int[])null); GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int[])null);
GL.CompileShader(vertex_shader_object); GL.CompileShader(vertex_shader_object);
GL.GetShaderiv(vertex_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); GL.GetShader(vertex_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status);
if (status != (int)Enums.Boolean.TRUE) if (status != (int)Enums.Boolean.TRUE)
{ {
StringBuilder info = new StringBuilder(1024); StringBuilder info = new StringBuilder(1024);
@ -82,7 +82,7 @@ namespace Examples.Tutorial
GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int[])null); GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int[])null);
GL.CompileShader(fragment_shader_object); GL.CompileShader(fragment_shader_object);
GL.GetShaderiv(fragment_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); GL.GetShader(fragment_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status);
if (status != (int)Enums.Boolean.TRUE) if (status != (int)Enums.Boolean.TRUE)
{ {
StringBuilder info = new StringBuilder(1024); StringBuilder info = new StringBuilder(1024);
@ -184,41 +184,41 @@ namespace Examples.Tutorial
{ {
GL.Begin(Enums.BeginMode.QUADS); GL.Begin(Enums.BeginMode.QUADS);
GL.Color3f(1, 0, 0); GL.Color3(1, 0, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Color3f(1, 1, 0); GL.Color3(1, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Color3f(1, 0, 1); GL.Color3(1, 0, 1);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 0); GL.Color3(0, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Color3f(0, 0, 1); GL.Color3(0, 0, 1);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 1); GL.Color3(0, 1, 1);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.End(); GL.End();
} }

View file

@ -167,41 +167,41 @@ namespace Examples.WinForms
{ {
GL.Begin(Enums.BeginMode.QUADS); GL.Begin(Enums.BeginMode.QUADS);
GL.Color3f(1, 0, 0); GL.Color3(1, 0, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Color3f(1, 1, 0); GL.Color3(1, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Color3f(1, 0, 1); GL.Color3(1, 0, 1);
GL.Vertex3f(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 0); GL.Color3(0, 1, 0);
GL.Vertex3f(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Color3f(0, 0, 1); GL.Color3(0, 0, 1);
GL.Vertex3f(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3f(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Color3f(0, 1, 1); GL.Color3(0, 1, 1);
GL.Vertex3f(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3f(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3f(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.End(); GL.End();
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("0.3.9.3")] [assembly: AssemblyVersion("0.3.9.4")]
[assembly: AssemblyFileVersion("0.3.9.3")] [assembly: AssemblyFileVersion("0.3.9.4")]