shithub: 3dee

Download patch

ref: bbadf2f31be926a9755548d7a2e9e96444224ec9
parent: e862d6f0224de67b0a329e16b91841206feb844a
author: rodri <[email protected]>
date: Wed Sep 11 16:58:17 EDT 2024

adapt to new changes in libgraphics.

--- a/med.c
+++ b/med.c
@@ -130,10 +130,11 @@
 	p[2] = Pt3(Dx(cam->view->r),Dy(cam->view->r),1,1);
 	p[3] = Pt3(0,Dy(cam->view->r),1,1);
 	memset(&l, 0, sizeof l);
+	l.type = PLine;
+	l.v[0].c = l.v[1].c = Pt3(1,1,1,1);
 
 	for(i = 0; i < nelem(p); i++){
 		/* front frame */
-		l.type = PLine;
 		l.v[0].p = world2model(subject, viewport2world(cam, p[i]));
 		l.v[1].p = world2model(subject, viewport2world(cam, p[(i+1)%nelem(p)]));
 		qlock(&scenelk);
@@ -496,10 +497,13 @@
 void
 renderproc(void *)
 {
+	static Image *bg;
 	uvlong t0, Δt;
 
 	threadsetname("renderproc");
 
+	bg = eallocimage(display, UR, XRGB32, 1, 0x888888FF);
+
 	t0 = nsec();
 	for(;;){
 		qlock(&scenelk);
@@ -509,6 +513,7 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
+			draw(screenb, screenb->r, bg, nil, ZP);
 			cam->view->draw(cam->view, screenb, nil);
 			compass.cam->view->draw(compass.cam->view, screenb, nil);
 			unlockdisplay(display);
--- a/solar.c
+++ b/solar.c
@@ -168,28 +168,6 @@
 static int doprof;
 static int showhud;
 
-static Point3
-minpt3(Point3 a, Point3 b)
-{
-	return (Point3){
-		min(a.x, b.x),
-		min(a.y, b.y),
-		min(a.z, b.z),
-		min(a.w, b.w)
-	};
-}
-
-static Point3
-maxpt3(Point3 a, Point3 b)
-{
-	return (Point3){
-		max(a.x, b.x),
-		max(a.y, b.y),
-		max(a.z, b.z),
-		max(a.w, b.w)
-	};
-}
-
 static void
 refreshinfobox(Infobox *info)
 {
@@ -202,7 +180,7 @@
 	assert(info != nil && info->image != nil && info->items != nil);
 
 	if(tbg == nil){
-		tbg = eallocimage(display, UR, RGBA32, 1, 0x4444887F);
+		tbg = eallocimage(display, UR, RGBA32, 1, 0x2222447F);
 		tfg = display->white;
 		bg[0] = eallocimage(display, UR, RGBA32, 1, 0xEEEEEEEE);
 		bg[1] = eallocimage(display, UR, RGBA32, 1, 0xAAAAAAAA);
@@ -557,10 +535,13 @@
 void
 renderproc(void *)
 {
+	static Image *bg;
 	uvlong t0, Δt;
 
 	threadsetname("renderproc");
 
+	bg = eallocimage(display, UR, XRGB32, 1, DBlack);
+
 	t0 = nsec();
 	for(;;){
 		shootcamera(camera, &shader);
@@ -567,6 +548,7 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
+			draw(screenb, screenb->r, bg, nil, ZP);
 			camera->view->draw(camera->view, screenb, nil);
 			unlockdisplay(display);
 			nbsend(drawc, nil);
@@ -951,6 +933,7 @@
 		else
 			cmds[i].r = rectaddpt(cmds[i].r, Pt(cmds[i-1].r.max.x+Cmdmargin,cmds[i-1].r.min.y));
 	}
+
 	screenb = eallocimage(display, viewr, XRGB32, 0, DNofill);
 	camera = Cam(screenb->r, rctl, cameracfg.ptype, cameracfg.fov, cameracfg.clipn, cameracfg.clipf);
 	placecamera(camera, scene, cameracfg.p, cameracfg.lookat, cameracfg.up);
--- a/vis.c
+++ b/vis.c
@@ -52,6 +52,7 @@
 };
 char stats[Se][256];
 Image *screenb;
+Image *clr;
 Mousectl *mctl;
 Keyboardctl *kctl;
 Channel *drawc;
@@ -166,6 +167,7 @@
 	else
 		tc = Pt3(1,1,1,1);
 
+	sp->v->n.w = 1;
 	sp->toraster(sp, "normals", &sp->v->n);
 
 	return modulapt3(sp->v->c, tc);
@@ -266,6 +268,7 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
+	sp->v->n.w = 1;
 	sp->toraster(sp, "normals", &sp->v->n);
 
 	c = addpt3(ambient, addpt3(diffuse, specular));
@@ -340,6 +343,7 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
+	sp->v->n.w = 1;
 	sp->toraster(sp, "normals", &sp->v->n);
 
 	c = addpt3(ambient, addpt3(diffuse, specular));
@@ -377,6 +381,7 @@
 		 intens > 0.30? 0.45:
 		 intens > 0.15? 0.30: 0.15;
 
+	sp->v->n.w = 1;
 	sp->toraster(sp, "normals", &sp->v->n);
 
 	return Pt3(intens, 0.6*intens, 0, 1);
@@ -402,6 +407,7 @@
 	else
 		tc = Pt3(1,1,1,1);
 
+	sp->v->n.w = 1;
 	sp->toraster(sp, "normals", &sp->v->n);
 
 	return modulapt3(sp->v->c, tc);
@@ -605,6 +611,7 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
+			draw(screenb, screenb->r, clr, nil, ZP);
 			maincam->view->draw(maincam->view, screenb, shownormals? "normals": nil);
 			unlockdisplay(display);
 			nbsend(drawc, nil);
@@ -630,18 +637,6 @@
 	}
 }
 
-static Color
-ul2col(ulong l)
-{
-	Color c;
-
-	c.b = (l     & 0xff)/255.0;
-	c.g = (l>>8  & 0xff)/255.0;
-	c.r = (l>>16 & 0xff)/255.0;
-	c.a = (l>>24 & 0xff)/255.0;
-	return c;
-}
-
 void
 lmb(void)
 {
@@ -743,6 +738,7 @@
 	static Menu menu = { .item = items };
 	char buf[256], *f[3];
 	int nf;
+	ulong clrcol;
 
 	lockdisplay(display);
 	switch(menuhit(2, mctl, &menu, _screen)){
@@ -767,13 +763,18 @@
 		shownormals ^= 1;
 		break;
 	case SETCLRCOL:
-		snprint(buf, sizeof buf, "0x%08lux", maincam->clearcolor);
+		if(unloadimage(clr, UR, (uchar*)&clrcol, 4) != 4)
+			break;
+		clrcol = clrcol<<8 | 0xFF;	/* xrgb2rgba */
+		snprint(buf, sizeof buf, "0x%08lux", clrcol);
 		if(enter("clear color", buf, sizeof buf, mctl, kctl, nil) <= 0)
 			break;
 		nf = tokenize(buf, f, 1);
 		if(nf != 1)
 			break;
-		maincam->clearcolor = strtoul(buf, nil, 0);
+		clrcol = strtoul(buf, nil, 0);
+		freeimage(clr);
+		clr = eallocimage(display, UR, XRGB32, 1, clrcol);
 		break;
 	case CULLFRONT:
 		maincam->cullmode = CullFront;
@@ -1108,7 +1109,10 @@
 
 	rctl->doprof = doprof;
 
-	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, 0x888888FF);
+	clr = eallocimage(display, UR, XRGB32, 1, 0x888888FF);
+	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, DNofill);
+//	if(nameimage(screenb, "screenb", 1) == 0)
+//		sysfatal("nameimage: %r");
 fprint(2, "screen %R\n", screenb->r);
 	for(i = 0; i < nelem(cams); i++){
 		if(fbw == 0 || fbh == 0)