90 lines
6.2 KiB
C#
90 lines
6.2 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RecrownedAthenaeum.Render
|
|
{
|
|
/// <summary>
|
|
/// A <see cref="SpriteBatch"/> that keeps it's settings through begin and end unless manually changed either by the <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> 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.
|
|
/// </summary>
|
|
public class ConsistentSpriteBatch : SpriteBatch
|
|
{
|
|
/// <summary>
|
|
/// How to blend the colors. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public BlendState BlendState;
|
|
|
|
/// <summary>
|
|
/// The state of sampler to use for the spritebatch. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public SamplerState SamplerState;
|
|
|
|
/// <summary>
|
|
/// The state of the depth-stencil buffer. Uses <see cref="SpriteBatch"/>'s defaultdefault if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public DepthStencilState DepthStencilState;
|
|
|
|
/// <summary>
|
|
/// The state of rasterizer to use. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public RasterizerState RasterizerState;
|
|
|
|
/// <summary>
|
|
/// An effect to apply to the batch. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public Effect Effect;
|
|
|
|
/// <summary>
|
|
/// A matrix to be applied to transform the sprites geometry. An identity matrix is used if not provided before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
|
/// </summary>
|
|
public Matrix? TransformMatrix;
|
|
|
|
/// <summary>
|
|
/// Creates a consistent sprite batch with default values.
|
|
/// </summary>
|
|
/// <param name="graphicsDevice">The graphics device to use to create a <see cref="SpriteBatch"/>.</param>
|
|
public ConsistentSpriteBatch(GraphicsDevice graphicsDevice) : base(graphicsDevice)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Begins the consistent sprite batch.
|
|
/// </summary>
|
|
/// <param name="sortMode">Defines the spritebatch's method of sorting the items in each batch. Uses <see cref="SpriteBatch"/>'s default.</param>
|
|
/// <param name="blendState">How to blend the colors. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
|
/// <param name="samplerState">The state of sampler to use for the spritebatch. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
|
/// <param name="depthStencilState">What type of rasterization to use. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
|
/// <param name="rasterizerState">What type of rasterization to use. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
|
/// <param name="effect">An effect to apply to the batch. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
|
/// <param name="transformMatrix">A matrix to be applied to transform the sprites geometry. An identity is used if not provided.</param>
|
|
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: blendState,
|
|
samplerState: samplerState,
|
|
depthStencilState: depthStencilState,
|
|
rasterizerState: rasterizerState,
|
|
effect: effect,
|
|
transformMatrix: transformMatrix);
|
|
}
|
|
}
|
|
}
|