Example #1
0
        public static void Main(string[] args)
        {
            XmlSpecParser xmlParser = new XmlSpecParser();
            DotNetTranslator translator = new DotNetTranslator();
            DotNetFileWriter writer = new DotNetFileWriter();

            var glSpec = xmlParser.Parse(@"specs\gl.xml", @"specs\gl.overrides.xml", new XmlSpecParser.Options()
                {
                    Prefix = "gl",
                });
            XmlSerializer.WriteToFile(glSpec, "glSpecData.xml");

            var glCommands = glSpec.Features.Where(x => x.Api == "gl" && (x.VersionMajor <= 3 || (x.VersionMajor == 4 && x.VersionMinor <= 5))).SelectMany(x => x.Commands);

            var glApi = translator.Translate(glSpec, new DotNetTranslator.Options()
                {
                    Prefix = "gl",
                    CommandFilter = x => glCommands.Contains(x.Name)
                });
            XmlSerializer.WriteToFile(glApi, "glDotNetData.xml");

            writer.WriteFiles(glApi, new DotNetFileWriter.Options()
                {
                    Prefix = "GL",
                    OutputPath = @"..\..\..\GLDotNet.GL\",
                    Namespace = "GLDotNet.GL",
                    ConstantsFileName = "GLContext.Constants.Generated.cs",
                    EnumsFileName = "GLEnums.Generated.cs",
                    FunctionsFileName = "GLFunctions.Generated.cs",
                    FunctionsClassName = "GLFunctions",
                    ContextFileName = "GLContext.Generated.cs",
                    ContextClassName = "GLContext"
                });
        }
Example #2
0
        private static void WriteGL(XmlSpecData glSpec, DotNetTranslator translator, DotNetFileWriter writer)
        {
            Console.WriteLine("GLDotNet.GL");

            var glCommands = glSpec.Features.Where(x => x.Api == "gl" && (x.VersionMajor <= 3 || (x.VersionMajor == 4 && x.VersionMinor <= 5))).SelectMany(x => x.AddedCommands);

            var glApi = translator.Translate(glSpec, new DotNetTranslator.Options()
            {
                Prefix = "gl",
                CommandFilter = x => glCommands.Contains(x.Name),
                EnumGroupFilter = ShouldOutputEnumGroup,
                EnumFilter = ShouldOutputEnum
            });
            //XmlSerializer.WriteToFile(glApi, "glDotNetData.xml");

            writer.WriteFiles(glApi, new DotNetFileWriter.Options()
            {
                Prefix = "GL",
                OutputPath = @"..\..\..\GLDotNet.GL\",
                Namespace = "GLDotNet.GL",
                ConstantsFileName = "GLConstants.Generated.cs",
                ConstantsClassName = "GLConstants",
                EnumsFileName = "GLEnums.Generated.cs",
                CommandsFileName = "GLCommands.Generated.cs",
                CommandsClassName = "GLCommands",
                ContextFileName = "GLContext.Generated.cs",
                ContextClassName = "GLContext",
                ContextInitializeDelegatesByVersionNumber = true
            });
        }
Example #3
0
        public static void Main(string[] args)
		{
			XmlSpecParser xmlParser = new XmlSpecParser();
			DotNetTranslator translator = new DotNetTranslator();
			DotNetFileWriter writer = new DotNetFileWriter();

            var glSpec = xmlParser.Parse(@"specs\gl.xml", @"specs\gl.overrides.xml", new XmlSpecParser.Options()
                {
                    Prefix = "gl",
                });
			//XmlSerializer.WriteToFile(glSpec, "glSpecData.xml");

            WriteGL(glSpec, translator, writer);

            WriteGLVersions(glSpec, translator, writer);
		}
