/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="filter"></param> public void GenerateEnums(RegistryContext ctx, string path, EnumerantFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); List<Enumerant> enumerants = mRegistry.Enumerants; if ((filter != null) && (enumerants.FindIndex(delegate(Enumerant item) { return (filter(item)); }) < 0)) return; Console.WriteLine("Generate registry enums to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in mRegistry.Enumerants) { if ((filter != null) && (filter(enumerant) == false)) continue; enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
private static void GenerateVersionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.Versions.cs", ctx.Class); Console.WriteLine("Generate version support class to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("#region Known Versions Constants"); sw.WriteLine(); foreach (Feature featureVersion in ctx.Registry.Features) { if (featureVersion.Number == null) continue; // Determine version value (support up to 3 version numbers) Match versionMatch = Regex.Match(featureVersion.Number, @"(?<Major>\d+)\.(?<Minor>\d+)(\.(?<Rev>\d+))?"); if (versionMatch.Success == false) continue; int versionMajor = Int32.Parse(versionMatch.Groups["Major"].Value); int versionMinor = Int32.Parse(versionMatch.Groups["Minor"].Value); int versionRev = versionMatch.Groups["Rev"].Success ? Int32.Parse(versionMatch.Groups["Rev"].Value) : 0; int versionValue = versionMajor * 100 + versionMinor * 10 + versionRev; // Determine version name string versionName = String.Format("Version_{0}", versionValue); if (featureVersion.IsEsVersion) versionName = String.Format("Version_{0}ES", versionValue); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Version for {0} API.", SpecificationStyle.GetKhronosVersionHumanReadable(featureVersion.Name)); sw.WriteLine("/// </summary>"); sw.WriteLine("public const int {0} = {1};", versionName, versionValue); sw.WriteLine(); } sw.WriteLine("#endregion"); sw.WriteLine(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
private static void GenerateExtensionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.Extensions.cs", ctx.Class); Console.WriteLine("Generate registry khronosExtensions to {0}.", path); SortedList<int, List<IFeature>> khronosExtensions = new SortedList<int, List<IFeature>>(); SortedList<int, List<IFeature>> vendorExtensions = new SortedList<int, List<IFeature>>(); foreach (IFeature feature in ctx.Registry.Extensions) { SortedList<int, List<IFeature>> extensionDict; List<IFeature> extensionFeatures; if (Extension.IsArbVendor(feature.Name)) extensionDict = khronosExtensions; else extensionDict = vendorExtensions; int index = ExtensionIndices.GetIndex(feature.Name); if (extensionDict.TryGetValue(index, out extensionFeatures) == false) { extensionFeatures = new List<IFeature>(); extensionDict.Add(index, extensionFeatures); } extensionFeatures.Add(feature); } using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Extension support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class Extensions : ExtensionsCollection"); sw.WriteLine("{"); sw.Indent(); foreach (KeyValuePair<int, List<IFeature>> pair in khronosExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) sw.WriteLine("[Extension(\"{0}\")]", feature.Name); Extension mainExtension = (Extension)mainFeature; if (String.IsNullOrEmpty(mainExtension.Supported) == false) sw.WriteLine("[ExtensionSupport(\"{0}\")]", mainExtension.Supported); sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } foreach (KeyValuePair<int, List<IFeature>> pair in vendorExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) sw.WriteLine("[Extension(\"{0}\")]", feature.Name); sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommandsDelegates(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("#pragma warning disable 649, 1572, 1573"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Delegates // Write delegates sw.WriteLine("internal unsafe static partial class Delegates"); sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) continue; if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateDelegate(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommandsImports(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) throw new ArgumentNullException("path"); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Imports // Write delegates switch (ctx.Class) { // Glx and Wgl classes exposes public unsafe native methods: let UnsafeNativeMethods be public (note: automatically // generated members have internal scope) case "Glx": case "Wgl": sw.WriteLine("public unsafe static partial class UnsafeNativeMethods"); break; default: sw.WriteLine("internal unsafe static partial class UnsafeNativeMethods"); break; } sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) continue; if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateImport(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommands(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) throw new ArgumentNullException("path"); Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); // Warning CS1734 XML comment on 'method' has a paramref tag for 'param', but there is no parameter by that name sw.WriteLine("#pragma warning disable 1734"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommands(RegistryContext ctx, string path, CommandSerializerDelegate filter) { if (path == null) throw new ArgumentNullException("path"); Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // Function implementations filter(ctx, sw); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
private static void GenerateVbCommands(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { Dictionary <string, bool> serializedCommands = new Dictionary <string, bool>(); Dictionary <string, bool> serializedEnums = new Dictionary <string, bool>(); List <Command> featureVbCommands = new List <Command>(); List <Enumerant> featureVbEnums = new List <Enumerant>(); Console.WriteLine("Testing for VB.Net incompatibilities."); #region Select VB incompatible commands foreach (IFeature feature in ctx.Registry.AllFeatures(ctx)) { foreach (FeatureCommand featureCommand in feature.Requirements) { if (featureCommand.Api != null && !ctx.IsSupportedApi(featureCommand.Api)) { Console.WriteLine("Skip command: API {1} not supported", featureCommand.Api); continue; } foreach (FeatureCommand.Item featureCommandItem in featureCommand.Commands) { Command command = ctx.Registry.GetCommand(featureCommandItem.Name); Debug.Assert(command != null); if (serializedCommands.ContainsKey(command.Prototype.Name)) { continue; } serializedCommands.Add(command.Prototype.Name, true); // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) { continue; } // Do not generate command with aliases if (command.Alias != null) { continue; } // Do not generate methods not conflicting with enumerations having the same name with different case Enumerant enumInConflict = ctx.Registry.GetEnumerantNoCase(command.GetImplementationName(ctx)); if (enumInConflict == null) { continue; } // VB.Net command featureVbCommands.Add(command); if (serializedEnums.ContainsKey(enumInConflict.Name)) { continue; } serializedEnums.Add(enumInConflict.Name, true); // VB.Net enum featureVbEnums.Add(enumInConflict); } } } #endregion string path = Path.Combine(BasePath, String.Format("{0}/{1}.Vb.cs", _OutputBasePath, ctx.Class)); if (featureVbCommands.Count > 0) { Console.WriteLine("Generate registry commands to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { RegistryProcessor.GenerateLicensePreamble(sw); // Warning CS1734 XML comment on 'method' has a paramref tag for 'param', but there is no parameter by that name // sw.WriteLine("#pragma warning disable 1734"); // sw.WriteLine(); sw.WriteLine("#pragma warning disable 649, 1572, 1573"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Diagnostics;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Class for scoping those methods conflicting with other fields/enums."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); // VB Commands class sw.WriteLine("public static class VB"); sw.WriteLine("{"); sw.Indent(); // VB Function implementations foreach (Command command in featureVbCommands) { command.GenerateImplementations(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); // VB Commands class sw.WriteLine(); sw.WriteLine("public static class VBEnum"); sw.WriteLine("{"); sw.Indent(); // VB Function implementations foreach (Enumerant enumerant in featureVbEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } } else { if (File.Exists(path)) { File.Delete(path); } } }
private static void GenerateExtensionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("{0}/{1}.Extensions.cs", _OutputBasePath, ctx.Class); Console.WriteLine("Generate registry khronosExtensions to {0}.", path); SortedList <int, List <IFeature> > khronosExtensions = new SortedList <int, List <IFeature> >(); SortedList <int, List <IFeature> > vendorExtensions = new SortedList <int, List <IFeature> >(); foreach (IFeature feature in ctx.Registry.Extensions) { SortedList <int, List <IFeature> > extensionDict; List <IFeature> extensionFeatures; if (Extension.IsArbVendor(feature.Name)) { extensionDict = khronosExtensions; } else { extensionDict = vendorExtensions; } int index = ExtensionIndices.GetIndex(feature.Name); if (extensionDict.TryGetValue(index, out extensionFeatures) == false) { extensionFeatures = new List <IFeature>(); extensionDict.Add(index, extensionFeatures); } extensionFeatures.Add(feature); } using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace {0}", _Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Extension support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public partial class Extensions : ExtensionsCollection"); sw.WriteLine("{"); sw.Indent(); foreach (KeyValuePair <int, List <IFeature> > pair in khronosExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) { if (feature.Api != null && feature.Api != ctx.Class.ToLower()) { sw.WriteLine("[Extension(\"{0}\", Api = \"{1}\")]", feature.Name, feature.Api); } else { sw.WriteLine("[Extension(\"{0}\")]", feature.Name); } } Extension mainExtension = (Extension)mainFeature; if (String.IsNullOrEmpty(mainExtension.Supported) == false) { sw.WriteLine("[ExtensionSupport(\"{0}\")]", mainExtension.Supported); } sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } foreach (KeyValuePair <int, List <IFeature> > pair in vendorExtensions) { IFeature mainFeature = pair.Value[0]; string extensionFieldName = SpecificationStyle.GetExtensionBindingName(mainFeature.Name); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Support for extension {0}.", mainFeature.Name); sw.WriteLine("/// </summary>"); foreach (IFeature feature in pair.Value) { if (feature.Api != null && feature.Api != ctx.Class.ToLower()) { sw.WriteLine("[Extension(\"{0}\", Api = \"{1}\")]", feature.Name, feature.Api); } else { sw.WriteLine("[Extension(\"{0}\")]", feature.Name); } } sw.WriteLine("public bool {0};", extensionFieldName); sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateVersionsSupportClass(RegistryContext ctx) { string path = String.Format("{0}/{1}.Versions.cs", Program.OutputBasePath, ctx.Class); Console.WriteLine("Generate version support class to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(Program.BasePath, path), false)) { GenerateLicensePreamble(sw); sw.WriteLine("using Khronos;"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("#region Known Versions Constants"); sw.WriteLine(); foreach (Feature featureVersion in ctx.Registry.Features) { if (featureVersion.Number == null) { continue; } // Determine version value (support up to 3 version numbers) Match versionMatch = Regex.Match(featureVersion.Number, @"(?<Major>\d+)\.(?<Minor>\d+)(\.(?<Rev>\d+))?"); if (versionMatch.Success == false) { continue; } int versionMajor = Int32.Parse(versionMatch.Groups["Major"].Value); int versionMinor = Int32.Parse(versionMatch.Groups["Minor"].Value); int versionRev = versionMatch.Groups["Rev"].Success ? Int32.Parse(versionMatch.Groups["Rev"].Value) : 0; int versionValue = versionMajor * 100 + versionMinor * 10 + versionRev; // Determine version/api name string versionName = String.Format("Version_{0}", versionValue); string api = ctx.Class; if (featureVersion.IsEsVersion) { versionName = String.Format("Version_{0}_ES", versionValue); switch (versionMajor) { case 1: api = "Gles1"; break; case 2: default: api = "Gles2"; break; } } else if (featureVersion.IsScVersion) { versionName = String.Format("Version_{0}_SC", versionValue); api = "Glsc2"; } sw.WriteLine("/// <summary>"); sw.WriteLine("/// Version for {0} API.", SpecificationStyle.GetKhronosVersionHumanReadable(featureVersion.Name)); sw.WriteLine("/// </summary>"); if (versionRev != 0) { sw.WriteLine("public static readonly KhronosVersion {0} = new KhronosVersion({1}, {2}, {3}, KhronosVersion.Api{4});", versionName, versionMajor, versionMinor, versionRev, api); } else { sw.WriteLine("public static readonly KhronosVersion {0} = new KhronosVersion({1}, {2}, KhronosVersion.Api{3});", versionName, versionMajor, versionMinor, api); } sw.WriteLine(); } sw.WriteLine("#endregion"); sw.WriteLine(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateLimitsSupportClass(RegistryContext ctx) { string path = String.Format("{0}/{1}.Limits.cs", Program.OutputBasePath, ctx.Class); List <Enumerant> limitEnums = new List <Enumerant>(); foreach (Enumerant enumerant in ctx.Registry.Enumerants) { // Skip enumeration with aliases if (enumerant.EnumAlias != null) { continue; } bool maxLimit = enumerant.Name.StartsWith("GL_MAX_"); bool minLimit = enumerant.Name.StartsWith("GL_MIN_"); if (!maxLimit && !minLimit) { continue; } if (CommandFlagsDatabase.IsExcludedLimit(enumerant.Name)) { continue; } limitEnums.Add(enumerant); } foreach (CommandFlagsDatabase.Limit limit in CommandFlagsDatabase.GetLimits()) { if (limitEnums.Exists(delegate(Enumerant item) { return(item.Name == limit.Name); })) { continue; } Enumerant addedEnum = ctx.Registry.GetEnumerant(limit.Name); Debug.Assert(addedEnum != null); if (addedEnum == null) { continue; } limitEnums.Add(addedEnum); } Console.WriteLine("Generate API limits to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(Program.BasePath, path), false)) { GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("using Khronos;"); sw.WriteLine(); sw.WriteLine("namespace {0}", Namespace); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("/// <summary>"); sw.WriteLine("/// Limits support listing."); sw.WriteLine("/// </summary>"); sw.WriteLine("public sealed partial class Limits"); sw.WriteLine("{"); sw.Indent(); foreach (Enumerant enumerant in limitEnums) { // Filter enumerant CommandFlagsDatabase.Limit limit = CommandFlagsDatabase.GetLimit(enumerant.Name); string fieldName = SpecificationStyle.GetCamelCase(ctx, enumerant.ImplementationName); string fieldType = "int"; int fieldLength = 1; if (limit != null) { fieldType = limit.Type; fieldLength = limit.Length; } enumerant.GenerateDocumentation(sw, ctx); if (fieldLength > 1) { sw.WriteLine("[Limit({0}, ArrayLength = {1})]", enumerant.ImplementationName, fieldLength); enumerant.GenerateRequirements(sw, ctx); StringBuilder sb = new StringBuilder(); sb.AppendFormat("public {0}[] {1} = new {0}[] {{", fieldType, fieldName); for (int i = 0; i < fieldLength; i++) { switch (fieldType) { case "int": sb.Append("0"); break; case "float": sb.Append("0.0f"); break; } if (i < fieldLength - 1) { sb.Append(", "); } } sb.Append(" };"); sw.WriteLine(sb.ToString()); } else { sw.WriteLine("[Limit({0})]", enumerant.ImplementationName); enumerant.GenerateRequirements(sw, ctx); sw.WriteLine("public {0} {1};", fieldType, fieldName); } sw.WriteLine(); } sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommandsDelegates(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("#pragma warning disable 649, 1572, 1573"); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Delegates // Write delegates sw.WriteLine("internal unsafe static partial class Delegates"); sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) { continue; } if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateDelegate(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
public void GenerateCommandsImports(RegistryContext ctx, string path, CommandFilterDelegate filter) { if (path == null) { throw new ArgumentNullException("path"); } using (SourceStreamWriter sw = new SourceStreamWriter(path, false)) { GenerateLicensePreamble(sw); sw.WriteLine("using System;"); sw.WriteLine("using System.Security;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine(); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public unsafe partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); #region Function Imports // Write delegates switch (ctx.Class) { // Glx and Wgl classes exposes public unsafe native methods: let UnsafeNativeMethods be public (note: automatically // generated members have internal scope) case "Glx": case "Wgl": sw.WriteLine("public unsafe static partial class UnsafeNativeMethods"); break; default: sw.WriteLine("internal unsafe static partial class UnsafeNativeMethods"); break; } sw.WriteLine("{"); sw.Indent(); foreach (Command command in mRegistry.Commands) { if ((filter != null) && (filter(command) == false)) { continue; } if ((command.Flags & CommandFlags.Disable) == 0) { command.GenerateImport(sw, ctx); sw.WriteLine(); } } sw.Unindent(); sw.WriteLine("}"); #endregion sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }
private static void GenerateVersionsSupportClass(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { string path = String.Format("OpenGL.NET/{0}.Versions.cs", ctx.Class); Console.WriteLine("Generate version support class to {0}.", path); using (SourceStreamWriter sw = new SourceStreamWriter(Path.Combine(BasePath, path), false)) { RegistryProcessor.GenerateLicensePreamble(sw); sw.WriteLine("namespace OpenGL"); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("public partial class {0}", ctx.Class); sw.WriteLine("{"); sw.Indent(); sw.WriteLine("#region Known Versions Constants"); sw.WriteLine(); foreach (Feature featureVersion in ctx.Registry.Features) { if (featureVersion.Number == null) { continue; } // Determine version value (support up to 3 version numbers) Match versionMatch = Regex.Match(featureVersion.Number, @"(?<Major>\d+)\.(?<Minor>\d+)(\.(?<Rev>\d+))?"); if (versionMatch.Success == false) { continue; } int versionMajor = Int32.Parse(versionMatch.Groups["Major"].Value); int versionMinor = Int32.Parse(versionMatch.Groups["Minor"].Value); int versionRev = versionMatch.Groups["Rev"].Success ? Int32.Parse(versionMatch.Groups["Rev"].Value) : 0; int versionValue = versionMajor * 100 + versionMinor * 10 + versionRev; // Determine version name string versionName = String.Format("Version_{0}", versionValue); if (featureVersion.IsEsVersion) { versionName = String.Format("Version_{0}ES", versionValue); } sw.WriteLine("/// <summary>"); sw.WriteLine("/// Version for {0} API.", SpecificationStyle.GetKhronosVersionHumanReadable(featureVersion.Name)); sw.WriteLine("/// </summary>"); sw.WriteLine("public const int {0} = {1};", versionName, versionValue); sw.WriteLine(); } sw.WriteLine("#endregion"); sw.WriteLine(); sw.Unindent(); sw.WriteLine("}"); sw.Unindent(); sw.WriteLine(); sw.WriteLine("}"); } }