diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 20:31:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-16 20:31:59 -0300 |
| commit | 82fca5c9f29124f37f6dcd08e73e6999ce44a69d (patch) | |
| tree | b3d5487659aa933d47699e5e420fa6140b0b75f3 /src/host/gfx.zig | |
| parent | e77b01d4b5504cea08a3f88cf8502897d868a1d3 (diff) | |
| download | sketchbook-82fca5c9f29124f37f6dcd08e73e6999ce44a69d.tar.gz sketchbook-82fca5c9f29124f37f6dcd08e73e6999ce44a69d.zip | |
Add display-paced frame timing and presentation feedback in Zig
Diffstat (limited to 'src/host/gfx.zig')
| -rw-r--r-- | src/host/gfx.zig | 13 |
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. |
