DVUI

renderTexture

Only valid between Window.beginand Window.end.

Parameters

#
tex:Texture
Texture
rs:RectScale
RectScale
opts:TextureOptions
TextureOptions

Source

Implementation

#
pub fn renderTexture(tex: Texture, rs: RectScale, opts: TextureOptions) Backend.GenericError!void {
    if (rs.s == 0) return;
    if (dvui.clipGet().intersect(rs.r).empty()) return;

    const cw = dvui.currentWindow();

    if (!cw.render_target.rendering) {
        cw.addRenderCommand(.{ .texture = .{ .tex = tex, .rs = rs, .opts = opts } }, false);
        return;
    }

    var rect = rs.r;
    if (cw.snap_to_pixels) {
        rect.x = @round(rect.x);
        rect.y = @round(rect.y);
    }

    var path: dvui.Path.Builder = .init(dvui.currentWindow().lifo());
    defer path.deinit();

    path.addRect(rect, opts.corners.scale(rs.s, CornerRect.Physical));

    var triangles = try path.build().fillConvexTriangles(cw.lifo(), .{ .color = opts.colormod.opacity(cw.alpha), .fade = opts.fade });
    defer triangles.deinit(cw.lifo());

    const uvRect = opts.uv_rect orelse rect;
    triangles.uvFromRectuv(uvRect, opts.uv);
    triangles.rotate(rect.center(), opts.rotation);

    if (opts.background_color) |bg_col| {
        var back_tri = try triangles.dupe(cw.lifo());
        defer back_tri.deinit(cw.lifo());

        back_tri.color(bg_col);
        try renderTriangles(back_tri, null);
    }

    try renderTriangles(triangles, tex);
}