shithub: libgraphics

Download patch

ref: 02c06cfbc711c01d22bb0c52f8440f7060c10916
parent: 0874435504c0816c0e5f11a2e852507626fe185e
author: rodri <rgl@antares-labs.eu>
date: Tue Mar 26 06:42:23 EDT 2024

pass a Viewport in the Renderjob instead of a fb.

do the frame buffer clearing and swapping as part
of the rendering process, not within shootcamera.

--- a/camera.c
+++ b/camera.c
@@ -86,17 +86,15 @@
 
 	job = emalloc(sizeof *job);
 	memset(job, 0, sizeof *job);
-	job->fb = c->vp->fbctl->fb[c->vp->fbctl->idx^1];	/* address the back buffer */
+	job->v = c->vp;
 	job->scene = c->s;
 	job->shaders = s;
 	job->donec = chancreate(sizeof(void*), 0);
 
-	c->vp->fbctl->reset(c->vp->fbctl);
 	t0 = nanosec();
 	sendp(c->rctl->c, job);
 	recvp(job->donec);
 	t1 = nanosec();
-	c->vp->fbctl->swap(c->vp->fbctl);
 
 	chanfree(job->donec);
 	free(job);
--- a/graphics.h
+++ b/graphics.h
@@ -176,7 +176,7 @@
 
 struct Renderjob
 {
-	Framebuf *fb;
+	Viewport *v;
 	Scene *scene;
 	Shadertab *shaders;
 	Channel *donec;
@@ -215,6 +215,7 @@
 
 	void (*draw)(Viewport*, Image*);
 	void (*memdraw)(Viewport*, Memimage*);
+	Framebuf *(*getfb)(Viewport*);
 };
 
 struct Camera
--- a/render.c
+++ b/render.c
@@ -509,6 +509,7 @@
 			job->nrem = sc->nents;
 			job->lastid = 0;
 			job->time0 = nanosec();
+			job->v->fbctl->reset(job->v->fbctl);
 
 			if(jobq.tl == nil){
 				jobq.tl = jobq.hd = job;
@@ -526,7 +527,7 @@
 			if(ent != nil && ent != &sc->ents){
 				params = emalloc(sizeof *params);
 				memset(params, 0, sizeof *params);
-				params->fb = job->fb;
+				params->fb = job->v->getfb(job->v);
 				params->id = job->lastid++;
 				params->frag = rgb(DBlack);
 				params->donec = donec;
@@ -548,8 +549,10 @@
 			}
 			break;
 		case DONE:
-			if(--params2->job->nrem < 1)
+			if(--params2->job->nrem < 1){
+				params2->job->v->fbctl->swap(params2->job->v->fbctl);
 				send(params2->job->donec, nil);
+			}
 
 			freememimage(params2->frag);
 			free(params2);
--- a/viewport.c
+++ b/viewport.c
@@ -20,6 +20,12 @@
 	v->fbctl->memdraw(v->fbctl, dst);
 }
 
+static Framebuf *
+viewport_getfb(Viewport *v)
+{
+	return v->fbctl->fb[v->fbctl->idx^1];	/* address the back buffer */
+}
+
 Viewport *
 mkviewport(Rectangle r)
 {
@@ -32,6 +38,7 @@
 	v->fbctl = mkfbctl(r);
 	v->draw = viewport_draw;
 	v->memdraw = viewport_memdraw;
+	v->getfb = viewport_getfb;
 	return v;
 }