renderTriangles
Rendered Triangles taking in to account the current clip rect
and deferred rendering through render targets.
Expect that dvui.Window.alpha has already been applied.
Only valid between Window.beginand Window.end.
Parameters
Source
Implementation
pub fn renderTriangles(triangles: Triangles, tex: ?Texture) Backend.GenericError!void {
if (triangles.vertexes.len == 0) {
return;
}
if (dvui.clipGet().empty()) {
return;
}
const cw = dvui.currentWindow();
if (!cw.render_target.rendering) {
const tri_copy = try triangles.dupe(cw.arena());
cw.addRenderCommand(.{ .triangles = .{ .tri = tri_copy, .tex = tex } }, false);
return;
}
// expand clipping to full pixels before testing
var clipping = dvui.clipGet();
clipping.w = @max(0, @ceil(clipping.x - @floor(clipping.x) + clipping.w));
clipping.x = @floor(clipping.x);
clipping.h = @max(0, @ceil(clipping.y - @floor(clipping.y) + clipping.h));
clipping.y = @floor(clipping.y);
const clipr: ?Rect.Physical = if (triangles.bounds.clippedBy(clipping)) clipping.offsetNegPoint(cw.render_target.offset) else null;
if (cw.render_target.offset.nonZero()) {
const offset = cw.render_target.offset;
for (triangles.vertexes) |*v| {
v.pos = v.pos.diff(offset);
}
}
cw.render_stats.draw_calls += 1;
cw.render_stats.vertices +|= @intCast(triangles.vertexes.len);
cw.render_stats.triangles +|= @intCast(triangles.indices.len / 3);
if (tex != null) cw.render_stats.texture_binds += 1;
try cw.backend.drawClippedTriangles(tex, triangles.vertexes, triangles.indices, clipr);
}