From 76f41120c1d9685ea78e940bcaf23db79e17f4cd Mon Sep 17 00:00:00 2001 From: rodri Date: Thu, 9 Nov 2023 17:07:05 +0000 Subject: track nanosec.c and fix some things. --- main.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 2581117..741322b 100644 --- a/main.c +++ b/main.c @@ -207,14 +207,14 @@ filltriangle(Memimage *dst, Point p0, Point p1, Point p2, Memimage *src) } void -shade(Memimage *dst, Memimage *(*shader)(Point)) +shade(Memimage *dst, Rectangle r, Memimage *(*shader)(Point)) { Point p; Memimage *c; - p = ZP; - for(; p.y < Dy(dst->r); p.y++) - for(p.x = 0; p.x < Dx(dst->r); p.x++) + p = r.min; + for(; p.y < r.max.y; p.y++) + for(p.x = 0; p.x < r.max.x; p.x++) if((c = shader(p)) != nil) pixel(dst, p, c); } @@ -231,10 +231,8 @@ triangleshader(Point p) t.p2 = Pt2(240,40,1); bbox = Rect( - min(min(t.p0.x, t.p1.x), t.p2.x), - min(min(t.p0.y, t.p1.y), t.p2.y), - max(max(t.p0.x, t.p1.x), t.p2.x), - max(max(t.p0.y, t.p1.y), t.p2.y) + min(min(t.p0.x, t.p1.x), t.p2.x), min(min(t.p0.y, t.p1.y), t.p2.y), + max(max(t.p0.x, t.p1.x), t.p2.x), max(max(t.p0.y, t.p1.y), t.p2.y) ); if(!ptinrect(p, bbox)) return nil; @@ -250,7 +248,7 @@ redraw(void) { lockdisplay(display); draw(screen, screen->r, display->black, nil, ZP); - loadimage(screen, screen->r, byteaddr(fb, fb->r.min), bytesperline(fb->r, fb->depth)*Dy(fb->r)); + loadimage(screen, fb->r, byteaddr(fb, fb->r.min), bytesperline(fb->r, fb->depth)*Dy(fb->r)); flushimage(display, 1); unlockdisplay(display); } @@ -334,7 +332,7 @@ threadmain(int argc, char *argv[]) triangle(fb, Pt(400,230), Pt(450,180), Pt(150, 320), red); t0 = nanosec(); - shade(fb, triangleshader); + shade(fb, rectsubpt(fb->r, fb->r.min), triangleshader); t1 = nanosec(); fprint(2, "shader took %lludns\n", t1-t0); -- cgit v1.2.3