Esempio n. 1
0
        public static EffectMember Parse(BytecodeReader reader, BytecodeReader memberReader, ShaderVersion version)
        {
            var result     = new EffectMember();
            var nameOffset = memberReader.ReadUInt32();

            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name = nameReader.ReadString();

            var semanticNameOffset = memberReader.ReadUInt32();

            if (semanticNameOffset != 0)
            {
                var semanticNameReader = reader.CopyAtOffset((int)semanticNameOffset);
                result.Semantic = semanticNameReader.ReadString();
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = memberReader.ReadUInt32();
            var typeOffset = memberReader.ReadUInt32();
            var typeReader = reader.CopyAtOffset((int)typeOffset);

            result.Type = EffectType.Parse(reader, typeReader, version);
            return(result);
        }
Esempio n. 2
0
        public static EffectType Parse(BytecodeReader reader, BytecodeReader typeReader, ShaderVersion version)
        {
            var result         = new EffectType();
            var typeNameOffset = typeReader.ReadUInt32();
            var nameReader     = reader.CopyAtOffset((int)typeNameOffset);

            result.TypeName = nameReader.ReadString();
            //I suspect this is object type, 1 for numeric, 2 for object, 3 for struct
            result.EffectVariableType = (EffectVariableType)typeReader.ReadUInt32();
            result.ElementCount       = typeReader.ReadUInt32();
            result.UnpackedSize       = typeReader.ReadUInt32();
            result.Stride             = typeReader.ReadUInt32();
            result.PackedSize         = typeReader.ReadUInt32();
            if (result.EffectVariableType == EffectVariableType.Numeric)
            {
                var type        = result.PackedType = typeReader.ReadUInt32();
                var numericType = result.NumericType = EffectNumericType.Parse(type);
                switch (numericType.NumericLayout)
                {
                case EffectNumericLayout.Scalar:
                    result.VariableClass = ShaderVariableClass.Scalar;
                    break;

                case EffectNumericLayout.Vector:
                    result.VariableClass = ShaderVariableClass.Vector;
                    break;

                case EffectNumericLayout.Matrix:
                    result.VariableClass = type.DecodeValue(14, 14) == 1 ?
                                           ShaderVariableClass.MatrixColumns :
                                           ShaderVariableClass.MatrixRows;
                    break;
                }
                switch (numericType.ScalarType)
                {
                case EffectScalarType.Float:
                    result.ObjectType = EffectObjectType.Float;
                    break;

                case EffectScalarType.Int:
                    result.ObjectType = EffectObjectType.Int;
                    break;

                case EffectScalarType.UInt:
                    result.ObjectType = EffectObjectType.UInt;
                    break;

                case EffectScalarType.Bool:
                    result.ObjectType = EffectObjectType.Bool;
                    break;
                }
            }
            else if (result.EffectVariableType == EffectVariableType.Object)
            {
                var type = result.PackedType = typeReader.ReadUInt32();
                result.VariableClass = ShaderVariableClass.Object;
                result.ObjectType    = (EffectObjectType)type;
            }
            else if (result.EffectVariableType == EffectVariableType.Struct)
            {
                result.ObjectType    = EffectObjectType.Void;
                result.VariableClass = ShaderVariableClass.Struct;
                result.MemberCount   = typeReader.ReadUInt32();
                for (int i = 0; i < result.MemberCount; i++)
                {
                    result.Members.Add(EffectMember.Parse(reader, typeReader, version));
                }
                if (version.MajorVersion == 5)
                {
                    result.BaseClassType  = typeReader.ReadUInt32();
                    result.InterfaceCount = typeReader.ReadUInt32();
                    for (int i = 0; i < result.InterfaceCount; i++)
                    {
                        var interfaceOffset = typeReader.ReadUInt32();
                        var interfaceReader = reader.CopyAtOffset((int)interfaceOffset);
                        result.InterfaceTypes.Add(EffectType.Parse(reader, interfaceReader, version));
                    }
                }
            }
            else if (result.EffectVariableType == EffectVariableType.Interface)
            {
                result.VariableClass = ShaderVariableClass.InterfaceClass;
                result.ObjectType    = EffectObjectType.Interface;
            }
            return(result);
        }