/// <summary> /// Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects and a custom effect. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, depthStencilState.None, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). /// Passing a null effect selects the default effect shader. /// </summary> /// <param name="effect">The effect to use for this begin/end draw session (default effect if null)</param> /// <param name="parameterCollectionGroup">The parameter collection group.</param> /// <param name="sessionSortMode">Sprite drawing order used for the Begin/End session.</param> /// <param name="sessionBlendState">Blending state used for the Begin/End session</param> /// <param name="sessionSamplerState">Texture sampling used for the Begin/End session</param> /// <param name="sessionDepthStencilState">Depth and stencil state used for the Begin/End session</param> /// <param name="sessionRasterizerState">Rasterization state used for the Begin/End session</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference for the Begin/End session</param> /// <exception cref="System.InvalidOperationException">Only one SpriteBatch at a time can use SpriteSortMode.Immediate</exception> protected void Begin(Effect effect, EffectParameterCollectionGroup parameterCollectionGroup, SpriteSortMode sessionSortMode, BlendState sessionBlendState, SamplerState sessionSamplerState, DepthStencilState sessionDepthStencilState, RasterizerState sessionRasterizerState, int stencilValue) { CheckEndHasBeenCalled("begin"); SortMode = sessionSortMode; BlendState = sessionBlendState; SamplerState = sessionSamplerState; DepthStencilState = sessionDepthStencilState; RasterizerState = sessionRasterizerState; StencilReferenceValue = stencilValue; Effect = effect ?? (GraphicsDevice.ColorSpace == ColorSpace.Linear ? DefaultEffectSRgb : DefaultEffect); ParameterCollectionGroup = parameterCollectionGroup ?? defaultParameterCollectionGroup; if (ParameterCollectionGroup == defaultParameterCollectionGroup && ParameterCollectionGroup.Effect != Effect) { // If ParameterCollectionGroup is not specified (using default one), let's make sure it is updated to matches effect // It is quite inefficient if user is often switching effect without providing a matching ParameterCollectionGroup ParameterCollectionGroup = defaultParameterCollectionGroup = new EffectParameterCollectionGroup(GraphicsDevice, Effect, new[] { parameters }); } textureUpdater = null; if (Effect.HasParameter(TexturingKeys.Texture0)) { textureUpdater = Effect.GetParameterFastUpdater(TexturingKeys.Texture0); } if (Effect.HasParameter(TexturingKeys.TextureCube0)) { textureUpdater = Effect.GetParameterFastUpdater(TexturingKeys.TextureCube0); } if (Effect.HasParameter(TexturingKeys.Texture3D0)) { textureUpdater = Effect.GetParameterFastUpdater(TexturingKeys.Texture3D0); } // Immediate mode, then prepare for rendering here instead of End() if (sessionSortMode == SpriteSortMode.Immediate) { if (ResourceContext.IsInImmediateMode) { throw new InvalidOperationException("Only one SpriteBatch at a time can use SpriteSortMode.Immediate"); } PrepareForRendering(); ResourceContext.IsInImmediateMode = true; } // Sets to true isBeginCalled isBeginCalled = true; }
/// <summary> /// Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects and a custom effect. /// Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, depthStencilState.None, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). /// Passing a null effect selects the default effect shader. /// </summary> /// <param name="effect">The effect to use for this begin/end draw session (default effect if null)</param> /// <param name="sessionSortMode">Sprite drawing order used for the Begin/End session.</param> /// <param name="sessionBlendState">Blending state used for the Begin/End session</param> /// <param name="sessionSamplerState">Texture sampling used for the Begin/End session</param> /// <param name="sessionDepthStencilState">Depth and stencil state used for the Begin/End session</param> /// <param name="sessionRasterizerState">Rasterization state used for the Begin/End session</param> /// <param name="stencilValue">The value of the stencil buffer to take as reference for the Begin/End session</param> protected void Begin(Effect effect, SpriteSortMode sessionSortMode, BlendState sessionBlendState, SamplerState sessionSamplerState, DepthStencilState sessionDepthStencilState, RasterizerState sessionRasterizerState, int stencilValue) { CheckEndHasBeenCalled("begin"); SortMode = sessionSortMode; BlendState = sessionBlendState; SamplerState = sessionSamplerState; DepthStencilState = sessionDepthStencilState; RasterizerState = sessionRasterizerState; StencilReferenceValue = stencilValue; Effect = effect ?? DefaultEffect; texture0Updater = null; texture1Updater = null; if (Effect.HasParameter(TexturingKeys.Texture0)) { texture0Updater = Effect.GetParameterFastUpdater(TexturingKeys.Texture0); } if (Effect.HasParameter(TexturingKeys.Texture1)) { texture1Updater = Effect.GetParameterFastUpdater(TexturingKeys.Texture1); } // Immediate mode, then prepare for rendering here instead of End() if (sessionSortMode == SpriteSortMode.Immediate) { if (ResourceContext.IsInImmediateMode) { throw new InvalidOperationException("Only one SpriteBatch at a time can use SpriteSortMode.Immediate"); } PrepareForRendering(); ResourceContext.IsInImmediateMode = true; } // Sets to true isBeginCalled isBeginCalled = true; }