using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace RecrownedAthenaeum.Render
{
///
/// A that keeps it's settings through begin and end unless manually changed either by the or through changing the fields. Note that changing the fields while the batch has begun will not take effect until the next time the batch is started.
/// Casting this as a will not persist the configuration and will call the normal .
///
public class ConsistentSpriteBatch : SpriteBatch
{
///
/// How to blend the colors. Uses 's default if not set before or during call.
/// Changes will only take effect on call.
///
public BlendState blendState;
///
/// The state of sampler to use for the spritebatch. Uses 's default if not set before or during call.
/// Changes will only take effect on call.
///
public SamplerState samplerState;
///
/// The state of the depth-stencil buffer. Uses 's defaultdefault if not set before or during call.
/// Changes will only take effect on call.
///
public DepthStencilState depthStencilState;
///
/// The state of rasterizer to use. Uses 's default if not set before or during call.
/// Changes will only take effect on call.
///
public RasterizerState rasterizerState;
///
/// An effect to apply to the batch. Uses 's default if not set before or during call.
/// Changes will only take effect on call.
///
public Effect effect;
///
/// A matrix to be applied to transform the sprites geometry. An identity matrix is used if not provided before or during call.
/// Changes will only take effect on call.
///
public Matrix? transformMatrix;
///
/// Creates a consistent sprite batch with default values.
///
/// The graphics device to use to create a .
public ConsistentSpriteBatch(GraphicsDevice graphicsDevice) : base(graphicsDevice)
{
}
///
/// Begins the consistent sprite batch. The configuration passed to this function is saved for later begin calls.
///
/// Defines the spritebatch's method of sorting the items in each batch. Uses 's default.
/// How to blend the colors. Uses 's default if not set and field is also not set.
/// The state of sampler to use for the spritebatch. Uses 's default if not set and field is also not set.
/// What type of rasterization to use. Uses 's default if not set and field is also not set.
/// What type of rasterization to use. Uses 's default if not set and field is also not set.
/// An effect to apply to the batch. Uses 's default if not set and field is also not set.
/// A matrix to be applied to transform the sprites geometry. Uses 's default if not set and field is also not set.
public new void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null)
{
if (blendState != null) this.blendState = blendState;
if (samplerState != null) this.samplerState = samplerState;
if (depthStencilState != null) this.depthStencilState = depthStencilState;
if (rasterizerState != null) this.rasterizerState = rasterizerState;
if (effect != null) this.effect = effect;
if (transformMatrix != null) this.transformMatrix = transformMatrix;
base.Begin(
sortMode: sortMode,
blendState: this.blendState,
samplerState: this.samplerState,
depthStencilState: this.depthStencilState,
rasterizerState: this.rasterizerState,
effect: this.effect,
transformMatrix: this.transformMatrix);
}
///
/// Begins the consistent sprite batch without saving the configuration. Useful for one time changes to one portion of the configuration.
///
/// Defines the spritebatch's method of sorting the items in each batch. Uses 's default.
/// How to blend the colors. Uses 's default if not set and field is also not set.
/// The state of sampler to use for the spritebatch. Uses 's default if not set and field is also not set.
/// What type of rasterization to use. Uses 's default if not set and field is also not set.
/// What type of rasterization to use. Uses 's default if not set and field is also not set.
/// An effect to apply to the batch. Uses 's default if not set and field is also not set.
/// A matrix to be applied to transform the sprites geometry. Uses 's default if not set and field is also not set.
public void BeginWithoutSaving(SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null)
{
base.Begin(
sortMode: sortMode,
blendState: blendState ?? this.blendState,
samplerState: samplerState ?? this.samplerState,
depthStencilState: depthStencilState ?? this.depthStencilState,
rasterizerState: rasterizerState ?? this.rasterizerState,
effect: effect ?? this.effect,
transformMatrix: transformMatrix ?? this.transformMatrix);
}
}
}