Example #4
0
        private static void WriteGLVersions(XmlSpecData glSpec, DotNetTranslator translator, DotNetFileWriter writer)
        {
            string basePath = Path.Combine("..", "..", "..", "GLDotNet.GL");

            var baseProjectFile = XDocument.Load(Path.Combine(basePath, "GLDotNet.GL.csproj"));
            var projectXmlNamespace = baseProjectFile.Root.GetDefaultNamespace();
            baseProjectFile.Root.Descendants(projectXmlNamespace + "Compile").First().Parent.Name = projectXmlNamespace + "CompileItemGroup";
            baseProjectFile.Root.Descendants(projectXmlNamespace + "Compile").Remove();

            var glVersions = glSpec.Features
                .Where(x => x.Api == "gl")
                .OrderBy(x => x.VersionMajor)
                .ThenBy(x => x.VersionMinor)
                .ToArray();

            // Start at 1 because GL version 1.0 seems to not work correctly...
            for (int i = 1; i < glVersions.Length; i++)
            {
                var path = basePath + glVersions[i].VersionMajor + glVersions[i].VersionMinor;
                var ns = "GLDotNet.GL" + glVersions[i].VersionMajor + glVersions[i].VersionMinor;
                var projectGuid = CalculateProjectGuid(ns);

                Console.WriteLine($"{ns} {projectGuid}");

                var glEnums = new List<string>();
                var glCommands = new List<string>();

                for (int j = 0; j <= i; j++)
                {
                    glEnums.AddRange(glVersions[j].AddedEnums);
                    glCommands.AddRange(glVersions[j].AddedCommands);

                    glEnums.RemoveAll(x => glVersions[j].RemovedEnums.Contains(x));
                    glCommands.RemoveAll(x => glVersions[j].RemovedCommands.Contains(x));
                }

                Directory.CreateDirectory(path);

                var glApi = translator.Translate(glSpec, new DotNetTranslator.Options()
                {
                    Prefix = "gl",
                    CommandFilter = x => glCommands.Contains(x.Name),
                    EnumGroupFilter = ShouldOutputEnumGroup,
                    EnumFilter = x => ShouldOutputEnum(x) && glEnums.Contains(x.Name),
                    DocsFolder = glVersions[i].VersionMajor >= 2 ? Path.Combine("docs", "man" + glVersions[i].VersionMajor.ToString()) : null
                });

                writer.WriteFiles(glApi, new DotNetFileWriter.Options()
                {
                    Prefix = "GL",
                    OutputPath = path,
                    Namespace = ns,
                    ConstantsFileName = "GLConstants.Generated.cs",
                    ConstantsClassName = "GLConstants",
                    EnumsFileName = "GLEnums.Generated.cs",
                    CommandsFileName = "GLCommands.Generated.cs",
                    CommandsClassName = "GLCommands",
                    ContextFileName = "GLContext.Methods.Generated.cs",
                    ContextClassName = "GLContext"
                });

                var projectFile = new XDocument(baseProjectFile);
                projectFile.Root.Descendants(projectXmlNamespace + "ProjectGuid").Single().Value = "{" + projectGuid.ToString().ToUpper() + "}";
                projectFile.Root.Descendants(projectXmlNamespace + "RootNamespace").Single().Value = ns;
                projectFile.Root.Descendants(projectXmlNamespace + "AssemblyName").Single().Value = ns;

                foreach (var documentationNode in projectFile.Root.Descendants(projectXmlNamespace + "DocumentationFile"))
                    documentationNode.Value = documentationNode.Value.Replace("GLDotNet.GL", ns);

                var compileItemGroup = projectFile.Root.Descendants(projectXmlNamespace + "CompileItemGroup").Single();

                foreach (var file in Directory.EnumerateFiles(path, "*.cs").Select(x => Path.GetFileName(x)))
                {
                    compileItemGroup.Add(new XElement(projectXmlNamespace + "Compile", new XAttribute("Include", file)));
                }

                compileItemGroup.Add(new XElement(projectXmlNamespace + "Compile", new XAttribute("Include", @"Properties\AssemblyInfo.cs")));

                compileItemGroup.Name = projectXmlNamespace + "ItemGroup";

                File.WriteAllText(Path.Combine(path, ns + ".csproj"), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine + projectFile.ToString());

                Directory.CreateDirectory(Path.Combine(path, "Properties"));

                TemplateEngine.Run("AssemblyVersion", Path.Combine(path, "Properties", "AssemblyVersion.cs"), new Dictionary<string, string>()
                {
                    ["Namespace"] = ns,
                    ["ProjectGuid"] = projectGuid.ToString()
                });

                TemplateEngine.Run("GLContext", Path.Combine(path, "GLContext.Generated.cs"), new Dictionary<string, string>()
                {
                    ["Namespace"] = ns
                });
            }
        }