Exemple #1
0
        public static ShaderRequiresFlags GlobalFlagsToRequireFlags(GlobalFlags flags)
        {
            ShaderRequiresFlags result = ShaderRequiresFlags.None;

            if (flags.HasFlag(GlobalFlags.ForceEarlyDepthStencilTest))
            {
                result |= ShaderRequiresFlags.EarlyDepthStencil;
            }
            return(result);
        }
Exemple #2
0
        public void WriteTo(BinaryStream stream, int baseOffset = 0)
        {
            var value = Value;

            switch (Type)
            {
            case DescriptorType.None:
                stream.WriteByte(value);
                break;

            case DescriptorType.BigValue:
            case DescriptorType.Reference:
            {
                var code = (byte)~Type;

                if (ReferenceType == ReferenceType.Offset)
                {
                    var ptr    = (int)stream.Position + baseOffset;
                    var offset = (ptr - value);

                    if (offset < 0)
                    {
                        throw new InvalidOperationException("Cannot write a forward-offset!");
                    }

                    value = offset;
                }

                if (GlobalFlags.HasFlag(DescriptorFlags.Use24Bit))
                {
                    if ((value & 0xFFFFFF) != value)
                    {
                        throw new InvalidOperationException($"Descriptor value '{value}' too large, cannot fit into 24-bits!");
                    }

                    value <<= 8;
                    value  |= code;

                    stream.Write(value);
                }
                else
                {
                    stream.WriteByte(code);
                    stream.Write(value);
                }
            } break;
            }
        }
        public static string GetDescription(this GlobalFlags value)
        {
            string result = string.Empty;

            foreach (Enum enumValue in Enum.GetValues(typeof(GlobalFlags)))
            {
                if ((int)value > 0 && value.HasFlag(enumValue))
                {
                    if (!string.IsNullOrEmpty(result))
                    {
                        result += " | ";
                    }
                    result += enumValue.GetDescription();
                }
            }
            return(result);
        }
Exemple #4
0
        public static DescriptorTag CreateReference(int value, ReferenceType refType)
        {
            if (refType == ReferenceType.None)
            {
                throw new InvalidOperationException("ID:10T error -- why the f**k are you creating a reference with no type?!");
            }

            if (GlobalFlags.HasFlag(DescriptorFlags.Use24Bit))
            {
                if ((value & 0xFFFFFF) != value)
                {
                    throw new InvalidOperationException($"Descriptor offset '{value}' too large, cannot fit into 24-bits!");
                }
            }

            return(new DescriptorTag(value, DescriptorType.Reference, refType));
        }
Exemple #5
0
        public static DescriptorTag Create(int value)
        {
            var type = DescriptorType.None;

            if (value >= 254u)
            {
                type = DescriptorType.BigValue;
            }

            if (GlobalFlags.HasFlag(DescriptorFlags.Use24Bit))
            {
                if ((value & 0xFFFFFF) != value)
                {
                    throw new InvalidOperationException($"Descriptor value '{value}' too large, cannot fit into 24-bits!");
                }
            }

            return(new DescriptorTag(value, type, ReferenceType.None));
        }
Exemple #6
0
        public static DescriptorTag Read(BinaryStream stream, ReferenceType refType = ReferenceType.None)
        {
            var ptr = (int)stream.Position;

            var value = stream.ReadByte();
            var type  = GetDescriptorType(value);

            if ((type == DescriptorType.Reference) && (refType == ReferenceType.None))
            {
                throw new InvalidOperationException("ID:10T error while reading a descriptor -- consumed a reference with no type defined!");
            }

            var isOffset = (type == DescriptorType.Reference) &&
                           (refType == ReferenceType.Offset);

            if (type != DescriptorType.None)
            {
                if (GlobalFlags.HasFlag(DescriptorFlags.Use24Bit))
                {
                    // move back
                    stream.Position -= 1;

                    // read in value without control code
                    value = (int)(stream.ReadUInt32() >> 8);
                }
                else
                {
                    value = stream.ReadInt32();
                }

                if (isOffset)
                {
                    // make offset absolute
                    value = (ptr - value);
                }
            }

            return(new DescriptorTag(value, type, refType));
        }