internal EffectPass(Effect effect, EffectPass cloneSource) { Debug.Assert(effect != null, "Got a null effect!"); Debug.Assert(cloneSource != null, "Got a null cloneSource!"); _effect = effect; // Share all the immutable types. Name = cloneSource.Name; _blendState = cloneSource._blendState; _depthStencilState = cloneSource._depthStencilState; _rasterizerState = cloneSource._rasterizerState; Annotations = cloneSource.Annotations; _vertexShader = cloneSource._vertexShader; _pixelShader = cloneSource._pixelShader; }
/// <summary> /// Constructs a <see cref="SpriteBatch"/>. /// </summary> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/>, which will be used for sprite rendering.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="graphicsDevice"/> is null.</exception> public SpriteBatch(GraphicsDevice graphicsDevice) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; // Use a custom SpriteEffect so we can control the transformation matrix _spriteEffect = new Effect(graphicsDevice, EffectResource.SpriteEffect.Bytecode); _matrixTransform = _spriteEffect.Parameters["MatrixTransform"]; _spritePass = _spriteEffect.CurrentTechnique.Passes[0]; _batcher = new SpriteBatcher(graphicsDevice); _beginCalled = false; }
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)); }