Skip to content

GraphicsAPI reference

Class DeviceRenderer

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.dll
Guide: Graphics

The drawing API (IRenderer) as a façade over the 2D batcher (Renderer2D) on a graphics device: every call is recorded into the batcher, and the frame reaches the device in as few draw calls as the draws’ textures and states allow. Straight-alpha colours are premultiplied on the way in, so the blend modes keep their written equations (see SetBlendMode).

C#
public sealed class DeviceRenderer : IRenderer

Inheritance

object ← DeviceRenderer

Implements

IRenderer

Constructors

DeviceRenderer(Renderer2D, DeviceGraphics, RenderTarget)

A renderer drawing into target (the canvas) with the textures of graphics.

C#
public DeviceRenderer(Renderer2D batcher, DeviceGraphics graphics, RenderTarget target)

Parameters

batcher Renderer2D

graphics DeviceGraphics

target RenderTarget

DeviceRenderer(Renderer2D, DeviceGraphics, RenderTarget, float)

A renderer whose units are scale target pixels each (the UI view: UI units at the window’s resolution). Width and Height are the target’s size in those units; the clip is in them too.

C#
public DeviceRenderer(Renderer2D batcher, DeviceGraphics graphics, RenderTarget target, float scale)

Parameters

batcher Renderer2D

graphics DeviceGraphics

target RenderTarget

scale float

Exceptions

ArgumentOutOfRangeException

scale is not positive.

Properties

Height

Height of the virtual canvas in pixels.

C#
public int Height { get; }

Property Value

int

Statistics

The batcher’s counts for the last frame (sprites, draw calls, flushes): exact and the same on every device.

C#
public Renderer2DStatistics Statistics { get; }

Property Value

Renderer2DStatistics

Target

The render target this renderer draws into (the canvas, or the UI view’s target). Valid only during the frame, between Begin and End: the canvas can be replaced between frames (an expanding presentation resizes it), so keep the renderer, not the target. Work submitted to the device into this target between two Flush calls (a 3D pass) lands between the 2D drawn before and after it.

C#
public RenderTarget Target { get; }

Property Value

RenderTarget

Width

Width of the virtual canvas in pixels.

C#
public int Width { get; }

Property Value

int

Methods

Begin()

Starts a frame: the canvas keeps its pixels, blending is Alpha, no clip, no camera.

C#
public void Begin()

Clear(Color)

Replaces every pixel of the canvas with color, alpha included, whatever the clip (SetClip) and blend mode, and replaces what was drawn before it in the frame. The clip still applies to the draws after it. The game clears to its settings’ Background colour before the scenes draw.

C#
public void Clear(Color color)

Parameters

color Color

Draw(Texture, RectF, Vector2, Color, in DrawOptions)

C#
public void Draw(Texture texture, RectF source, Vector2 position, Color tint, in DrawOptions options = default)

Parameters

texture Texture

source RectF

position Vector2

tint Color

options DrawOptions

DrawLine(Vector2, Vector2, float, Color)

Draws a straight line thickness pixels wide. A zero-length line draws nothing.

C#
public void DrawLine(Vector2 from, Vector2 to, float thickness, Color color)

Parameters

from Vector2

to Vector2

thickness float

color Color

DrawStretched(Texture, RectF, RectF, Color)

Draws the source part of texture scaled to fill destination.

C#
public void DrawStretched(Texture texture, RectF source, RectF destination, Color tint)

Parameters

texture Texture

source RectF

destination RectF

tint Color

Exceptions

ObjectDisposedException

texture was disposed; nothing is drawn.

ArgumentException

Another graphics device created texture; nothing is drawn.

End()

Ends the frame and submits it.

C#
public void End()

Exceptions

InvalidOperationException

A camera pushed this frame was not popped.

FillCircle(Vector2, float, Color)

Fills a circle; radius is in pixels.

C#
public void FillCircle(Vector2 center, float radius, Color color)

Parameters

center Vector2

radius float

color Color

FillRect(RectF, Color)

Fills a rectangle: the pixels whose centre lies inside it (see the rules of IRenderer). A fully transparent colour draws nothing.

C#
public void FillRect(RectF rect, Color color)

Parameters

rect RectF

color Color

FillTriangle(Vector2, Vector2, Vector2, Color)

Fills a triangle.

C#
public void FillTriangle(Vector2 a, Vector2 b, Vector2 c, Color color)

Parameters

a Vector2

b Vector2

c Vector2

color Color

Flush()

Submits to the device everything this renderer recorded since the frame began or since the last flush (the frame’s Clear included, so a clear always lands before the first flush’s other work) and keeps the frame open: state, camera and clip stay as they are, and draws recorded after the flush are submitted after anything submitted to the device in between. Use it to put device work (a 3D pass into Target) between 2D draws. Outside a frame it does nothing.

C#
public void Flush()

PopCamera()

Returns to the coordinates in use before the last PushCamera.

C#
public void PopCamera()

Exceptions

InvalidOperationException

No camera was pushed.

PushCamera(Camera2D)

Draws in the world coordinates of camera until PopCamera: its RenderOffset replaces the current offset (cameras do not combine). Every push needs a pop in the same frame.

C#
public void PushCamera(Camera2D camera)

Parameters

camera Camera2D

SetBlendMode(BlendMode)

Sets how later draws combine with the canvas. Every frame starts with Alpha. With source colour s (after the tint), its alpha a and canvas colour d: Alpha writes s·a + d·(1 − a), Additive s·a + d, Multiply s·a·d + d·(1 − a) (the colour multiplies the canvas in proportion to its opacity), each channel clamped to 0..1.

C#
public void SetBlendMode(BlendMode mode)

Parameters

mode BlendMode

SetClip(RectF?)

Restricts drawing to a screen-space rectangle (the camera does not move it); pass null to remove. X, Y, Width and Height are truncated to whole pixels. Clear ignores the clip.

C#
public void SetClip(RectF? screenRect)

Parameters

screenRect RectF?