summaryrefslogtreecommitdiff
path: root/src/host/gfx.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/gfx.zig')
-rw-r--r--src/host/gfx.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/host/gfx.zig b/src/host/gfx.zig
index fef58c3..94e154f 100644
--- a/src/host/gfx.zig
+++ b/src/host/gfx.zig
@@ -434,6 +434,19 @@ pub const Painter = struct {
} else _ = c.SDL_RenderTexture(renderer, t, srcp, &frect(dst));
}
+ /// One atlas batch; vertex colors are premultiplied when the image is.
+ pub fn texturedTriangles(p: *Painter, image: abi.Image, vertices: []const c.SDL_Vertex, indices: []const u16) void {
+ if (vertices.len == 0 or indices.len == 0 or vertices.len > std.math.maxInt(c_int) or indices.len > std.math.maxInt(c_int)) return;
+ const entry = p.images.get(image) orelse return;
+ const texture = entry.texture orelse return;
+ if (image == p.target) return;
+ p.flush();
+ if (entry.stale) p.resolve(entry);
+ _ = c.SDL_SetTextureBlendMode(texture, textureBlend(p.blend, entry.premultiplied));
+ const stride = @sizeOf(c.SDL_Vertex);
+ _ = c.SDL_RenderGeometryRaw(p.renderer, texture, @ptrCast(&vertices[0].position), stride, &vertices[0].color, stride, @ptrCast(&vertices[0].tex_coord), stride, @intCast(vertices.len), indices.ptr, @intCast(indices.len), @sizeOf(u16));
+ }
+
/// `Command.shape`: its triangles in one geometry call, one colour for
/// every vertex (stride 0, nothing copied) or each subpath's. The
/// subpaths are for the web; native needs only the triangles.