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.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;
|
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
|
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
GL2,
|
|
|
|
GL3,
|
2009-07-15 17:03:22 +02:00
|
|
|
ES10,
|
|
|
|
ES11,
|
|
|
|
ES20,
|
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,
|
|
|
|
Cpp
|
|
|
|
}
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
static class MainClass
|
|
|
|
{
|
2009-03-25 20:41:10 +01:00
|
|
|
static GeneratorMode mode = GeneratorMode.GL2;
|
2009-02-22 11:43:35 +01:00
|
|
|
static internal IBind Generator;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2009-08-25 17:46:22 +02:00
|
|
|
string dirName = null;
|
|
|
|
|
2009-02-22 11:43:35 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (string a in arguments)
|
|
|
|
{
|
|
|
|
if (a.StartsWith("--") || a.StartsWith("-") || a.StartsWith("/"))
|
|
|
|
{
|
2010-12-05 23:58:20 +01:00
|
|
|
string[] b = a.Split(new char[] { '-', ':', '=' }, StringSplitOptions.RemoveEmptyEntries);
|
2009-02-22 11:43:35 +01:00
|
|
|
switch (b[0])
|
|
|
|
{
|
|
|
|
case "?":
|
|
|
|
case "help":
|
|
|
|
ShowHelp();
|
|
|
|
return;
|
|
|
|
case "in":
|
|
|
|
case "input":
|
2009-08-25 17:46:22 +02:00
|
|
|
Settings.InputPath = string.Join(Path.DirectorySeparatorChar.ToString(), b.Skip(1).ToArray());
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
case "out":
|
|
|
|
case "output":
|
2009-08-25 17:46:22 +02:00
|
|
|
Settings.OutputPath = string.Join(Path.DirectorySeparatorChar.ToString(), b.Skip(1).ToArray());
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
2010-12-03 11:21:50 +01:00
|
|
|
case "l":
|
|
|
|
case "lang":
|
|
|
|
case "language":
|
|
|
|
{
|
|
|
|
string arg = b[1].ToLower();
|
|
|
|
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";
|
|
|
|
Settings.EnumsNamespace = "";
|
2010-12-05 16:45:23 +01:00
|
|
|
Settings.NamespaceSeparator = "::";
|
2010-12-03 13:06:36 +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
|
|
|
{
|
|
|
|
string arg = b[1].ToLower();
|
2010-12-03 13:06:36 +01:00
|
|
|
SetGeneratorMode(dirName, arg);
|
2010-12-03 11:21:50 +01:00
|
|
|
if (b.Length > 2)
|
|
|
|
dirName = b[2];
|
|
|
|
break;
|
|
|
|
}
|
2009-02-22 11:43:35 +01:00
|
|
|
case "namespace":
|
|
|
|
case "ns":
|
|
|
|
Settings.OutputNamespace = b[1];
|
|
|
|
break;
|
|
|
|
case "class":
|
|
|
|
Settings.OutputClass = b[1];
|
|
|
|
break;
|
|
|
|
case "gl":
|
|
|
|
Settings.GLClass = b[1];
|
|
|
|
break;
|
|
|
|
case "legacy":
|
|
|
|
case "o":
|
|
|
|
case "option":
|
2009-10-27 23:37:05 +01:00
|
|
|
Settings.Compatibility |= b[1].ToLower() == "tao" ? Settings.Legacy.Tao : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= b[1].ToLower() == "simple_enums" ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= b[1].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;
|
2009-10-27 23:37:05 +01:00
|
|
|
Settings.Compatibility |= b[1].ToLower() == "permutations" ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= b[1].ToLower() == "enums_in_class" ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= b[1].ToLower() == "nodocs" ? Settings.Legacy.NoDocumentation : Settings.Legacy.None;
|
|
|
|
Settings.Compatibility |= b[1].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
|
|
|
|
{
|
2009-08-21 22:28:14 +02:00
|
|
|
long ticks = DateTime.Now.Ticks;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
2010-12-03 12:23:11 +01:00
|
|
|
case GeneratorMode.GL3:
|
2009-02-22 11:43:35 +01:00
|
|
|
case GeneratorMode.GL2:
|
2010-10-12 19:39:14 +02:00
|
|
|
Generator = new GL4Generator("OpenGL", dirName);
|
2009-02-22 11:43:35 +01:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES10:
|
2009-08-25 17:46:22 +02:00
|
|
|
Generator = new ESGenerator("ES10", dirName);
|
2009-06-30 10:39:35 +02:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES11:
|
2009-08-25 17:46:22 +02:00
|
|
|
Generator = new ESGenerator("ES11", dirName);
|
2009-06-30 10:39:35 +02:00
|
|
|
break;
|
|
|
|
|
2009-07-15 17:03:22 +02:00
|
|
|
case GeneratorMode.ES20:
|
2009-08-25 17:46:22 +02:00
|
|
|
Generator = new ESGenerator("ES20", 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:
|
2009-10-09 07:25:53 +02:00
|
|
|
Generator = new CLGenerator("CL10", 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
|
|
|
case GeneratorMode.Unknown:
|
|
|
|
default:
|
|
|
|
Console.WriteLine("Please specify a generator mode (use '-mode:gl2/gl3/glu/wgl/glx])'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Generator.Process();
|
2010-12-03 11:21:50 +01:00
|
|
|
ISpecWriter writer = null;
|
2010-12-05 12:24:05 +01:00
|
|
|
switch (Settings.Language)
|
2010-12-03 11:21:50 +01:00
|
|
|
{
|
|
|
|
case GeneratorLanguage.Cpp:
|
|
|
|
writer = new CppSpecWriter();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeneratorLanguage.CSharp:
|
|
|
|
default:
|
|
|
|
writer = new CSharpSpecWriter();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writer.WriteBindings(Generator);
|
2009-02-22 11:43:35 +01:00
|
|
|
|
2009-08-21 22:28:14 +02:00
|
|
|
ticks = DateTime.Now.Ticks - ticks;
|
2009-02-22 11:43:35 +01:00
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("Bindings generated in {0} seconds.", ticks / (double)10000000.0);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (arg == "gl" || arg == "gl2" || arg == "gl3" || arg == "gl4")
|
|
|
|
{
|
|
|
|
mode = GeneratorMode.GL2;
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.OpenGL";
|
|
|
|
}
|
|
|
|
else if (arg == "es10")
|
|
|
|
{
|
|
|
|
mode = GeneratorMode.ES10;
|
|
|
|
Settings.DefaultOutputPath = Path.Combine(
|
|
|
|
Directory.GetParent(Settings.DefaultOutputPath).ToString(),
|
|
|
|
dirName);
|
2010-12-05 03:19:47 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES10";
|
2010-12-03 13:06:36 +01:00
|
|
|
}
|
|
|
|
else if (arg == "es11")
|
|
|
|
{
|
|
|
|
mode = GeneratorMode.ES11;
|
|
|
|
Settings.DefaultOutputPath = Path.Combine(
|
|
|
|
Directory.GetParent(Settings.DefaultOutputPath).ToString(),
|
|
|
|
dirName);
|
2010-12-05 03:19:47 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES11";
|
2010-12-03 13:06:36 +01:00
|
|
|
}
|
|
|
|
else if (arg == "es20")
|
|
|
|
{
|
|
|
|
mode = GeneratorMode.ES20;
|
|
|
|
Settings.DefaultOutputPath = Path.Combine(
|
|
|
|
Directory.GetParent(Settings.DefaultOutputPath).ToString(),
|
|
|
|
dirName);
|
2010-12-05 03:19:47 +01:00
|
|
|
Settings.DefaultOutputNamespace = "OpenTK.Graphics.ES20";
|
2010-12-03 13:06:36 +01:00
|
|
|
}
|
|
|
|
else if (arg == "cl" || arg == "cl10")
|
|
|
|
{
|
|
|
|
mode = GeneratorMode.CL10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
-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)
|
|
|
|
");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|