/// <summary> /// Generate all required files for OpenGL C# bindings. /// </summary> /// <param name="glRegistryProcessor"> /// The <see cref="RegistryProcessor"/> that actually process the OpenGL specification. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> that actually parses the OpenGL specification. /// </param> private static void GenerateCommandsAndEnums(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { Dictionary <string, bool> serializedCommands = new Dictionary <string, bool>(); Dictionary <string, bool> serializedEnums = new Dictionary <string, bool>(); glRegistryProcessor.GenerateStronglyTypedEnums(ctx, Path.Combine(BasePath, String.Format("{0}/{1}.Enums.cs", _OutputBasePath, ctx.Class)), null); #region By features and extensions foreach (IFeature feature in ctx.Registry.AllFeatures(ctx)) { List <Command> featureCommands = new List <Command>(); List <Enumerant> featureEnums = new List <Enumerant>(); #region Select enumerants and commands 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; } featureCommands.Add(command); } foreach (FeatureCommand.Item featureEnumItem in featureCommand.Enums) { Enumerant enumerant = ctx.Registry.GetEnumerant(featureEnumItem.Name); if (enumerant == null) { continue; } if (serializedEnums.ContainsKey(enumerant.Name)) { continue; } serializedEnums.Add(enumerant.Name, true); // Do not generate enumerant if it has an alias if (enumerant.EnumAlias != null) { continue; } featureEnums.Add(enumerant); } } #endregion if ((featureCommands.Count == 0) && (featureEnums.Count == 0)) { // No commands and no enumerations: remove file if existing string sourceFilePath = GetFeatureFilePath(feature, ctx); if (File.Exists(sourceFilePath)) { File.Delete(sourceFilePath); } // Next... continue; } glRegistryProcessor.GenerateCommands(ctx, GetFeatureFilePath(feature, ctx), delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", featureEnums.Count); foreach (Enumerant enumerant in featureEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", featureCommands.Count); foreach (Command command in featureCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } if (featureCommands.Count > 0) { GenerateCommandsImports(cctx, sw, featureCommands); sw.WriteLine(); } if (featureCommands.Count > 0) { GenerateCommandsDelegates(cctx, sw, featureCommands); } }); } #endregion #region Orphans List <Command> orphanCommands = new List <Command>(); List <Enumerant> orphanEnums = new List <Enumerant>(); foreach (Command command in ctx.Registry.Commands) { if (serializedCommands.ContainsKey(command.Prototype.Name)) { continue; } // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) { continue; } // Do not generate command with aliases if (command.Alias != null) { continue; } orphanCommands.Add(command); } foreach (Enumerant enumerant in ctx.Registry.Enumerants) { if (serializedEnums.ContainsKey(enumerant.Name)) { continue; } orphanEnums.Add(enumerant); } string orphanFile = Path.Combine(BasePath, String.Format("{0}/{1}.Orphans.cs", _OutputBasePath, ctx.Class)); if ((orphanCommands.Count != 0) || (orphanEnums.Count != 0)) { glRegistryProcessor.GenerateCommands(ctx, orphanFile, delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", orphanEnums.Count); foreach (Enumerant enumerant in orphanEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", orphanCommands.Count); foreach (Command command in orphanCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); } else { if (File.Exists(orphanFile)) { File.Delete(orphanFile); } } #endregion }
/// <summary> /// Generate all required files for OpenGL C# bindings. /// </summary> /// <param name="glRegistryProcessor"> /// The <see cref="RegistryProcessor"/> that actually process the OpenGL specification. /// </param> /// <param name="ctx"> /// The <see cref="RegistryContext"/> that actually parses the OpenGL specification. /// </param> private static void GenerateCommandsAndEnums(RegistryProcessor glRegistryProcessor, RegistryContext ctx) { Dictionary<string, bool> serializedCommands = new Dictionary<string, bool>(); Dictionary<string, bool> serializedEnums = new Dictionary<string, bool>(); glRegistryProcessor.GenerateStronglyTypedEnums(ctx, Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Enums.cs", ctx.Class)), null); glRegistryProcessor.GenerateCommandsImports(ctx, Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Imports.cs", ctx.Class)), null); glRegistryProcessor.GenerateCommandsDelegates(ctx, Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Delegates.cs", ctx.Class)), delegate(Command command) { return (command.Alias == null); }); #region By features and extensions foreach (IFeature feature in ctx.Registry.AllFeatures(ctx)) { List<Command> featureCommands = new List<Command>(); List<Enumerant> featureEnums = new List<Enumerant>(); #region Select enumerants and commands foreach (FeatureCommand featureCommand in feature.Requirements) { if (featureCommand.Api != null && !Regex.IsMatch(ctx.Class.ToLower(), 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; featureCommands.Add(command); } foreach (FeatureCommand.Item featureEnumItem in featureCommand.Enums) { Enumerant enumerant = ctx.Registry.GetEnumerant(featureEnumItem.Name); if (enumerant == null) continue; if (serializedEnums.ContainsKey(enumerant.Name)) continue; serializedEnums.Add(enumerant.Name, true); // Do not generate enumerant if it has an alias if (enumerant.EnumAlias != null) continue; featureEnums.Add(enumerant); } } #endregion if ((featureCommands.Count == 0) && (featureEnums.Count == 0)) { // No commands and no enumerations: remove file if existing string sourceFilePath = GetFeatureFilePath(feature, ctx); if (File.Exists(sourceFilePath)) File.Delete(sourceFilePath); // Next... continue; } glRegistryProcessor.GenerateCommands(ctx, GetFeatureFilePath(feature, ctx), delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", featureEnums.Count); foreach (Enumerant enumerant in featureEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", featureCommands.Count); foreach (Command command in featureCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); } #endregion #region Orphans List<Command> orphanCommands = new List<Command>(); List<Enumerant> orphanEnums = new List<Enumerant>(); foreach (Command command in ctx.Registry.Commands) { if (serializedCommands.ContainsKey(command.Prototype.Name)) continue; // Do not generate manually disabled command if ((command.Flags & CommandFlags.Disable) != 0) continue; // Do not generate command with aliases if (command.Alias != null) continue; orphanCommands.Add(command); } foreach (Enumerant enumerant in ctx.Registry.Enumerants) { if (serializedEnums.ContainsKey(enumerant.Name)) continue; orphanEnums.Add(enumerant); } string orphanFile = Path.Combine(BasePath, String.Format("OpenGL.NET/{0}.Orphans.cs", ctx.Class)); if ((orphanCommands.Count != 0) || (orphanEnums.Count != 0)) { glRegistryProcessor.GenerateCommands(ctx, orphanFile, delegate(RegistryContext cctx, SourceStreamWriter sw) { Console.WriteLine("\tGenerate {0} enumerants...", orphanEnums.Count); foreach (Enumerant enumerant in orphanEnums) { enumerant.GenerateSource(sw, ctx); sw.WriteLine(); } Console.WriteLine("\tGenerate {0} commands...", orphanCommands.Count); foreach (Command command in orphanCommands) { command.GenerateImplementations(sw, cctx); sw.WriteLine(); } }); } else { if (File.Exists(orphanFile)) File.Delete(orphanFile); } #endregion }