Пример #1
0
        internal static EffectNumericVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version, bool isShared)
        {
            var result     = new EffectNumericVariable();
            var nameOffset = variableReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name = nameReader.ReadString();
            var typeOffset = variableReader.ReadUInt32();
            var typeReader = reader.CopyAtOffset((int)typeOffset);

            result.Type = EffectType.Parse(reader, typeReader, version);
            var semanticOffset = result.SemanticOffset = variableReader.ReadUInt32();

            if (semanticOffset != 0)
            {
                var semanticReader = reader.CopyAtOffset((int)semanticOffset);
                result.Semantic = semanticReader.ReadString();
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = variableReader.ReadUInt32();
            var defaultValueOffset = variableReader.ReadUInt32();

            List <Number> defaultValue = null;
            var           size         = result.Type.PackedSize;

            if (defaultValueOffset != 0)
            {
                defaultValue = new List <Number>();
                var defaultValueReader = reader.CopyAtOffset((int)defaultValueOffset);
                if (size % 4 != 0)
                {
                    throw new ParseException("Can only deal with 4-byte default values at the moment.");
                }
                for (int i = 0; i < size; i += 4)
                {
                    defaultValue.Add(new Number(defaultValueReader.ReadBytes(4)));
                }
            }
            result.DefaultValue = defaultValue;

            if (!isShared)
            {
                result.ExplicitBindPoint = variableReader.ReadUInt32();
            }
            var annotationCount = variableReader.ReadUInt32();

            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version));
            }
            return(result);
        }
Пример #2
0
        public static EffectBuffer Parse(BytecodeReader reader, BytecodeReader bufferReader, ShaderVersion version, bool isShared)
        {
            var result     = new EffectBuffer();
            var nameOffset = result.NameOffset = bufferReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name           = nameReader.ReadString();
            result.BufferSize     = bufferReader.ReadUInt32();
            result.BufferType     = (ConstantBufferType)bufferReader.ReadUInt32();
            result.VariableCount  = bufferReader.ReadUInt32();
            result.RegisterNumber = bufferReader.ReadUInt32();
            if (!isShared)
            {
                var unknown0 = bufferReader.ReadUInt32();
                //TODO: Unknown0
                //Debug.Assert(result.Unknown0 == 0, $"EffectBuffer.Unknown0: {result.Unknown0}");
            }
            for (int i = 0; i < result.VariableCount; i++)
            {
                result.Variables.Add(EffectNumericVariable.Parse(reader, bufferReader, version, isShared));
            }
            return(result);
        }