2009-08-12 10:12:16 +00:00
|
|
|
#region --- License ---
|
2009-02-22 10:43:35 +00:00
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
* See license.txt for license info
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
2009-08-17 12:28:22 +00:00
|
|
|
using System.IO;
|
2009-10-27 22:37:05 +00:00
|
|
|
using System.Linq;
|
2009-02-22 10:43:35 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2009-05-29 15:57:01 +00:00
|
|
|
using System.Xml.XPath;
|
2009-08-17 12:28:22 +00:00
|
|
|
using Bind.Structures;
|
2009-08-21 20:28:14 +00:00
|
|
|
using Delegate=Bind.Structures.Delegate;
|
|
|
|
using Enum=Bind.Structures.Enum;
|
|
|
|
using Type=Bind.Structures.Type;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
namespace Bind.GL2
|
|
|
|
{
|
|
|
|
class Generator : IBind
|
|
|
|
{
|
2010-12-02 21:36:05 +00:00
|
|
|
#region Fields
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
protected string glTypemap = "GL2/gl.tm";
|
|
|
|
protected string csTypemap = "csharp.tm";
|
|
|
|
protected string enumSpec = "GL2/enum.spec";
|
|
|
|
protected string enumSpecExt = "GL2/enumext.spec";
|
|
|
|
protected string glSpec = "GL2/gl.spec";
|
|
|
|
protected string glSpecExt = "";
|
2009-02-28 19:29:34 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
protected string loadAllFuncName = "LoadAll";
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
protected Regex enumToDotNet = new Regex("_[a-z|A-Z]?", RegexOptions.Compiled);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
protected readonly char[] numbers = "0123456789".ToCharArray();
|
2009-03-21 21:44:07 +00:00
|
|
|
//protected static readonly Dictionary<string, string> doc_replacements;
|
2010-12-02 21:36:05 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
protected ISpecReader SpecReader { get; set; }
|
2013-11-03 00:27:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The Profile field corresponds to the "profile" attribute
|
|
|
|
/// in the OpenGL registry. We use this to distinguish between
|
|
|
|
/// different profiles (e.g. "gl", "glcore", "gles1", "gles2").
|
|
|
|
/// </summary>
|
2013-10-30 23:18:07 +00:00
|
|
|
protected string Profile = "gl";
|
2013-11-03 00:27:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The Version field corresponds to the "number" attribute
|
|
|
|
/// in the OpenGL registry. We use this to distinguish between
|
|
|
|
/// OpenGL ES 2.0 and 3.0, which share the same profile "gles2".
|
|
|
|
/// If empty, then all elements of a profile will be parsed, and
|
|
|
|
/// their version number will be ignored.
|
|
|
|
/// </summary>
|
|
|
|
protected string Version = String.Empty;
|
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
public Settings Settings { get; protected set; }
|
2010-12-02 21:36:05 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2010-12-02 21:36:05 +00:00
|
|
|
#region Constructors
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2013-11-03 00:27:10 +00:00
|
|
|
public Generator(Settings settings, string dirName)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2013-11-01 08:25:31 +00:00
|
|
|
if (settings == null)
|
|
|
|
throw new ArgumentNullException("settings");
|
2013-10-30 23:18:07 +00:00
|
|
|
if (dirName == null)
|
|
|
|
dirName = "GL2";
|
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
Settings = settings.Clone();
|
|
|
|
|
2013-10-30 23:18:07 +00:00
|
|
|
glTypemap = "GL2/gl.tm";
|
|
|
|
csTypemap = Settings.LanguageTypeMapFile;
|
|
|
|
|
|
|
|
enumSpec = Path.Combine(dirName, "signatures.xml");
|
|
|
|
enumSpecExt = String.Empty;
|
|
|
|
glSpec = Path.Combine(dirName, "signatures.xml");
|
|
|
|
glSpecExt = String.Empty;
|
|
|
|
Settings.OverridesFile = Path.Combine(dirName, "overrides.xml");
|
|
|
|
|
|
|
|
Settings.ImportsClass = "Core";
|
|
|
|
Settings.DelegatesClass = "Delegates";
|
|
|
|
Settings.OutputClass = "GL";
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
if (Settings.Compatibility == Settings.Legacy.Tao)
|
|
|
|
{
|
|
|
|
Settings.OutputNamespace = "Tao.OpenGl";
|
|
|
|
Settings.OutputClass = "Gl";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Defaults
|
|
|
|
}
|
2010-12-02 21:58:49 +00:00
|
|
|
|
2013-11-03 00:27:10 +00:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.OpenGL";
|
|
|
|
Settings.DefaultImportsFile = "GLCore.cs";
|
|
|
|
Settings.DefaultDelegatesFile = "GLDelegates.cs";
|
|
|
|
Settings.DefaultEnumsFile = "GLEnums.cs";
|
|
|
|
Settings.DefaultWrappersFile = "GL.cs";
|
2011-12-05 14:30:40 +00:00
|
|
|
|
|
|
|
Delegates = new DelegateCollection();
|
|
|
|
Enums = new EnumCollection();
|
|
|
|
Wrappers = new FunctionCollection();
|
2013-11-01 08:25:31 +00:00
|
|
|
|
|
|
|
SpecReader = new XmlSpecReader(Settings);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2010-12-03 10:21:50 +00:00
|
|
|
#region IBind Members
|
|
|
|
|
|
|
|
public DelegateCollection Delegates { get; private set; }
|
|
|
|
public EnumCollection Enums { get; private set; }
|
|
|
|
public FunctionCollection Wrappers { get; private set; }
|
2013-11-01 08:25:31 +00:00
|
|
|
public IDictionary<string, string> GLTypes { get; private set; }
|
|
|
|
public IDictionary<string, string> CSTypes { get; private set; }
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
public virtual void Process()
|
|
|
|
{
|
2010-12-06 14:34:16 +00:00
|
|
|
string overrides = Path.Combine(Settings.InputPath, Settings.OverridesFile);
|
2013-11-01 08:25:31 +00:00
|
|
|
|
|
|
|
GLTypes = SpecReader.ReadTypeMap(Path.Combine(Settings.InputPath, glTypemap));
|
|
|
|
CSTypes = SpecReader.ReadCSTypeMap(Path.Combine(Settings.InputPath, csTypemap));
|
|
|
|
|
2013-11-03 00:27:10 +00:00
|
|
|
SpecReader.ReadEnums(Path.Combine(Settings.InputPath, enumSpec), Enums, Profile, Version);
|
|
|
|
SpecReader.ReadEnums(overrides, Enums, Profile, Version);
|
|
|
|
SpecReader.ReadDelegates(Path.Combine(Settings.InputPath, glSpec), Delegates, Profile, Version);
|
|
|
|
SpecReader.ReadDelegates(overrides, Delegates, Profile, Version);
|
2010-12-06 14:34:16 +00:00
|
|
|
|
2013-11-01 08:25:31 +00:00
|
|
|
var enum_processor = new EnumProcessor(this, overrides);
|
|
|
|
var func_processor = new FuncProcessor(this, overrides);
|
2013-10-26 23:30:45 +00:00
|
|
|
|
2013-11-03 00:27:10 +00:00
|
|
|
Enums = enum_processor.Process(Enums, Profile);
|
2013-11-04 18:32:52 +00:00
|
|
|
Wrappers = func_processor.Process(enum_processor, Delegates, Enums, Profile, Version);
|
2009-02-28 19:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|