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;
|
2013-11-01 09:28:54 +01:00
|
|
|
using System.Collections.Generic;
|
2009-02-22 11:43:35 +01:00
|
|
|
using System.Diagnostics;
|
2009-08-25 17:46:22 +02:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2009-08-21 22:28:14 +02:00
|
|
|
using System.Reflection;
|
2009-08-17 14:28:22 +02:00
|
|
|
using System.Security;
|
2013-11-01 09:28:54 +01:00
|
|
|
using System.Text.RegularExpressions;
|
2009-08-21 22:28:14 +02:00
|
|
|
using Bind.CL;
|
|
|
|
using Bind.ES;
|
|
|
|
using Bind.GL2;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
namespace Bind
|
|
|
|
{
|
|
|
|
enum GeneratorMode
|
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
All = 0,
|
|
|
|
Default = All,
|
2009-02-22 11:43:35 +01:00
|
|
|
GL2,
|
|
|
|
GL3,
|
2013-11-01 09:28:54 +01:00
|
|
|
GL4,
|
2009-07-15 17:03:22 +02:00
|
|
|
ES10,
|
|
|
|
ES11,
|
|
|
|
ES20,
|
2013-11-01 09:28:54 +01:00
|
|
|
ES30,
|
2009-08-09 17:46:36 +02:00
|
|
|
CL10,
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
|
2010-12-03 11:21:50 +01:00
|
|
|
enum GeneratorLanguage
|
|
|
|
{
|
|
|
|
CSharp,
|
2011-12-02 12:27:04 +01:00
|
|
|
Cpp,
|
|
|
|
Java
|
2010-12-03 11:21:50 +01:00
|
|
|
}
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
static class MainClass
|
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
static GeneratorMode mode = GeneratorMode.Default;
|
|
|
|
static internal List<IBind> Generators = new List<IBind>();
|
|
|
|
static Settings Settings = new Settings();
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
static void Main(string[] arguments)
|
|
|
|
{
|
|
|
|
Debug.Listeners.Clear();
|
|
|
|
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
|
|
|
|
Debug.AutoFlush = true;
|
|
|
|
Trace.Listeners.Clear();
|
|
|
|
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
|
|
|
|
Trace.AutoFlush = true;
|
|
|
|
|
|
|
|
Console.WriteLine("OpenGL binding generator {0} for OpenTK.",
|
2009-08-21 22:28:14 +02:00
|
|
|
Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
2009-02-22 11:43:35 +01:00
|
|
|
Console.WriteLine("For comments, bugs and suggestions visit http://opentk.sourceforge.net");
|
|
|
|
Console.WriteLine();
|
|
|
|
|
2013-11-03 01:28:01 +01:00
|
|
|
string dirName = "GL2";
|
2009-08-25 17:46:22 +02:00
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
try
|
|
|
|
{
|
2010-12-06 16:19:45 +01:00
|
|
|
var split = new Regex(@"-\w+", RegexOptions.Compiled);
|
|
|
|
foreach (var argument in arguments)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2010-12-06 16:19:45 +01:00
|
|
|
string a = argument.Replace("--", "-").Trim();
|
|
|
|
var match = split.Match(a);
|
|
|
|
if (match.Success)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
2010-12-06 16:19:45 +01:00
|
|
|
string opt = match.Value.Substring(1).Trim();
|
|
|
|
string val = a.Substring(match.Value.Length + 1).Trim();
|
|
|
|
switch (opt)
|
2009-02-22 11:43:35 +01:00
|
|
|
{
|
|
|
|
case "?":
|
|
|
|
case "help":
|
|
|
|
ShowHelp();
|
|
|
|
return;
|
|
|
|
case "in":
|
|
|
|
case "input":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.InputPath = val;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
case "out":
|
|
|
|
case "output":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.OutputPath = val;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
2010-12-03 11:21:50 +01:00
|
|
|
case "l":
|
|
|
|
case "lang":
|
|
|
|
case "language":
|
|
|
|
{
|
2010-12-06 16:19:45 +01:00
|
|
|
string arg = val.ToLower();
|
2010-12-03 11:21:50 +01:00
|
|
|
if (arg == "cpp" || arg == "c++" || arg == "c")
|
2010-12-03 13:06:36 +01:00
|
|
|
{
|
2010-12-05 12:24:05 +01:00
|
|
|
Settings.Language = GeneratorLanguage.Cpp;
|
2010-12-03 13:06:36 +01:00
|
|
|
Settings.DefaultOutputPath = "gl";
|
2010-12-05 12:24:05 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK";
|
2011-12-02 14:12:53 +01:00
|
|
|
// Settings.DefaultLanguageTypeMapFile = "cpp.tm"; // Todo: create this file!
|
2010-12-05 12:24:05 +01:00
|
|
|
Settings.EnumsNamespace = "";
|
2010-12-05 16:45:23 +01:00
|
|
|
Settings.NamespaceSeparator = "::";
|
2011-12-05 12:49:59 +01:00
|
|
|
Settings.DefaultKeywordEscapeCharacter = "_";
|
2010-12-03 13:06:36 +01:00
|
|
|
}
|
2011-12-02 12:27:04 +01:00
|
|
|
else if (arg == "java")
|
|
|
|
{
|
|
|
|
Settings.Language = GeneratorLanguage.Java;
|
|
|
|
Settings.DefaultOutputPath = "gl";
|
|
|
|
Settings.DefaultOutputNamespace = "com.opentk";
|
2011-12-02 14:12:53 +01:00
|
|
|
Settings.DefaultLanguageTypeMapFile = "java.tm";
|
2011-12-02 12:27:04 +01:00
|
|
|
Settings.EnumsNamespace = "";
|
|
|
|
Settings.NamespaceSeparator = ".";
|
2011-12-05 12:49:59 +01:00
|
|
|
Settings.DefaultKeywordEscapeCharacter = "_";
|
2011-12-02 12:27:04 +01:00
|
|
|
}
|
2010-12-03 11:21:50 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
case "mode":
|
2010-12-03 11:21:50 +01:00
|
|
|
{
|
2010-12-06 16:19:45 +01:00
|
|
|
string arg = val.ToLower();
|
2010-12-03 13:06:36 +01:00
|
|
|
SetGeneratorMode(dirName, arg);
|
2010-12-03 11:21:50 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
case "namespace":
|
|
|
|
case "ns":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.OutputNamespace = val;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
case "class":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.OutputClass = val;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
case "gl":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.GLClass = val;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
case "legacy":
|
|
|
|
case "o":
|
|
|
|
case "option":
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.Compatibility |= val.ToLower() == "tao" ? Settings.Legacy.Tao : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= val.ToLower() == "simple_enums" ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= val.ToLower() == "safe" ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None;
|
2009-02-22 11:43:35 +01:00
|
|
|
//Settings.Compatibility |= b[1].ToLower().Contains("novoid") ? Settings.Legacy.TurnVoidPointersToIntPtr : Settings.Legacy.None;
|
2010-12-06 16:19:45 +01:00
|
|
|
Settings.Compatibility |= val.ToLower() == "permutations" ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= val.ToLower() == "enums_in_class" ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= val.ToLower() == "nodocs" ? Settings.Legacy.NoDocumentation : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= val.ToLower() == "keep_untyped_enums" ? Settings.Legacy.KeepUntypedEnums : Settings.Legacy.None;
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException(
|
|
|
|
String.Format("Argument {0} not recognized. Use the '/?' switch for help.", a)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NullReferenceException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Argument error ({0}). Please use the '-?' switch for help.", e.ToString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (ArgumentException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Argument error ({0}). Please use the '-?' switch for help.", e.ToString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
case GeneratorMode.All:
|
|
|
|
Console.WriteLine("Using 'all' generator mode.");
|
2013-11-03 01:28:01 +01:00
|
|
|
Console.WriteLine("Use '-mode:all/gl2/gl4/es10/es11/es20/es30' to select a specific mode.");
|
|
|
|
Generators.Add(new Generator(Settings, dirName));
|
|
|
|
Generators.Add(new GL4Generator(Settings, dirName));
|
|
|
|
Generators.Add(new ESGenerator(Settings, dirName));
|
|
|
|
Generators.Add(new ES2Generator(Settings, dirName));
|
|
|
|
Generators.Add(new ES3Generator(Settings, dirName));
|
2013-11-01 09:28:54 +01:00
|
|
|
break;
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
case GeneratorMode.GL2:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new Generator(Settings, dirName));
|
2013-10-31 00:18:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeneratorMode.GL3:
|
2013-11-01 09:28:54 +01:00
|
|
|
case GeneratorMode.GL4:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new GL4Generator(Settings, dirName));
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES10:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new ESGenerator(Settings, dirName));
|
2009-06-30 10:39:35 +02:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES11:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new ESGenerator(Settings, dirName));
|
2009-06-30 10:39:35 +02:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES20:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new ES2Generator(Settings, dirName));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeneratorMode.ES30:
|
|
|
|
Generators.Add(new ES3Generator(Settings, dirName));
|
2009-06-30 10:39:35 +02:00
|
|
|
break;
|
2009-07-22 16:36:39 +02:00
|
|
|
|
2009-08-09 17:46:36 +02:00
|
|
|
case GeneratorMode.CL10:
|
2013-11-03 01:28:01 +01:00
|
|
|
Generators.Add(new CLGenerator(Settings, dirName));
|
2009-07-22 16:36:39 +02:00
|
|
|
break;
|
2009-06-30 10:39:35 +02:00
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
default:
|
2013-11-03 01:28:01 +01:00
|
|
|
Console.WriteLine("Please specify a generator mode (use '-mode:gl2/gl4/es10/es11/es20/es30')");
|
2009-02-22 11:43:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
foreach (var generator in Generators)
|
2010-12-03 11:21:50 +01:00
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
long ticks = DateTime.Now.Ticks;
|
2010-12-03 11:21:50 +01:00
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
generator.Process();
|
2011-12-02 12:27:04 +01:00
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
ISpecWriter writer = null;
|
|
|
|
switch (generator.Settings.Language)
|
|
|
|
{
|
|
|
|
case GeneratorLanguage.Cpp:
|
|
|
|
writer = new CppSpecWriter();
|
|
|
|
break;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
case GeneratorLanguage.Java:
|
|
|
|
writer = new JavaSpecWriter();
|
|
|
|
break;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
case GeneratorLanguage.CSharp:
|
|
|
|
default:
|
|
|
|
writer = new CSharpSpecWriter();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writer.WriteBindings(generator);
|
|
|
|
|
|
|
|
ticks = DateTime.Now.Ticks - ticks;
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("Bindings generated in {0} seconds.", ticks / (double)10000000.0);
|
|
|
|
}
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
Console.WriteLine();
|
2010-10-13 23:31:24 +02:00
|
|
|
if (Debugger.IsAttached)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Press any key to continue...");
|
|
|
|
Console.ReadKey(true);
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
}
|
|
|
|
catch (SecurityException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Security violation \"{0}\" in method \"{1}\".", e.Message, e.Method);
|
|
|
|
Console.WriteLine("This application does not have permission to take the requested actions.");
|
|
|
|
}
|
|
|
|
catch (NotImplementedException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
Console.WriteLine("The requested functionality is not implemented yet.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 13:06:36 +01:00
|
|
|
private static void SetGeneratorMode(string dirName, string arg)
|
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
switch (arg)
|
2010-12-03 13:06:36 +01:00
|
|
|
{
|
2013-11-01 09:28:54 +01:00
|
|
|
case "gl":
|
|
|
|
case "gl2":
|
|
|
|
mode = GeneratorMode.GL2;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.OpenGL";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "gl3":
|
|
|
|
case "gl4":
|
|
|
|
mode = GeneratorMode.GL2;
|
2013-11-03 12:14:13 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.OpenGL4";
|
2013-11-01 09:28:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "es10":
|
|
|
|
mode = GeneratorMode.ES10;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES10";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "es11":
|
|
|
|
mode = GeneratorMode.ES11;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES11";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "es20":
|
|
|
|
mode = GeneratorMode.ES20;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES20";
|
|
|
|
break;
|
|
|
|
|
2013-11-03 01:28:01 +01:00
|
|
|
case "es30":
|
|
|
|
mode = GeneratorMode.ES30;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES30";
|
|
|
|
break;
|
|
|
|
|
2013-11-01 09:28:54 +01:00
|
|
|
case "cl":
|
|
|
|
case "cl10":
|
|
|
|
mode = GeneratorMode.CL10;
|
2013-11-03 01:28:01 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Compute.OpenCL";
|
2013-11-01 09:28:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new NotSupportedException();
|
2010-12-03 13:06:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
private static void ShowHelp()
|
|
|
|
{
|
|
|
|
Console.WriteLine(
|
2009-03-25 20:41:10 +01:00
|
|
|
@"Usage: bind [-in:path] [-out:path] [switches]
|
2009-02-22 11:43:35 +01:00
|
|
|
Available switches:
|
|
|
|
-in: Input directory (e.g. -in:../specs/)
|
|
|
|
-out: Output directory (e.g. -out:out)
|
2009-02-28 19:50:16 +01:00
|
|
|
-ns: Output namespace (e.g. -ns:OpenTK.Graphics).
|
2009-02-22 11:43:35 +01:00
|
|
|
Default: OpenTK.Graphics.OpenGL
|
|
|
|
-namespace: Same as -ns
|
|
|
|
-class: Output class (e.g. -class:GL3).
|
|
|
|
Default: GL/Wgl/Glu/Glx (depends on -mode)
|
2013-11-01 09:28:54 +01:00
|
|
|
-mode: Generator mode (e.g. -mode:gl4).
|
|
|
|
Default: all
|
|
|
|
Accepted: all/gl2/gl4/es10/es11/es20
|
2009-02-22 11:43:35 +01:00
|
|
|
-o/-option: Set advanced option. Available options:
|
|
|
|
-o:tao Tao compatibility mode.
|
|
|
|
-o:enums Follow OpenGL instead .Net naming conventions.
|
|
|
|
-o:safe Do not generate public unsafe functions.
|
|
|
|
-o:enums_in_class
|
|
|
|
Place enums in a nested class (i.e. GL.Enums)
|
|
|
|
instead of a namespace (i.e. OpenTK.Graphics.OpenGL.Enums)
|
|
|
|
");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|