mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 08:25:37 +00:00
Split translation code between Type.Translate() and Parameter.Translate().
This commit is contained in:
parent
b9afd64b0a
commit
99612e5961
|
@ -242,144 +242,42 @@ namespace Bind.Structures
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region internal static Parameter Translate(Parameter par, string Category)
|
#region override public void Translate(string category)
|
||||||
|
|
||||||
internal static Parameter Translate(Parameter par, string Category)
|
override public void Translate(string category)
|
||||||
{
|
{
|
||||||
Enum @enum;
|
base.Translate(category);
|
||||||
string s;
|
|
||||||
Parameter p = new Parameter(par);
|
|
||||||
|
|
||||||
// Try to find out if it is an enum. If the type exists in the normal GLEnums list, use this.
|
// Find out the necessary wrapper types.
|
||||||
// Otherwise, try to find it in the aux enums list. If it exists in neither, it is not an enum.
|
if (Pointer)/* || CurrentType == "IntPtr")*/
|
||||||
bool normal = false;
|
{
|
||||||
bool aux = false;
|
WrapperType = WrapperTypes.ArrayParameter;
|
||||||
normal = Enum.GLEnums.TryGetValue(p.CurrentType, out @enum);
|
|
||||||
if (!normal)
|
|
||||||
aux = Enum.AuxEnums != null && Enum.AuxEnums.TryGetValue(p.CurrentType, out @enum);
|
|
||||||
|
|
||||||
// Translate enum types
|
if (CurrentType.ToLower().Contains("char") || CurrentType.ToLower().Contains("string"))
|
||||||
if ((normal || aux) && @enum.Name != "GLenum")
|
|
||||||
{
|
|
||||||
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
|
|
||||||
{
|
|
||||||
p.CurrentType = "int";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (normal)
|
|
||||||
{
|
|
||||||
p.CurrentType = p.CurrentType.Insert(0, String.Format("{0}.", Settings.NormalEnumsClass));
|
|
||||||
}
|
|
||||||
else if (aux)
|
|
||||||
{
|
|
||||||
p.CurrentType = p.CurrentType.Insert(0, String.Format("{0}.", Settings.AuxEnumsClass));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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.ConstIntEnums) == 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.NormalEnumsClass, Category);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p.CurrentType = String.Format("{0}.{1}", Settings.NormalEnumsClass, Settings.CompleteEnumName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p.CurrentType = "int";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// This is not enum, default translation:
|
|
||||||
if (p.CurrentType == "PIXELFORMATDESCRIPTOR" || p.CurrentType == "LAYERPLANEDESCRIPTOR" ||
|
|
||||||
p.CurrentType == "GLYPHMETRICSFLOAT")
|
|
||||||
{
|
|
||||||
if (Settings.Compatibility == Settings.Legacy.Tao)
|
|
||||||
{
|
|
||||||
p.CurrentType = p.CurrentType.Insert(0, "Gdi.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (p.CurrentType == "PIXELFORMATDESCRIPTOR")
|
|
||||||
p.CurrentType ="PixelFormatDescriptor";
|
|
||||||
else if (p.CurrentType == "LAYERPLANEDESCRIPTOR")
|
|
||||||
p.CurrentType = "LayerPlaneDescriptor";
|
|
||||||
else if (p.CurrentType == "GLYPHMETRICSFLOAT")
|
|
||||||
p.CurrentType = "GlyphMetricsFloat";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (p.CurrentType == "XVisualInfo")
|
|
||||||
{
|
|
||||||
//p.Pointer = false;
|
|
||||||
//p.Reference = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p.CurrentType = s;
|
|
||||||
}
|
|
||||||
p.CurrentType =
|
|
||||||
Bind.Structures.Type.CSTypes.ContainsKey(p.CurrentType) ?
|
|
||||||
Bind.Structures.Type.CSTypes[p.CurrentType] : p.CurrentType;
|
|
||||||
|
|
||||||
if (p.CurrentType == "IntPtr")
|
|
||||||
{
|
|
||||||
p.Pointer = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (CSTypes.ContainsKey(p.CurrentType))
|
|
||||||
// p.CurrentType = CSTypes[p.CurrentType];
|
|
||||||
|
|
||||||
// Translate pointer parameters
|
|
||||||
if (p.Pointer)/* || p.CurrentType == "IntPtr")*/
|
|
||||||
{
|
|
||||||
p.WrapperType = WrapperTypes.ArrayParameter;
|
|
||||||
|
|
||||||
if (p.CurrentType.ToLower().Contains("char") || p.CurrentType.ToLower().Contains("string"))
|
|
||||||
{
|
{
|
||||||
// char* or string -> [In] String or [Out] StringBuilder
|
// char* or string -> [In] String or [Out] StringBuilder
|
||||||
p.CurrentType =
|
CurrentType =
|
||||||
p.Flow == Parameter.FlowDirection.Out ?
|
Flow == Parameter.FlowDirection.Out ?
|
||||||
"System.Text.StringBuilder" :
|
"System.Text.StringBuilder" :
|
||||||
"System.String";
|
"System.String";
|
||||||
|
|
||||||
p.Pointer = false;
|
Pointer = false;
|
||||||
p.WrapperType = WrapperTypes.None;
|
WrapperType = WrapperTypes.None;
|
||||||
}
|
}
|
||||||
else if (p.CurrentType.ToLower().Contains("void")) /*|| p.CurrentType.Contains("IntPtr"))*/
|
else if (CurrentType.ToLower().Contains("void")) /*|| CurrentType.Contains("IntPtr"))*/
|
||||||
{
|
{
|
||||||
p.CurrentType = "IntPtr";
|
CurrentType = "IntPtr";
|
||||||
p.Pointer = false;
|
Pointer = false;
|
||||||
p.WrapperType = WrapperTypes.GenericParameter;
|
WrapperType = WrapperTypes.GenericParameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.Reference)
|
if (Reference)
|
||||||
{
|
WrapperType = WrapperTypes.ReferenceParameter;
|
||||||
p.WrapperType = WrapperTypes.ReferenceParameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.CurrentType.ToLower().Contains("bool"))
|
// This causes problems with bool arrays
|
||||||
{
|
//if (CurrentType.ToLower().Contains("bool"))
|
||||||
// Is this actually used anywhere?
|
// WrapperType = WrapperTypes.BoolParameter;
|
||||||
p.WrapperType = WrapperTypes.BoolParameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -254,19 +254,89 @@ namespace Bind.Structures
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region internal static Type Translate(Type type)
|
#region public virtual void Translate(string category)
|
||||||
|
|
||||||
internal static Type Translate(Type type)
|
public virtual void Translate(string category)
|
||||||
{
|
{
|
||||||
Type t = new Type(type);
|
Enum @enum;
|
||||||
|
string s;
|
||||||
|
|
||||||
if (GLTypes.ContainsKey(t.CurrentType))
|
if (this.CurrentType == "BlendEquationModeEXT")
|
||||||
t.CurrentType = GLTypes[t.CurrentType];
|
{
|
||||||
|
}
|
||||||
|
|
||||||
if (CSTypes.ContainsKey(t.CurrentType))
|
// Try to find out if it is an enum. If the type exists in the normal GLEnums list, use this.
|
||||||
t.CurrentType = CSTypes[t.CurrentType];
|
// Otherwise, try to find it in the aux enums list. If it exists in neither, it is not an enum.
|
||||||
|
// Special case for Boolean - it is an enum, but it is dumb to use that instead of the 'bool' type.
|
||||||
|
bool normal = false;
|
||||||
|
bool aux = false;
|
||||||
|
normal = Enum.GLEnums.TryGetValue(CurrentType, out @enum);
|
||||||
|
if (!normal)
|
||||||
|
aux = Enum.AuxEnums != null && Enum.AuxEnums.TryGetValue(CurrentType, out @enum);
|
||||||
|
|
||||||
return t;
|
// Translate enum types
|
||||||
|
if ((normal || aux) && @enum.Name != "GLenum" && @enum.Name != "Boolean")
|
||||||
|
{
|
||||||
|
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) != Settings.Legacy.None)
|
||||||
|
CurrentType = "int";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (normal)
|
||||||
|
CurrentType = Enum.TranslateName(CurrentType).Insert(0, String.Format("{0}.", Settings.EnumsOutput));
|
||||||
|
else if (aux)
|
||||||
|
CurrentType = Enum.TranslateName(CurrentType).Insert(0, String.Format("{0}.", Settings.EnumsAuxOutput));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Bind.Structures.Type.GLTypes.TryGetValue(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.ConstIntEnums) != Settings.Legacy.None)
|
||||||
|
CurrentType = "int";
|
||||||
|
else
|
||||||
|
// Better match: enum.Name == function.Category (e.g. GL_VERSION_1_1 etc)
|
||||||
|
if (Enum.GLEnums.ContainsKey(category))
|
||||||
|
CurrentType = String.Format("{0}.{1}", Settings.EnumsOutput, Enum.TranslateName(category));
|
||||||
|
else
|
||||||
|
CurrentType = String.Format("{0}.{1}", Settings.EnumsOutput, Settings.CompleteEnumName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This is not enum, default translation:
|
||||||
|
if (CurrentType == "PIXELFORMATDESCRIPTOR" || CurrentType == "LAYERPLANEDESCRIPTOR" ||
|
||||||
|
CurrentType == "GLYPHMETRICSFLOAT")
|
||||||
|
{
|
||||||
|
if (Settings.Compatibility == Settings.Legacy.Tao)
|
||||||
|
CurrentType = CurrentType.Insert(0, "Gdi.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (CurrentType == "PIXELFORMATDESCRIPTOR")
|
||||||
|
CurrentType = "PixelFormatDescriptor";
|
||||||
|
else if (CurrentType == "LAYERPLANEDESCRIPTOR")
|
||||||
|
CurrentType = "LayerPlaneDescriptor";
|
||||||
|
else if (CurrentType == "GLYPHMETRICSFLOAT")
|
||||||
|
CurrentType = "GlyphMetricsFloat";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (CurrentType == "XVisualInfo")
|
||||||
|
{
|
||||||
|
//p.Pointer = false;
|
||||||
|
//p.Reference = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CurrentType = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentType =
|
||||||
|
Bind.Structures.Type.CSTypes.ContainsKey(CurrentType) ?
|
||||||
|
Bind.Structures.Type.CSTypes[CurrentType] : CurrentType;
|
||||||
|
|
||||||
|
if (CurrentType == "IntPtr")
|
||||||
|
Pointer = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue