Microsoft.Xna.Framework.Graphics.Effect.ReadPasses C# (CSharp) Method

ReadPasses() private static method

private static ReadPasses ( BinaryReader reader, Effect effect, Shader shaders ) : EffectPassCollection
reader BinaryReader
effect Effect
shaders Shader
return EffectPassCollection
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, Shader[] shaders)
        {
            var count = (int)reader.ReadByte();
            var passes = new EffectPass[count];

            for (var i = 0; i < count; i++)
            {
                var name = reader.ReadString();
                var annotations = ReadAnnotations(reader);

                // Get the vertex shader.
                Shader vertexShader = null;
                var shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                    vertexShader = shaders[shaderIndex];

                // Get the pixel shader.
                Shader pixelShader = null;
                shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                    pixelShader = shaders[shaderIndex];

				BlendState blend = null;
				DepthStencilState depth = null;
				RasterizerState raster = null;
				if (reader.ReadBoolean())
				{
					blend = new BlendState
					{
						AlphaBlendFunction = (BlendFunction)reader.ReadByte(),
						AlphaDestinationBlend = (Blend)reader.ReadByte(),
						AlphaSourceBlend = (Blend)reader.ReadByte(),
						BlendFactor = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), 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())
				{
					depth = 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())
				{
					raster = new RasterizerState
					{
						CullMode = (CullMode)reader.ReadByte(),
						DepthBias = reader.ReadSingle(),
						FillMode = (FillMode)reader.ReadByte(),
						MultiSampleAntiAlias = reader.ReadBoolean(),
						ScissorTestEnable = reader.ReadBoolean(),
						SlopeScaleDepthBias = reader.ReadSingle(),
					};
				}

                passes[i] = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
			}

            return new EffectPassCollection(passes);
		}

Usage Example

Esempio n. 1
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];
        }