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).
public sealed class DeviceRenderer : IRendererInheritance
Implements
Constructors
DeviceRenderer(Renderer2D, DeviceGraphics, RenderTarget)
A renderer drawing into target (the canvas) with the textures of graphics.
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.
public DeviceRenderer(Renderer2D batcher, DeviceGraphics graphics, RenderTarget target, float scale)Parameters
batcher Renderer2D
graphics DeviceGraphics
target RenderTarget
scale float
Exceptions
scale is not positive.
Properties
Height
Height of the virtual canvas in pixels.
public int Height { get; }Property Value
Statistics
The batcher’s counts for the last frame (sprites, draw calls, flushes): exact and the same on every device.
public Renderer2DStatistics Statistics { get; }Property Value
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.
public RenderTarget Target { get; }Property Value
Width
Width of the virtual canvas in pixels.
public int Width { get; }Property Value
Methods
Begin()
Starts a frame: the canvas keeps its pixels, blending is Alpha, no clip, no camera.
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.
public void Clear(Color color)Parameters
color Color
Draw(Texture, RectF, Vector2, Color, in DrawOptions)
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.
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.
public void DrawStretched(Texture texture, RectF source, RectF destination, Color tint)Parameters
texture Texture
source RectF
destination RectF
tint Color
Exceptions
texture was disposed; nothing is drawn.
Another graphics device created texture; nothing is drawn.
End()
Ends the frame and submits it.
public void End()Exceptions
A camera pushed this frame was not popped.
FillCircle(Vector2, float, Color)
Fills a circle; radius is in pixels.
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.
public void FillRect(RectF rect, Color color)Parameters
rect RectF
color Color
FillTriangle(Vector2, Vector2, Vector2, Color)
Fills a triangle.
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.
public void Flush()PopCamera()
Returns to the coordinates in use before the last PushCamera.
public void PopCamera()Exceptions
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.
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.
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.
public void SetClip(RectF? screenRect)Parameters
screenRect RectF?