Opentk/Source/Bind/Main.cs

218 lines
8.6 KiB
C#
Raw Normal View History

#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Text;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Collections.Generic;
using System.CodeDom;
using System.Diagnostics;
namespace Bind
{
enum GeneratorMode
{
Unknown,
GL2,
GL3,
2009-06-30 10:39:35 +02:00
GLES10,
GLES11,
GLES20,
Wgl,
Glx,
Glu,
}
static class MainClass
{
static GeneratorMode mode = GeneratorMode.GL2;
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.",
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
Console.WriteLine("For comments, bugs and suggestions visit http://opentk.sourceforge.net");
//Console.WriteLine(" - the OpenTK team ;-)");
Console.WriteLine();
try
{
foreach (string a in arguments)
{
if (a.StartsWith("--") || a.StartsWith("-") || a.StartsWith("/"))
{
string[] b = a.Split(new char[] { '-', '/', ':', '=' }, StringSplitOptions.RemoveEmptyEntries);
switch (b[0])
{
case "?":
case "help":
ShowHelp();
return;
case "in":
case "input":
Settings.InputPath = b[1];
break;
case "out":
case "output":
Settings.OutputPath = b[1];
break;
case "mode":
string arg = b[1].ToLower();
2009-06-30 10:39:35 +02:00
if (arg == "gl" || arg == "gl2")
mode = GeneratorMode.GL2;
2009-06-30 10:39:35 +02:00
else if (arg == "gles10")
mode = GeneratorMode.GLES10;
else if (arg == "gles11")
mode = GeneratorMode.GLES11;
else if (arg == "gles20")
mode = GeneratorMode.GLES20;
else
throw new NotImplementedException();
break;
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":
Settings.Compatibility |= b[1].ToLower().Contains("tao") ? Settings.Legacy.Tao : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("enums") ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("safe") ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None;
//Settings.Compatibility |= b[1].ToLower().Contains("novoid") ? Settings.Legacy.TurnVoidPointersToIntPtr : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("permutations") ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower().Contains("enums_in_class") ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
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
{
long ticks = System.DateTime.Now.Ticks;
switch (mode)
{
case GeneratorMode.GL2:
Generator = new Bind.GL2.Generator();
break;
2009-06-30 10:39:35 +02:00
case GeneratorMode.GLES10:
Generator = new Bind.GLES.GlesGenerator("GLES10");
break;
case GeneratorMode.GLES11:
Generator = new Bind.GLES.GlesGenerator("GLES11");
break;
case GeneratorMode.GLES20:
Generator = new Bind.GLES.GlesGenerator("GLES20");
break;
case GeneratorMode.Wgl:
Generator = new Bind.Wgl.Generator();
break;
case GeneratorMode.Glu:
Generator = new Bind.Glu.Generator();
break;
case GeneratorMode.Glx:
Generator = new Bind.Glx.Generator();
break;
case GeneratorMode.GL3:
throw new NotImplementedException(String.Format("Mode {0} not implemented.", mode));
case GeneratorMode.Unknown:
default:
Console.WriteLine("Please specify a generator mode (use '-mode:gl2/gl3/glu/wgl/glx])'");
return;
}
Generator.Process();
ticks = System.DateTime.Now.Ticks - ticks;
Console.WriteLine();
Console.WriteLine("Bindings generated in {0} seconds.", ticks / (double)10000000.0);
Console.WriteLine();
}
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.");
}
finally
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
private static void ShowHelp()
{
Console.WriteLine(
@"Usage: bind [-in:path] [-out:path] [switches]
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).
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)
");
}
}
}