Skip to content

GraphicsAPI reference

Interface IRenderer2D

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

The 2D renderer over the graphics device, implemented once in core: it writes vertices and indices into device buffers and draws them with the built-in Textured pipeline only, so it runs unchanged on every tier. Colours (tints, vertex colours) are premultiplied, and the default blend state is premultiplied alpha.

C#
public interface IRenderer2D

Remarks

Rules: a draw’s vertices are transformed on the CPU by its world matrix, then the pushed transforms, then the batch’s view, into target pixels; consecutive draws (after sorting) with the same texture and RenderState share one indexed draw; a Clear or Flush submits what was recorded so far; nothing reaches the device before End, Clear or Flush.

Properties

State

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

C#
RenderState State { get; set; }

Property Value

RenderState

Statistics

Counts of the current (or last) batch.

C#
Renderer2DStatistics Statistics { get; }

Property Value

Renderer2DStatistics

Target

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

C#
RenderTarget? Target { get; }

Property Value

RenderTarget?

Methods

Begin(in BatchSettings)

Starts a batch.

C#
void Begin(in BatchSettings settings)

Parameters

settings BatchSettings

Exceptions

InvalidOperationException

A batch is already open.

Clear(ColorF)

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

C#
void Clear(ColorF color)

Parameters

color ColorF

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

Draws the source texels of texture as a quad of source.Width × source.Height local units placed by world, multiplied by the premultiplied tint.

C#
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#
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#
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#
void Flush()

PopState()

Restores the state saved by the last PushState.

C#
void PopState()

Exceptions

InvalidOperationException

Nothing was pushed.

PopTransform()

Returns to the transform before the last PushTransform.

C#
void PopTransform()

Exceptions

InvalidOperationException

Nothing was pushed.

PushState(in RenderState)

Saves State and sets state until PopState.

C#
void PushState(in RenderState state)

Parameters

state RenderState

PushTransform(in Matrix3x2)

Multiplies later draws’ transforms by transform (before the view) until PopTransform.

C#
void PushTransform(in Matrix3x2 transform)

Parameters

transform Matrix3x2