aboutsummaryrefslogtreecommitdiff
path: root/camera.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-01-30 12:01:01 +0000
committerrodri <rgl@antares-labs.eu>2024-01-30 12:01:01 +0000
commit37da5f0a27740bb43bac67a2eb98f725beca975e (patch)
tree2e403bbd2f477e65c8b82f10e950721b4103c895 /camera.c
parentdf792cbb5cf94abf0d286ebfd73bad9714dce509 (diff)
downloadlibgraphics-37da5f0a27740bb43bac67a2eb98f725beca975e.tar.gz
libgraphics-37da5f0a27740bb43bac67a2eb98f725beca975e.tar.bz2
libgraphics-37da5f0a27740bb43bac67a2eb98f725beca975e.zip
import the new renderer and clean things up.
i integrated the renderer i've been developing on the tinyrend repo and got rid of a bunch of stuff that's no longer necessary. also began structuring things to fit the new interface i have in mind. there are still some artifacts with the projection xforms that cause issues with clipping and division by zero.
Diffstat (limited to 'camera.c')
-rw-r--r--camera.c57
1 files changed, 40 insertions, 17 deletions
diff --git a/camera.c b/camera.c
index 1d67868..7b33c91 100644
--- a/camera.c
+++ b/camera.c
@@ -1,32 +1,41 @@
#include <u.h>
#include <libc.h>
+#include <thread.h>
#include <draw.h>
+#include <memdraw.h>
#include <geometry.h>
-#include <graphics.h>
+#include "libobj/obj.h"
+#include "graphics.h"
+#include "internal.h"
-static int
-max(int a, int b)
+static void
+updatestats(Camera *c, uvlong v)
{
- return a > b ? a : b;
+ c->stats.v = v;
+ c->stats.n++;
+ c->stats.acc += v;
+ c->stats.avg = c->stats.acc/c->stats.n;
+ c->stats.min = v < c->stats.min || c->stats.n == 1? v: c->stats.min;
+ c->stats.max = v > c->stats.max || c->stats.n == 1? v: c->stats.max;
}
static void
verifycfg(Camera *c)
{
- assert(c->viewport != nil);
- if(c->ptype == Ppersp)
+ assert(c->vp != nil);
+ if(c->projtype == PERSPECTIVE)
assert(c->fov > 0 && c->fov < 360*DEG);
assert(c->clip.n > 0 && c->clip.n < c->clip.f);
}
void
-configcamera(Camera *c, Image *v, double fov, double n, double f, Projection p)
+configcamera(Camera *c, Viewport *v, double fov, double n, double f, Projection p)
{
- c->viewport = v;
+ c->vp = v;
c->fov = fov;
c->clip.n = n;
c->clip.f = f;
- c->ptype = p;
+ c->projtype = p;
reloadcamera(c);
}
@@ -55,23 +64,37 @@ reloadcamera(Camera *c)
double l, r, b, t;
verifycfg(c);
- switch(c->ptype){
- case Portho:
+ switch(c->projtype){
+ case ORTHOGRAPHIC:
/*
- r = Dx(c->viewport->r)/2;
- t = Dy(c->viewport->r)/2;
+ r = Dx(c->vp->fbctl->fb[0]->r)/2;
+ t = Dy(c->vp->fbctl->fb[0]->r)/2;
l = -r;
b = -t;
*/
l = t = 0;
- r = Dx(c->viewport->r);
- b = Dy(c->viewport->r);
+ r = Dx(c->vp->fbctl->fb[0]->r);
+ b = Dy(c->vp->fbctl->fb[0]->r);
orthographic(c->proj, l, r, b, t, c->clip.n, c->clip.f);
break;
- case Ppersp:
- a = (double)Dx(c->viewport->r)/Dy(c->viewport->r);
+ case PERSPECTIVE:
+ a = (double)Dx(c->vp->fbctl->fb[0]->r)/Dy(c->vp->fbctl->fb[0]->r);
perspective(c->proj, c->fov, a, c->clip.n, c->clip.f);
break;
default: sysfatal("unknown projection type");
}
}
+
+void
+shootcamera(Camera *c, OBJ *m, Memimage *tex, Shader *s)
+{
+ uvlong t0, t1;
+
+ c->vp->fbctl->reset(c->vp->fbctl);
+ t0 = nanosec();
+ shade(c->vp->fbctl->fb[c->vp->fbctl->idx^1], m, tex, s, 1); /* address the back buffer */
+ t1 = nanosec();
+ c->vp->fbctl->swap(c->vp->fbctl);
+
+ updatestats(c, t1-t0);
+}