feat: threads

This commit is contained in:
Dan Finch 2026-08-05 09:24:13 +02:00
parent 6fb46573da
commit 46e7070b6b
18 changed files with 878 additions and 125 deletions

View file

@ -51,6 +51,8 @@ export namespace Rasterizer {
viewProj: Mat4,
config: RenderConfig,
cull = false,
clipY0 = 0,
clipY1 = 1 << 30,
): void {
const { verts, indices } = mesh
const flat = config.lighting === "flat"
@ -65,7 +67,7 @@ export namespace Rasterizer {
// Near-clipping can turn one triangle into a quad; fan it back to tris.
const n = clipNear(3)
for (let k = 1; k + 1 < n; k++) {
fillTriangle(fb, 0, k, k + 1, shade, texture, config, cull)
fillTriangle(fb, 0, k, k + 1, shade, texture, config, cull, clipY0, clipY1)
}
}
}
@ -167,6 +169,8 @@ export namespace Rasterizer {
texture: Texture,
config: RenderConfig,
cull: boolean,
clipY0: number,
clipY1: number,
): void {
const oa = ia * CLIP
const ob = ib * CLIP
@ -210,8 +214,10 @@ export namespace Rasterizer {
const vC = dst[oc + 4]
const minX = Math.max(0, Math.floor(Math.min(sxA, sxB, sxC)))
const maxX = Math.min(width - 1, Math.ceil(Math.max(sxA, sxB, sxC)))
const minY = Math.max(0, Math.floor(Math.min(syA, syB, syC)))
const maxY = Math.min(height - 1, Math.ceil(Math.max(syA, syB, syC)))
// Clamp to the caller's Y-band (default full frame) so worker threads can
// each fill a disjoint slice of rows without ever touching the same pixel.
const minY = Math.max(0, clipY0, Math.floor(Math.min(syA, syB, syC)))
const maxY = Math.min(height - 1, clipY1 - 1, Math.ceil(Math.max(syA, syB, syC)))
// Edge deltas for the three barycentric edge functions (b->c, c->a, a->b).
const dx0 = sxC - sxB
const dy0 = syC - syB