示例#1
0
        static VkEnum GenerateEmptyBitmask(string name)
        {
            var vkEnum = new VkEnum
            {
                Name      = GetEnumName(name),
                IsBitmask = true,
            };

            var vkEnumValue = new VkEnumValue
            {
                Name  = "VK_NONE",
                Value = "0",
            };

            vkEnum.Values = new[] { vkEnumValue };

            return(vkEnum);
        }
示例#2
0
        void MergeExtensionConstants(VkEnum apiConstants, VkExtension[] extensions)
        {
            var constantList = apiConstants.Values.ToList();

            foreach (var ext in extensions.Where(x => x.Supported != "disabled"))
            {
                var constants = ext.Requirement.Enums.Where(x => x.IsConstant);
                foreach (var newConstantValue in constants)
                {
                    constantList.Add(new VkEnumValue {
                        Name     = newConstantValue.Name,
                        SpecName = newConstantValue.Name,
                        Value    = newConstantValue.Value.Replace("\"", string.Empty),
                    });
                }
            }
            apiConstants.Values = constantList.ToArray();
        }
示例#3
0
        VkEnum ReadEnum(XElement xenums)
        {
            if (xenums.Name != "enums")
            {
                throw new ArgumentException("Not an enum colletion", nameof(xenums));
            }

            var vkEnum = new VkEnum();

            var xattributes = xenums.Attributes();

            if (xattributes.Any())
            {
                foreach (var xattrib in xattributes)
                {
                    switch (xattrib.Name.ToString())
                    {
                    case "name":
                        vkEnum.Name = GetEnumName(xattrib.Value);
                        break;

                    case "type":
                        vkEnum.IsBitmask = xattrib.Value == "bitmask";
                        break;

                    case "comment":
                        vkEnum.Comment = xattrib.Value;
                        break;

                    default: throw new NotImplementedException(xattrib.Name.ToString());
                    }
                }
            }

            if (string.IsNullOrEmpty(vkEnum.Name))
            {
                throw new InvalidOperationException("Enum collection does not have proper `<name>` element");
            }

            // note: there are also `unused` blocks that are not currently used...
            vkEnum.Values = xenums.Elements("enum").Select(ReadEnumValue).ToArray();

            return(vkEnum);
        }
示例#4
0
        void RewriteEnumDefinition(VkEnum vkEnum)
        {
            if (vkEnum.Name.StartsWith("Vk"))
            {
                vkEnum.Name = vkEnum.Name.Remove(0, 2); // trim `Vk`
            }
            var isFlags = vkEnum.Name.EndsWith("Flags");

            var trimKHR = false;
            var trimEXT = false;

            var enumPrefix = vkEnum.Name;

            if (enumPrefix.EndsWith("KHR"))
            {
                enumPrefix = enumPrefix.Remove(enumPrefix.Length - 3, 3); // trim `KHR`
                trimKHR    = true;
            }

            if (enumPrefix.EndsWith("EXT"))
            {
                enumPrefix = enumPrefix.Remove(enumPrefix.Length - 3, 3); // trim `EXT`
                trimEXT    = true;
            }

            if (enumPrefix.EndsWith("Flags"))
            {
                enumPrefix = enumPrefix.Substring(0, enumPrefix.Length - 5);
            }

            enumPrefix = ToUppercaseEnumName(enumPrefix) + "_";

            var firstValue = vkEnum.Values.First();

            foreach (var vkEnumValue in vkEnum.Values)
            {
                var name = vkEnumValue.Name;
                if (name.StartsWith("VK_"))
                {
                    name = name.Substring(3, name.Length - 3);
                }

                if (!string.IsNullOrEmpty(enumPrefix) && name.StartsWith(enumPrefix))
                {
                    name = name.Substring(enumPrefix.Length, name.Length - enumPrefix.Length);
                }

                // bleh, this is janky

                if (name.EndsWith("_KHR") && trimKHR)
                {
                    name = name.Remove(name.Length - 4, 4); // trim `_KHR`
                }
                if (name.EndsWith("_EXT") && trimEXT)
                {
                    name = name.Remove(name.Length - 4, 4); // trim `_KHR`
                }
                if (name.EndsWith("_BIT"))
                {
                    name = name.Substring(0, name.Length - 4);
                }

                name = ToCamelCaseEnumName(name);

                if (name.EndsWith("Khr"))
                {
                    name = name.Remove(name.Length - 3, 3) + "KHR";
                }

                if (name.EndsWith("Ext"))
                {
                    name = name.Remove(name.Length - 3, 3) + "EXT";
                }

                if (name.EndsWith("Amd"))
                {
                    name = name.Remove(name.Length - 3, 3) + "AMD";
                }

                vkEnumValue.Name = name;
            }

            // After the we've renamed all the enum values, check if there are any that
            // begin with a number (invalid in C#) and fix it.
            if (vkEnum.Values.Any(x => Regex.IsMatch(x.Name, "^[0-9]")))
            {
                foreach (var vkEnumValue in vkEnum.Values)
                {
                    var name = vkEnumValue.Name;
                    name             = vkEnum.Name + name;
                    vkEnumValue.Name = name;
                }
            }
        }