Example #1
0
        public static EffectChunk Parse(BytecodeReader reader, uint size)
        {
            var headerReader = reader.CopyAtCurrentPosition();
            var result       = new EffectChunk();
            var header       = result.Header = EffectHeader.Parse(headerReader);
            var bodyOffset   = header.Version.MajorVersion < 5 ?
                               0x4C : 0x60;
            var footerOffset = (int)(result.Header.FooterOffset + bodyOffset);
            var bodyReader   = reader.CopyAtOffset((int)bodyOffset);
            var footerReader = reader.CopyAtOffset(footerOffset);
            var version      = header.Version;

            for (int i = 0; i < header.ConstantBuffers; i++)
            {
                result.LocalBuffers.Add(EffectBuffer.Parse(bodyReader, footerReader, version, false));
            }
            for (int i = 0; i < header.ObjectCount; i++)
            {
                result.LocalVariables.Add(EffectObjectVariable.Parse(bodyReader, footerReader, version, false));
            }
            for (int i = 0; i < header.SharedConstantBuffers; i++)
            {
                result.SharedBuffers.Add(EffectBuffer.Parse(bodyReader, footerReader, version, true));
            }
            for (int i = 0; i < header.SharedObjectCount; i++)
            {
                result.SharedVariables.Add(EffectObjectVariable.Parse(bodyReader, footerReader, version, true));
            }
            if (header.Version.MajorVersion >= 5)
            {
                for (int i = 0; i < header.InterfaceVariableCount; i++)
                {
                    result.InterfaceVariables.Add(EffectInterfaceVariable.Parse(bodyReader, footerReader, version));
                }
                for (int i = 0; i < header.GroupCount; i++)
                {
                    result.Groups.Add(EffectGroup.Parse(bodyReader, footerReader, header.Version));
                }
            }
            else
            {
                for (int i = 0; i < header.Techniques; i++)
                {
                    result.Techniques.Add(EffectTechnique.Parse(bodyReader, footerReader, header.Version));
                }
            }
            return(result);
        }
        public static EffectObjectVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version, bool isShared = false)
        {
            var result     = new EffectObjectVariable();
            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 = variableReader.ReadUInt32();

            if (semanticOffset != 0)
            {
                var semanticReader = reader.CopyAtOffset((int)semanticOffset);
                result.Semantic = semanticReader.ReadString();
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = variableReader.ReadUInt32();
            if (isShared)
            {
                return(result);
            }
            // Initializer data
            if (result.Type.ObjectType == EffectObjectType.String)
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    var stringValueOffset = variableReader.ReadUInt32();
                    var stringValueReader = reader.CopyAtOffset((int)stringValueOffset);
                    result.Strings.Add(stringValueReader.ReadString());
                }
            }
            if (IfHasAssignments(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    var assignmentCount = variableReader.ReadUInt32();
                    var assignments     = new List <EffectAssignment>();
                    result.Assignments.Add(assignments);
                    for (int j = 0; j < assignmentCount; j++)
                    {
                        assignments.Add(EffectAssignment.Parse(reader, variableReader));
                    }
                }
            }
            if (result.Type.ObjectType == EffectObjectType.GeometryShaderWithStream)
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.GSSOInitializers.Add(EffectGSSOInitializer.Parse(reader, variableReader));
                }
            }
            else if (IsShader5(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.ShaderData5.Add(EffectShaderData5.Parse(reader, variableReader));
                }
            }
            else if (IsShader(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.ShaderData.Add(EffectShaderData.Parse(reader, variableReader));
                }
            }
            var annotationCount = variableReader.ReadUInt32();

            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version));
            }
            return(result);
        }