示例#1
0
        static void GenerateVkEnums(VkEntityInspector inspector)
        {
            if (!Directory.Exists("Enums"))
            {
                Directory.CreateDirectory("Enums");
            }

            foreach (var container in inspector.Enums.Values)
            {
                using (var interfaceFile = new StreamWriter(Path.Combine("Enums", container.name + ".cs"), false))
                {
                    interfaceFile.WriteLine("using System;");
                    interfaceFile.WriteLine("");
                    interfaceFile.WriteLine("namespace Magnesium.Vulkan");
                    interfaceFile.WriteLine("{");
                    string tabbedField = "\t";

                    if (container.UseFlags)
                    {
                        interfaceFile.WriteLine(tabbedField + "[Flags]");
                    }
                    interfaceFile.WriteLine(tabbedField + "internal enum {0} : uint", container.name);
                    interfaceFile.WriteLine(tabbedField + "{");

                    var methodTabs = tabbedField + "\t";

                    foreach (var member in container.Members)
                    {
                        interfaceFile.WriteLine(methodTabs + member.Id + " = " + member.Value + ",");
                    }
                    interfaceFile.WriteLine(tabbedField + "}");
                    interfaceFile.WriteLine("}");
                }
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            //NativeVk();
            try
            {
                const string DLLNAME = "Vulkan-1.dll";

                var doc = XDocument.Load("TestData/vk.xml", LoadOptions.PreserveWhitespace);

                var inspector = new VkEntityInspector();
                inspector.Inspect(doc.Root);

                var parser = new VkCommandParser(inspector);

                //parser.Handles.Add("Instance", new HandleInfo { name = "Instance", type = "VK_DEFINE_HANDLE" });

                var lookup = new Dictionary <string, VkCommandInfo>();
                foreach (var child in doc.Root.Descendants("command"))
                {
                    VkCommandInfo command;
                    if (parser.Parse(child, out command))
                    {
                        lookup.Add(command.Name, command);
                    }
                }

                int noOfUnsafe            = 0;
                int totalNativeInterfaces = 0;

                var implementation = new VkInterfaceCollection();
                GenerateInterops(DLLNAME, lookup, ref noOfUnsafe, ref totalNativeInterfaces);
                GenerateImplementation(implementation, inspector);
                GenerateVkEnums(inspector);
                GenerateVkStructs(inspector);

                Console.WriteLine("totalNativeInterfaces :" + totalNativeInterfaces);
                Console.WriteLine("noOfUnsafe :" + noOfUnsafe);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }