Skip to content

GraphicsAPI reference

Class Renderer2D

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: The 2D batcher and the camera

The engine’s 2D batcher (IRenderer2D) over one graphics device.

C#
public sealed class Renderer2D : IRenderer2D, IDisposable

Inheritance

object ← Renderer2D

Implements

IRenderer2D, IDisposable

Constructors

Renderer2D(IGraphicsDevice)

Creates the batcher (and its 1 × 1 white texture, which untextured draws sample).

C#
public Renderer2D(IGraphicsDevice device)

Parameters

device IGraphicsDevice

Properties

Device

The device the batcher draws with.

C#
public IGraphicsDevice Device { get; }

Property Value

IGraphicsDevice

State

The state draws are recorded with; set it, or push and pop it.

C#
public RenderState State { get; set; }

Property Value

RenderState

Statistics

Counts of the current (or last) batch.

C#
public Renderer2DStatistics Statistics { get; }

Property Value

Renderer2DStatistics

Target

The target of the current batch, or null outside a batch.

C#
public RenderTarget? Target { get; }

Property Value

RenderTarget?

White

The 1 × 1 opaque white texture untextured draws sample.

C#
public Texture White { get; }

Property Value

Texture

Methods

Begin(in BatchSettings)

C#
public void Begin(in BatchSettings settings)

Parameters

settings BatchSettings

Clear(ColorF)

Submits what was recorded, then clears the whole target (viewport and scissor ignored) to a premultiplied colour.

C#
public void Clear(ColorF color)

Parameters

color ColorF

Dispose()

Releases the batcher’s buffers and white texture.

C#
public void Dispose()

Draw(Texture, RectF, in Matrix3x2, ColorF, float, SpriteFlip)

C#
public void Draw(Texture texture, RectF source, in Matrix3x2 world, ColorF tint, float depth = 0, SpriteFlip flip = SpriteFlip.None)

Parameters

texture Texture

source RectF

world Matrix3x2

tint ColorF

depth float

flip SpriteFlip

DrawGeometry(Texture?, ReadOnlySpan<Vertex2D>, ReadOnlySpan<ushort>, float)

Draws triangles (positions transformed like a draw’s local units); a null texture draws the vertex colours.

C#
public void DrawGeometry(Texture? texture, ReadOnlySpan<Vertex2D> vertices, ReadOnlySpan<ushort> indices, float depth = 0)

Parameters

texture Texture?

vertices ReadOnlySpan<Vertex2D>

indices ReadOnlySpan<ushort>

depth float

Exceptions

ArgumentOutOfRangeException

An index selects no vertex, or more than 65,535 vertices.

End()

Submits what remains and ends the batch.

C#
public void End()

Exceptions

InvalidOperationException

No batch is open, or a pushed transform or state was not popped.

Flush()

Submits what was recorded so far (for example before reading the target back).

C#
public void Flush()

PopState()

Restores the state saved by the last PushState.

C#
public void PopState()

Exceptions

InvalidOperationException

Nothing was pushed.

PopTransform()

Returns to the transform before the last PushTransform.

C#
public void PopTransform()

Exceptions

InvalidOperationException

Nothing was pushed.

PushState(in RenderState)

C#
public void PushState(in RenderState state)

Parameters

state RenderState

PushTransform(in Matrix3x2)

C#
public void PushTransform(in Matrix3x2 transform)

Parameters

transform Matrix3x2