2009-02-22 11:43:35 +01:00
|
|
|
#region --- License ---
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
* See license.txt for license info
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
2009-10-27 23:37:05 +01:00
|
|
|
using System.Linq;
|
2009-08-17 14:28:22 +02:00
|
|
|
using System.Text;
|
2009-05-29 17:57:01 +02:00
|
|
|
using System.Text.RegularExpressions;
|
2009-08-17 14:28:22 +02:00
|
|
|
using System.Xml.XPath;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
namespace Bind.Structures
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents an opengl function.
|
|
|
|
/// The return value, function name, function parameters and opengl version can be retrieved or set.
|
|
|
|
/// </summary>
|
2009-05-30 17:28:52 +02:00
|
|
|
public class Delegate : IComparable<Delegate>
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
internal static DelegateCollection Delegates;
|
|
|
|
|
|
|
|
private static bool delegatesLoaded;
|
2009-04-12 20:23:01 +02:00
|
|
|
bool? cls_compliance_overriden;
|
2009-05-29 17:57:01 +02:00
|
|
|
|
|
|
|
protected static Regex endings = new Regex(@"((((d|f|fi)|u?[isb])_?v?)|v)", RegexOptions.Compiled | RegexOptions.RightToLeft);
|
2009-08-20 23:38:23 +02:00
|
|
|
protected static Regex endingsNotToTrim = new Regex("(ib|[tdrey]s|[eE]n[vd]|bled|Flag|Tess|Status|Pixels|Instanced|Indexed|Varyings|Boolean|IDs)", RegexOptions.Compiled | RegexOptions.RightToLeft);
|
2009-05-29 17:57:01 +02:00
|
|
|
|
|
|
|
// Add a trailing v to functions matching this regex. Used to differntiate between overloads taking both
|
|
|
|
// a 'type' and a 'ref type' (such overloads are not CLS Compliant).
|
|
|
|
// The default Regex matches no functions. Create a new Regex in Bind.Generator classes to override the default behavior.
|
|
|
|
internal static Regex endingsAddV = new Regex("^0", RegexOptions.Compiled);
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
#region internal static void Initialize(string glSpec, string glSpecExt)
|
|
|
|
|
|
|
|
internal static void Initialize(string glSpec, string glSpecExt)
|
|
|
|
{
|
|
|
|
if (!delegatesLoaded)
|
|
|
|
{
|
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, glSpec))
|
|
|
|
{
|
2009-08-21 22:28:14 +02:00
|
|
|
Delegates = MainClass.Generator.ReadDelegates(sr);
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(glSpecExt))
|
|
|
|
{
|
|
|
|
using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, glSpecExt))
|
|
|
|
{
|
2009-08-21 22:28:14 +02:00
|
|
|
foreach (Delegate d in MainClass.Generator.ReadDelegates(sr).Values)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
Utilities.Merge(Delegates, d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-07 07:20:29 +02:00
|
|
|
Console.WriteLine("Enforcing CLS compliance.");
|
2009-04-12 20:23:01 +02:00
|
|
|
MarkCLSCompliance(Function.Wrappers);
|
2009-02-22 11:43:35 +01:00
|
|
|
delegatesLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
|
|
public Delegate()
|
|
|
|
{
|
|
|
|
Parameters = new ParameterCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Delegate(Delegate d)
|
|
|
|
{
|
2009-08-25 17:59:57 +02:00
|
|
|
Category = d.Category;
|
|
|
|
Name = d.Name;
|
|
|
|
Parameters = new ParameterCollection(d.Parameters);
|
|
|
|
ReturnType = new Type(d.ReturnType);
|
|
|
|
Version = d.Version;
|
2009-02-22 11:43:35 +01:00
|
|
|
//this.Version = !String.IsNullOrEmpty(d.Version) ? new string(d.Version.ToCharArray()) : "";
|
2010-10-10 14:28:27 +02:00
|
|
|
Deprecated = d.Deprecated;
|
|
|
|
DeprecatedVersion = d.DeprecatedVersion;
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region --- Properties ---
|
|
|
|
|
|
|
|
#region public bool CLSCompliant
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the CLSCompliant property. True if the delegate is not CLSCompliant.
|
|
|
|
/// </summary>
|
|
|
|
public virtual bool CLSCompliant
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-04-12 20:23:01 +02:00
|
|
|
if (cls_compliance_overriden != null)
|
|
|
|
return (bool)cls_compliance_overriden;
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
if (Unsafe)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ReturnType.CLSCompliant)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
foreach (Parameter p in Parameters)
|
|
|
|
{
|
|
|
|
if (!p.CLSCompliant)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-12 20:23:01 +02:00
|
|
|
set
|
|
|
|
{
|
|
|
|
cls_compliance_overriden = value;
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public string Category
|
|
|
|
|
|
|
|
private string _category;
|
|
|
|
|
|
|
|
public string Category
|
|
|
|
{
|
|
|
|
get { return _category; }
|
2009-02-28 20:29:34 +01:00
|
|
|
set { _category = Enum.TranslateName(value); }
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public bool NeedsWrapper
|
|
|
|
|
|
|
|
/// <summary>
|
2009-10-27 23:37:05 +01:00
|
|
|
/// Gets a value that indicates whether this function needs to be wrapped with a Marshaling function.
|
2009-02-22 11:43:35 +01:00
|
|
|
/// This flag is set if a function contains an Array parameter, or returns
|
|
|
|
/// an Array or string.
|
|
|
|
/// </summary>
|
|
|
|
public bool NeedsWrapper
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
#region public virtual bool Unsafe
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// True if the delegate must be declared as 'unsafe'.
|
|
|
|
/// </summary>
|
|
|
|
public virtual bool Unsafe
|
|
|
|
{
|
|
|
|
//get { return @unsafe; }
|
|
|
|
//set { @unsafe = value; }
|
|
|
|
get
|
|
|
|
{
|
|
|
|
//if ((Settings.Compatibility & Settings.Legacy.NoPublicUnsafeFunctions) != Settings.Legacy.None)
|
|
|
|
// return false;
|
|
|
|
|
2009-07-16 00:33:26 +02:00
|
|
|
if (ReturnType.Pointer != 0)
|
2009-02-22 11:43:35 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
foreach (Parameter p in Parameters)
|
|
|
|
{
|
2009-07-16 00:33:26 +02:00
|
|
|
if (p.Pointer != 0)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public Parameter ReturnType
|
|
|
|
|
|
|
|
Type _return_type = new Type();
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the return value of the opengl function.
|
|
|
|
/// </summary>
|
|
|
|
public Type ReturnType
|
|
|
|
{
|
|
|
|
get { return _return_type; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_return_type = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public virtual string Name
|
|
|
|
|
|
|
|
string _name;
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the name of the opengl function.
|
|
|
|
/// </summary>
|
|
|
|
public virtual string Name
|
|
|
|
{
|
|
|
|
get { return _name; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (!String.IsNullOrEmpty(value))
|
|
|
|
{
|
|
|
|
_name = value.Trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public ParameterCollection Parameters
|
|
|
|
|
|
|
|
ParameterCollection _parameters;
|
|
|
|
|
|
|
|
public ParameterCollection Parameters
|
|
|
|
{
|
|
|
|
get { return _parameters; }
|
2009-10-27 23:37:05 +01:00
|
|
|
set { _parameters = value; }
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public string Version
|
|
|
|
|
|
|
|
string _version;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the opengl version that introduced this function.
|
|
|
|
/// </summary>
|
|
|
|
public string Version
|
|
|
|
{
|
|
|
|
get { return _version; }
|
|
|
|
set { _version = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public bool Extension
|
|
|
|
|
|
|
|
string _extension;
|
|
|
|
|
|
|
|
public string Extension
|
|
|
|
{
|
|
|
|
//get { return _extension; }
|
|
|
|
//set { _extension = value; }
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (!String.IsNullOrEmpty(Name))
|
|
|
|
{
|
|
|
|
_extension = Utilities.GetGL2Extension(Name);
|
|
|
|
return String.IsNullOrEmpty(_extension) ? "Core" : _extension;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2010-10-10 14:28:27 +02:00
|
|
|
public bool Deprecated { get; set; }
|
|
|
|
public string DeprecatedVersion { get; set; }
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region --- Strings ---
|
|
|
|
|
|
|
|
#region public string CallString()
|
|
|
|
|
|
|
|
public string CallString()
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.Append(Settings.DelegatesClass);
|
|
|
|
sb.Append(".");
|
|
|
|
sb.Append(Settings.FunctionPrefix);
|
|
|
|
sb.Append(Name);
|
|
|
|
sb.Append(Parameters.CallString());
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a string representing the full non-delegate declaration without decorations.
|
|
|
|
/// (ie "(unsafe) void glXxxYyy(int a, float b, IntPtr c)"
|
|
|
|
/// </summary>
|
|
|
|
#region public string DeclarationString()
|
|
|
|
|
|
|
|
public string DeclarationString()
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.Append(Unsafe ? "unsafe " : "");
|
|
|
|
sb.Append(ReturnType);
|
|
|
|
sb.Append(" ");
|
|
|
|
sb.Append(Name);
|
|
|
|
sb.Append(Parameters.ToString(true));
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region override public string ToString()
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a string representing the full delegate declaration without decorations.
|
|
|
|
/// (ie "(unsafe) void delegate glXxxYyy(int a, float b, IntPtr c)"
|
|
|
|
/// </summary>
|
|
|
|
override public string ToString()
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.Append(Unsafe ? "unsafe " : "");
|
|
|
|
sb.Append("delegate ");
|
|
|
|
sb.Append(ReturnType);
|
|
|
|
sb.Append(" ");
|
|
|
|
sb.Append(Name);
|
|
|
|
sb.Append(Parameters.ToString(true));
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public Delegate GetCLSCompliantDelegate()
|
|
|
|
{
|
|
|
|
Delegate f = new Delegate(this);
|
|
|
|
|
|
|
|
for (int i = 0; i < f.Parameters.Count; i++)
|
|
|
|
{
|
|
|
|
f.Parameters[i].CurrentType = f.Parameters[i].GetCLSCompliantType();
|
|
|
|
}
|
|
|
|
|
|
|
|
f.ReturnType.CurrentType = f.ReturnType.GetCLSCompliantType();
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region --- Wrapper Creation ---
|
|
|
|
|
2009-04-12 20:23:01 +02:00
|
|
|
#region MarkCLSCompliance
|
|
|
|
|
|
|
|
static void MarkCLSCompliance(FunctionCollection collection)
|
|
|
|
{
|
|
|
|
foreach (List<Function> wrappers in Function.Wrappers.Values)
|
|
|
|
{
|
2009-05-22 01:34:20 +02:00
|
|
|
restart:
|
2009-04-12 20:23:01 +02:00
|
|
|
for (int i = 0; i < wrappers.Count; i++)
|
|
|
|
{
|
|
|
|
for (int j = i + 1; j < wrappers.Count; j++)
|
|
|
|
{
|
|
|
|
if (wrappers[i].TrimmedName == wrappers[j].TrimmedName && wrappers[i].Parameters.Count == wrappers[j].Parameters.Count)
|
|
|
|
{
|
|
|
|
bool function_i_is_problematic = false;
|
|
|
|
bool function_j_is_problematic = false;
|
|
|
|
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < wrappers[i].Parameters.Count; k++)
|
|
|
|
{
|
|
|
|
if (wrappers[i].Parameters[k].CurrentType != wrappers[j].Parameters[k].CurrentType)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (wrappers[i].Parameters[k].DiffersOnlyOnReference(wrappers[j].Parameters[k]))
|
|
|
|
if (wrappers[i].Parameters[k].Reference)
|
|
|
|
function_i_is_problematic = true;
|
|
|
|
else
|
|
|
|
function_j_is_problematic = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k == wrappers[i].Parameters.Count)
|
|
|
|
{
|
|
|
|
if (function_i_is_problematic)
|
2009-05-22 01:34:20 +02:00
|
|
|
wrappers.RemoveAt(i);
|
|
|
|
//wrappers[i].CLSCompliant = false;
|
2009-04-12 20:23:01 +02:00
|
|
|
if (function_j_is_problematic)
|
2009-05-22 01:34:20 +02:00
|
|
|
wrappers.RemoveAt(j);
|
|
|
|
//wrappers[j].CLSCompliant = false;
|
|
|
|
|
|
|
|
if (function_i_is_problematic || function_j_is_problematic)
|
|
|
|
goto restart;
|
2009-04-12 20:23:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CreateWrappers
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-04-12 20:23:01 +02:00
|
|
|
void CreateWrappers()
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
List<Function> wrappers = new List<Function>();
|
2009-10-27 23:37:05 +01:00
|
|
|
CreateNormalWrappers(wrappers);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-10-27 23:37:05 +01:00
|
|
|
// Generate wrappers using the untyped enum parameters, if necessary.
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.KeepUntypedEnums) != 0)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2009-10-27 23:37:05 +01:00
|
|
|
CreateUntypedEnumWrappers(wrappers);
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
2009-10-27 23:37:05 +01:00
|
|
|
|
|
|
|
// Add CLS-compliant overloads for non-CLS compliant wrappers.
|
|
|
|
CreateCLSCompliantWrappers(wrappers);
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-10-27 23:37:05 +01:00
|
|
|
private static void CreateCLSCompliantWrappers(List<Function> wrappers)
|
|
|
|
{
|
2009-02-22 11:43:35 +01:00
|
|
|
// 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)
|
|
|
|
{
|
2009-08-21 22:28:14 +02:00
|
|
|
Function.Wrappers.AddChecked(f);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
if (!f.CLSCompliant)
|
|
|
|
{
|
|
|
|
Function cls = new Function(f);
|
|
|
|
|
|
|
|
cls.Body.Clear();
|
2009-03-29 23:41:30 +02:00
|
|
|
cls.CreateBody(true);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-10-27 23:37:05 +01:00
|
|
|
bool modified = false;
|
2009-02-22 11:43:35 +01:00
|
|
|
for (int i = 0; i < f.Parameters.Count; i++)
|
|
|
|
{
|
|
|
|
cls.Parameters[i].CurrentType = cls.Parameters[i].GetCLSCompliantType();
|
|
|
|
if (cls.Parameters[i].CurrentType != f.Parameters[i].CurrentType)
|
2009-10-27 23:37:05 +01:00
|
|
|
modified = true;
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
2009-10-27 23:37:05 +01:00
|
|
|
if (modified)
|
2009-08-21 22:28:14 +02:00
|
|
|
Function.Wrappers.AddChecked(cls);
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-27 23:37:05 +01:00
|
|
|
private void CreateUntypedEnumWrappers(List<Function> wrappers)
|
|
|
|
{
|
|
|
|
Function f = new Function(this);
|
|
|
|
var modified = false;
|
|
|
|
f.Parameters = new ParameterCollection(f.Parameters.Select(p =>
|
|
|
|
{
|
|
|
|
if (p.IsEnum && p.CurrentType != Settings.CompleteEnumName)
|
|
|
|
{
|
|
|
|
p.CurrentType = Settings.CompleteEnumName;
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}));
|
|
|
|
if (modified)
|
|
|
|
{
|
|
|
|
f.WrapReturnType();
|
|
|
|
f.WrapParameters(wrappers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateNormalWrappers(List<Function> wrappers)
|
|
|
|
{
|
|
|
|
Function f = new Function(this);
|
|
|
|
f.WrapReturnType();
|
|
|
|
f.WrapParameters(wrappers);
|
|
|
|
}
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
#endregion
|
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
#region TrimName
|
|
|
|
|
|
|
|
// Trims unecessary suffices from the specified OpenGL function name.
|
|
|
|
protected static string TrimName(string name, bool keep_extension)
|
|
|
|
{
|
|
|
|
string trimmed_name = Utilities.StripGL2Extension(name);
|
|
|
|
string extension = Utilities.GetGL2Extension(name);
|
|
|
|
|
|
|
|
// Note: some endings should not be trimmed, for example: 'b' from Attrib.
|
|
|
|
// Check the endingsNotToTrim regex for details.
|
|
|
|
Match m = endingsNotToTrim.Match(trimmed_name);
|
|
|
|
if ((m.Index + m.Length) != trimmed_name.Length)
|
|
|
|
{
|
|
|
|
m = endings.Match(trimmed_name);
|
|
|
|
|
|
|
|
if (m.Length > 0 && m.Index + m.Length == trimmed_name.Length)
|
|
|
|
{
|
|
|
|
// Only trim endings, not internal matches.
|
|
|
|
if (m.Value[m.Length - 1] == 'v' && endingsAddV.IsMatch(name) &&
|
|
|
|
!name.StartsWith("Get") && !name.StartsWith("MatrixIndex"))
|
|
|
|
{
|
|
|
|
// Only trim ending 'v' when there is a number
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index) + "v";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!trimmed_name.EndsWith("xedv"))
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index);
|
|
|
|
else
|
|
|
|
trimmed_name = trimmed_name.Substring(0, m.Index + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keep_extension)
|
|
|
|
return trimmed_name + extension;
|
|
|
|
else
|
|
|
|
return trimmed_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region TranslateReturnType
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-08-11 16:12:20 +02:00
|
|
|
// Translates the opengl return type to the equivalent C# type.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
void TranslateReturnType(XPathNavigator overrides, XPathNavigator function_override)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2009-05-29 17:57:01 +02:00
|
|
|
if (function_override != null)
|
|
|
|
{
|
2009-07-16 00:33:26 +02:00
|
|
|
XPathNavigator return_override = function_override.SelectSingleNode("returns");
|
2009-05-29 17:57:01 +02:00
|
|
|
if (return_override != null)
|
|
|
|
{
|
|
|
|
ReturnType.CurrentType = return_override.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 17:59:57 +02:00
|
|
|
ReturnType.Translate(overrides, Category);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-07-16 00:33:26 +02:00
|
|
|
if (ReturnType.CurrentType.ToLower().Contains("void") && ReturnType.Pointer != 0)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2009-10-27 23:37:05 +01:00
|
|
|
ReturnType.QualifiedType = "System.IntPtr";
|
2009-02-22 11:43:35 +01:00
|
|
|
ReturnType.WrapperType = WrapperTypes.GenericReturnType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReturnType.CurrentType.ToLower().Contains("string"))
|
|
|
|
{
|
2009-10-27 23:37:05 +01:00
|
|
|
ReturnType.QualifiedType = "System.IntPtr";
|
2009-02-22 11:43:35 +01:00
|
|
|
ReturnType.WrapperType = WrapperTypes.StringReturnType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReturnType.CurrentType.ToLower().Contains("object"))
|
|
|
|
{
|
2009-10-27 23:37:05 +01:00
|
|
|
ReturnType.QualifiedType = "System.IntPtr";
|
2009-02-22 11:43:35 +01:00
|
|
|
ReturnType.WrapperType |= WrapperTypes.GenericReturnType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReturnType.CurrentType.Contains("GLenum"))
|
|
|
|
{
|
|
|
|
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None)
|
2009-10-27 23:37:05 +01:00
|
|
|
ReturnType.QualifiedType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
|
2009-02-22 11:43:35 +01:00
|
|
|
else
|
2009-10-27 23:37:05 +01:00
|
|
|
ReturnType.QualifiedType = "int";
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnType.CurrentType = ReturnType.GetCLSCompliantType();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
#region TranslateParameters
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-08-11 16:12:20 +02:00
|
|
|
protected virtual void TranslateParameters(XPathNavigator overrides, XPathNavigator function_override)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < Parameters.Count; i++)
|
|
|
|
{
|
2009-05-29 17:57:01 +02:00
|
|
|
if (function_override != null)
|
|
|
|
{
|
|
|
|
XPathNavigator param_override = function_override.SelectSingleNode(String.Format("param[@name='{0}']", Parameters[i].Name));
|
|
|
|
if (param_override != null)
|
|
|
|
{
|
|
|
|
foreach (XPathNavigator node in param_override.SelectChildren(XPathNodeType.Element))
|
|
|
|
{
|
|
|
|
switch (node.Name)
|
|
|
|
{
|
|
|
|
case "type": Parameters[i].CurrentType = (string)node.TypedValue; break;
|
|
|
|
case "name": Parameters[i].Name = (string)node.TypedValue; break;
|
2009-07-16 00:33:26 +02:00
|
|
|
case "flow": Parameters[i].Flow = Parameter.GetFlowDirection((string)node.TypedValue); break;
|
2009-05-29 17:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 17:59:57 +02:00
|
|
|
Parameters[i].Translate(overrides, Category);
|
2009-02-22 11:43:35 +01:00
|
|
|
if (Parameters[i].CurrentType == "UInt16" && Name.Contains("LineStipple"))
|
|
|
|
Parameters[i].WrapperType = WrapperTypes.UncheckedParameter;
|
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
// Special case: these functions take a string[] that should stay as is.
|
|
|
|
// Todo: move to gloverrides.xml
|
2009-06-29 20:32:51 +02:00
|
|
|
//if (Name.Contains("ShaderSource") && Parameters[i].CurrentType.ToLower().Contains("string"))
|
|
|
|
// Parameters[i].Array = 1;
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
internal void Translate(XPathDocument overrides)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2009-05-29 17:57:01 +02:00
|
|
|
if (overrides == null)
|
|
|
|
throw new ArgumentNullException("overrides");
|
|
|
|
|
2009-10-17 23:49:35 +02:00
|
|
|
string path = "/overrides/replace/function[@name='{0}' and @extension='{1}']";
|
2009-05-29 17:57:01 +02:00
|
|
|
string name = TrimName(Name, false);
|
|
|
|
XPathNavigator function_override = overrides.CreateNavigator().SelectSingleNode(String.Format(path, name, Extension));
|
2009-08-11 16:12:20 +02:00
|
|
|
|
|
|
|
TranslateReturnType(overrides.CreateNavigator(), function_override);
|
|
|
|
TranslateParameters(overrides.CreateNavigator(), function_override);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
CreateWrappers();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2009-05-30 17:28:52 +02:00
|
|
|
|
|
|
|
#region IComparable<Delegate> Members
|
|
|
|
|
|
|
|
public int CompareTo(Delegate other)
|
|
|
|
{
|
|
|
|
return Name.CompareTo(other.Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
#region class DelegateCollection : SortedDictionary<string, Delegate>
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-05-29 17:57:01 +02:00
|
|
|
class DelegateCollection : SortedDictionary<string, Delegate>
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
public void Add(Delegate d)
|
|
|
|
{
|
2009-08-25 17:59:57 +02:00
|
|
|
if (!ContainsKey(d.Name))
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2009-08-25 17:59:57 +02:00
|
|
|
Add(d.Name, d);
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Trace.WriteLine(String.Format(
|
|
|
|
"Spec error: function {0} redefined, ignoring second definition.",
|
|
|
|
d.Name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|