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.
public interface IRenderer2DRemarks
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.
RenderState State { get; set; }Property Value
Statistics
Counts of the current (or last) batch.
Renderer2DStatistics Statistics { get; }Property Value
Target
The target of the current batch, or null outside a batch.
RenderTarget? Target { get; }Property Value
Methods
Begin(in BatchSettings)
Starts a batch.
void Begin(in BatchSettings settings)Parameters
settings BatchSettings
Exceptions
A batch is already open.
Clear(ColorF)
Submits what was recorded, then clears the whole target (viewport and scissor ignored) to a premultiplied colour.
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.
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.
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
An index selects no vertex, or more than 65,535 vertices.
End()
Submits what remains and ends the batch.
void End()Exceptions
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).
void Flush()PopState()
Restores the state saved by the last PushState.
void PopState()Exceptions
Nothing was pushed.
PopTransform()
Returns to the transform before the last PushTransform.
void PopTransform()Exceptions
Nothing was pushed.
PushState(in RenderState)
Saves State and sets state until PopState.
void PushState(in RenderState state)Parameters
state RenderState
PushTransform(in Matrix3x2)
Multiplies later draws’ transforms by transform (before the view) until PopTransform.
void PushTransform(in Matrix3x2 transform)Parameters
transform Matrix3x2