BPL_BL_Canvas
BurrowLib 0.2.0, in the palette under BurrowLib › Canvas.
Drawing into a render target from a Blueprint.
A render target’s canvas draws every call on its own, so a picture made of many small draws costs a render draw each, and a thousand a frame is enough to stall the game. Instead, collect the picture as triangles in one array with AddRect, and hand the whole array to DrawTriangles, which draws it in a single call.
Functions
Section titled “Functions”AddRect
Section titled “AddRect”Adds a filled rectangle to a batch, as two triangles of one colour. x and y are its top left corner, in pixels of the render target.
fn AddRect(tris: ref array<CanvasUVTri>, x: float, y: float, w: float, h: float, colour: LinearColor)DrawTriangles
Section titled “DrawTriangles”Draws a batch of triangles into a render target in one call. It draws over what the target already holds, so a picture that changes should start with a rectangle covering it.
fn DrawTriangles(target: TextureRenderTarget2D, tris: ref array<CanvasUVTri>)Examples
Section titled “Examples”Drawing a picture in one call
Section titled “Drawing a picture in one call”Paint collects a dark background and an orange square as triangles, then draws them into the render target in one call. Set Target on the placed actor to the render target to draw into.
An Actor Blueprint, BP_CanvasPicture, with:
- a variable Tris, Array of Canvas UVTri Structures
- a variable Target, Texture Render Target 2D Object Reference, instance editable
Function Paint
Event Graph
blueprint BP_CanvasPicture : Actor at /Game/Mods/BurrowLibExamples/CanvasPicture/Loom/BP_CanvasPictureuse /Game/Mods/BurrowLib_0_2_0
// The picture, as triangles, collected before it is drawn.var Tris: array<CanvasUVTri>// Where the picture is drawn. Set it on the placed actor.editable var Target: TextureRenderTarget2D
on ReceiveBeginPlay { Paint()}
// Collects a dark background with an orange square on it, then draws the lot in one call.fn Paint() { Tris.Clear() BPL_BL_Canvas.AddRect(Tris, 0.0, 0.0, 256.0, 256.0, LinearColor(R: 0.02, G: 0.02, B: 0.03, A: 1.0)) BPL_BL_Canvas.AddRect(Tris, 96.0, 96.0, 64.0, 64.0, LinearColor(R: 1.0, G: 0.35, B: 0.0, A: 1.0)) if KismetSystemLibrary.IsValid(Target) { BPL_BL_Canvas.DrawTriangles(Target, Tris) }}