ReadAnnotations() private static method

private static ReadAnnotations ( BinaryReader reader ) : EffectAnnotationCollection
reader System.IO.BinaryReader
return EffectAnnotationCollection
Ejemplo n.º 1
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, (BlendState)null, (DepthStencilState)null, (RasterizerState)null, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }
Ejemplo n.º 2
0
        private EffectParameterCollection ReadParameters(BinaryReader reader)
        {
            EffectParameterCollection parameterCollection = new EffectParameterCollection();
            int num = (int)reader.ReadByte();

            if (num == 0)
            {
                return(parameterCollection);
            }
            for (int index1 = 0; index1 < num; ++index1)
            {
                EffectParameterClass class_ = (EffectParameterClass)reader.ReadByte();
                EffectParameterType  type   = (EffectParameterType)reader.ReadByte();
                string name     = reader.ReadString();
                string semantic = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int rowCount      = (int)reader.ReadByte();
                int columnCount   = (int)reader.ReadByte();
                int registerCount = this.version >= 3 ? (int)reader.ReadByte() : rowCount;
                EffectParameterCollection elements      = this.ReadParameters(reader);
                EffectParameterCollection structMembers = this.ReadParameters(reader);
                object data = (object)null;
                if (elements.Count == 0 && structMembers.Count == 0)
                {
                    switch (type)
                    {
                    case EffectParameterType.Bool:
                    case EffectParameterType.Int32:
                        int[] numArray1 = new int[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray1.Length; ++index2)
                        {
                            numArray1[index2] = reader.ReadInt32();
                        }
                        data = (object)numArray1;
                        break;

                    case EffectParameterType.Single:
                        float[] numArray2 = new float[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray2.Length; ++index2)
                        {
                            numArray2[index2] = reader.ReadSingle();
                        }
                        data = (object)numArray2;
                        break;

                    case EffectParameterType.String:
                        throw new NotImplementedException();
                    }
                }
                EffectParameter effectParameter = new EffectParameter(class_, type, name, rowCount, columnCount, registerCount, semantic, annotations, elements, structMembers, data);
                parameterCollection.Add(effectParameter);
            }
            return(parameterCollection);
        }
Ejemplo n.º 3
0
        private void ReadEffect(BinaryReader reader)
        {
            if (new string(reader.ReadChars("MGFX".Length)) != "MGFX")
            {
                throw new Exception("The MGFX file is corrupt!");
            }
            this.version = (int)reader.ReadByte();
            if (this.version < 4)
            {
                throw new Exception("Unsupported MGFX file version!");
            }
            if ((int)reader.ReadByte() != 0)
            {
                throw new Exception("The MGFX effect is the wrong profile for this platform!");
            }
            int length = (int)reader.ReadByte();

            this.ConstantBuffers = new ConstantBuffer[length];
            for (int index1 = 0; index1 < length; ++index1)
            {
                string name             = reader.ReadString();
                int    sizeInBytes      = (int)reader.ReadInt16();
                int[]  parameterIndexes = new int[(int)reader.ReadByte()];
                int[]  parameterOffsets = new int[parameterIndexes.Length];
                for (int index2 = 0; index2 < parameterIndexes.Length; ++index2)
                {
                    parameterIndexes[index2] = (int)reader.ReadByte();
                    parameterOffsets[index2] = (int)reader.ReadUInt16();
                }
                ConstantBuffer constantBuffer = new ConstantBuffer(this.GraphicsDevice, sizeInBytes, parameterIndexes, parameterOffsets, name);
                this.ConstantBuffers[index1] = constantBuffer;
            }
            this._shaderList = new List <Shader>();
            int num1 = (int)reader.ReadByte();

            for (int index = 0; index < num1; ++index)
            {
                this._shaderList.Add(new Shader(this.GraphicsDevice, reader));
            }
            this.Parameters = this.ReadParameters(reader);
            this.Techniques = new EffectTechniqueCollection();
            int num2 = (int)reader.ReadByte();

            for (int index = 0; index < num2; ++index)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                EffectPassCollection       passes      = Effect.ReadPasses(reader, this, this._shaderList);
                this.Techniques.Add(new EffectTechnique(this, name, passes, annotations));
            }
            this.CurrentTechnique = this.Techniques[0];
        }
Ejemplo n.º 4
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                BlendState        blendState        = (BlendState)null;
                DepthStencilState depthStencilState = (DepthStencilState)null;
                RasterizerState   rasterizerState   = (RasterizerState)null;
                if (reader.ReadBoolean())
                {
                    blendState = new BlendState()
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    depthStencilState = new DepthStencilState()
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    rasterizerState = new RasterizerState()
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle()
                    }
                }
                ;
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }