shithub: libgraphics

Download patch

ref: ef937fa5a18d8ec79099e5cf414324a4e23c94c4
parent: 6877b7512da0067202dcb3184b9507424210c67f
author: rodri <rgl@antares-labs.eu>
date: Thu Apr 24 18:01:20 EDT 2025

do not dup the scene, let the user handle that

i was trying to keep the user from having to sync rendering while
moving objects around by duplicating the scene every time a picture
was taken.  it seemed like a good idea at first, but we're just lying
to ourselves.  it's the user's responsibility to keep their update()
from messing with their render() anyway, and doing a duplication
without any form of locking on the user side is an invitation for
broken programs.

with this change we go back to the way it was before, and prims only
get copied while they are on the tilers and later being rasterized.
it uses less memory and keeps us from assuming things that are wrong.

--- a/camera.c
+++ b/camera.c
@@ -248,7 +248,6 @@
 	job->fb = fbctl->getbb(fbctl);
 	job->camera = _emalloc(sizeof *c);
 	*job->camera = *c;
-	job->camera->scene = dupscene(c->scene);	/* take a snapshot */
 	job->shaders = s;
 	job->donec = chancreate(sizeof(void*), 0);
 
@@ -255,7 +254,6 @@
 	t0 = nanosec();
 	sendp(c->rctl->jobq, job);
 	recvp(job->donec);
-	delscene(job->camera->scene);			/* destroy the snapshot */
 	/*
 	 * if the scene has a skybox, do another render pass,
 	 * filling in the pixels left untouched.
@@ -269,12 +267,11 @@
 		job->camera->cullmode = CullNone;
 		job->camera->fov = 90*DEG;
 		reloadcamera(job->camera);
-		job->camera->scene = dupscene(skyboxscene);
-		job->camera->scene->skybox = dupcubemap(c->scene->skybox);
+		job->camera->scene = skyboxscene;
+		job->camera->scene->skybox = c->scene->skybox;
 		job->shaders = &skyboxshader;
 		sendp(c->rctl->jobq, job);
 		recvp(job->donec);
-		delscene(job->camera->scene);
 	}
 	t1 = nanosec();
 	fbctl->swap(fbctl);
--- a/render.c
+++ b/render.c
@@ -553,7 +553,7 @@
 	SUparams *params, *newparams;
 	Rastertask *task;
 	Shaderparams vsp;
-	Primitive *ep, *cp, *p;		/* primitives to raster */
+	Primitive *ep, *cp, *p, prim;	/* primitives to raster */
 	Rectangle *wr, bbox;
 	Channel **taskchans;
 	ulong Δy, nproc;
@@ -620,7 +620,8 @@
 		for(ep = params->eb; ep != params->ee; ep++){
 			np = 1;	/* start with one. after clipping it might change */
 
-			p = ep;
+			prim = *ep;
+			p = &prim;
 			switch(p->type){
 			case PPoint:
 				p->v[0].mtl = p->mtl;
--