shithub: libgraphics

Download patch

ref: 6e461add61d35d23f733cffb5064a286419b79b0
parent: 086d2bb276e55f81bd13d03c15d9325db4d2bd4f
author: rodri <rgl@antares-labs.eu>
date: Fri May 17 10:47:12 EDT 2024

render: improve line raster (not fixed yet). also tag jobs with an id.

--- a/graphics.h
+++ b/graphics.h
@@ -195,6 +195,7 @@
 struct Renderjob
 {
 	Ref;
+	uvlong id;
 	Framebuf *fb;
 	Scene *scene;
 	Shadertab *shaders;
@@ -248,7 +249,7 @@
 	struct {
 		double n, f;	/* near and far clipping planes */
 	} clip;
-	Matrix3 proj;		/* VCS to NDC xform */
+	Matrix3 proj;		/* VCS to clip space xform */
 	Projection projtype;
 
 	struct {
--- a/render.c
+++ b/render.c
@@ -226,19 +226,16 @@
 		e = 0;
 		Δy = p1.y > p0.y? 1: -1;
 
-		/* TODO find out why sometimes lines go invisible depending on their location */
-
 		for(p = p0; p.x <= p1.x; p.x++){
 			Δp = subpt(p, p0);
 			dplen = hypot(dp.x, dp.y);
 			perc = dplen == 0? 0: hypot(Δp.x, Δp.y)/dplen;
 
-			if(steep) swapi(&p.x, &p.y);
-
+			/* TODO it seems depth testing messes with the output. find out why */
 			z = flerp(prim.v[0].p.z, prim.v[1].p.z, perc);
 			depth = fclamp(z, 0, 1);
 			if(depth <= params->fb->zb[p.x + p.y*Dx(params->fb->r)])
-				break;
+				continue;
 			params->fb->zb[p.x + p.y*Dx(params->fb->r)] = depth;
 
 			/* interpolate z⁻¹ and get actual z */
@@ -249,6 +246,8 @@
 			perc *= prim.v[0].p.w * z;
 			lerpvertex(&fsp.v, &prim.v[0], &prim.v[1], perc);
 
+			if(steep) swapi(&p.x, &p.y);
+
 			fsp.p = p;
 			c = params->fshader(&fsp);
 			memfillcolor(params->frag, col2ul(c));
@@ -639,11 +638,12 @@
 	Entity *ent;
 	SUparams *params;
 	Channel *paramsc;
-	uvlong time;
+	uvlong time, lastid;
 
 	threadsetname("renderer");
 
 	jobc = arg;
+	lastid = 0;
 	paramsc = chancreate(sizeof(SUparams*), 8);
 
 	proccreate(entityproc, paramsc, mainstacksize);
@@ -651,6 +651,7 @@
 	while((job = recvp(jobc)) != nil){
 		time = nanosec();
 		job->times.R.t0 = time;
+		job->id = lastid++;
 		sc = job->scene;
 		if(sc->nents < 1){
 			nbsend(job->donec, nil);