Exemplo n.º 1
0
        public static EffectAnnotation Parse(BytecodeReader reader, BytecodeReader annotationReader, ShaderVersion version)
        {
            var result     = new EffectAnnotation();
            var nameOffset = annotationReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

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

            result.Type = EffectType.Parse(reader, typeReader, version);
            //Note: Points to 27 and "foo" in Texture2D tex<int bla=27;string blu="foo";>;
            /// Value format and stride depends on Type
            var valueOffset        = annotationReader.ReadUInt32();
            var defaultValueReader = reader.CopyAtOffset((int)valueOffset);

            if (result.Type.EffectVariableType == EffectVariableType.Numeric)
            {
                for (int i = 0; i < result.Type.PackedSize / 4; i++)
                {
                    result.DefaultNumericValue.Add(Number.Parse(defaultValueReader));
                }
            }
            else
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.DefaultStringValue.Add(defaultValueReader.ReadString());
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        internal static EffectInterfaceVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version)
        {
            var result     = new EffectInterfaceVariable();
            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);
            //Pointer to InterfaceInitializer
            var defaultValueOffset = variableReader.ReadUInt32();
            var initializerReader  = reader.CopyAtOffset((int)defaultValueOffset);
            var instanceNameOffset = initializerReader.ReadUInt32();
            var instanceNameReader = reader.CopyAtOffset((int)instanceNameOffset);

            result.InstanceName = instanceNameReader.ReadString();
            result.Flags        = variableReader.ReadUInt32();
            var annotationCount = variableReader.ReadUInt32();

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

            return(result);
        }
Exemplo n.º 3
0
        public static EffectGroup Parse(BytecodeReader reader, BytecodeReader groupReader, ShaderVersion version)
        {
            var result          = new EffectGroup();
            var nameOffset      = groupReader.ReadUInt32();
            var techniqueCount  = groupReader.ReadUInt32();
            var annotationCount = groupReader.ReadUInt32();

            if (nameOffset != 0)
            {
                var nameReader = reader.CopyAtOffset((int)nameOffset);
                result.Name = nameReader.ReadString();
            }
            else
            {
                result.Name = "";
            }
            for (int i = 0; i < techniqueCount; i++)
            {
                result.Techniques.Add(EffectTechnique.Parse(reader, groupReader, version));
            }
            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, groupReader, version));
            }
            return(result);
        }
        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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public static EffectTechnique Parse(BytecodeReader reader, BytecodeReader techniqueReader, ShaderVersion version)
        {
            var result     = new EffectTechnique(version);
            var nameOffset = techniqueReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name = nameReader.ReadString();
            var passCount       = techniqueReader.ReadUInt32();
            var annotationCount = techniqueReader.ReadUInt32();

            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, techniqueReader, version));
            }
            for (int i = 0; i < passCount; i++)
            {
                result.Passes.Add(EffectPass.Parse(reader, techniqueReader, version));
            }
            return(result);
        }
Exemplo n.º 7
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);
        }