예제 #1
0
        public static EffectPass Parse(BytecodeReader reader, BytecodeReader passReader, ShaderVersion version)
        {
            var result     = new EffectPass();
            var nameOffset = passReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name = nameReader.ReadString();
            var assignmentCount = passReader.ReadUInt32();
            var annotationCount = passReader.ReadUInt32();

            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, passReader, version));
            }
            for (int i = 0; i < assignmentCount; i++)
            {
                result.Assignments.Add(EffectAssignment.Parse(reader, passReader));
            }
            return(result);
        }
예제 #2
0
        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);
        }