summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-07-14 08:32:25 +0000
committerrodri <rgl@antares-labs.eu>2024-07-14 08:32:25 +0000
commit78bf838d0c45fbe6e282450e127446de5888fa11 (patch)
tree55604bbe236d1a2846c87c14f739a05d23717926
parentaa277571f316168d7ccf043c76bd2abd97e5bacd (diff)
downloadlibgraphics-78bf838d0c45fbe6e282450e127446de5888fa11.tar.gz
libgraphics-78bf838d0c45fbe6e282450e127446de5888fa11.tar.bz2
libgraphics-78bf838d0c45fbe6e282450e127446de5888fa11.zip
small improvements and a skybox bugfix.
-rw-r--r--camera.c29
-rw-r--r--graphics.h2
-rw-r--r--xform.c2
3 files changed, 15 insertions, 18 deletions
diff --git a/camera.c b/camera.c
index deddeee..3bf0d89 100644
--- a/camera.c
+++ b/camera.c
@@ -100,25 +100,21 @@ updatetimes(Camera *c, Renderjob *j)
static void
verifycfg(Camera *c)
{
- assert(c->vp != nil);
+ assert(c->view != nil);
if(c->projtype == PERSPECTIVE)
assert(c->fov > 0 && c->fov < 360*DEG);
assert(c->clip.n > 0 && c->clip.n < c->clip.f);
}
Camera *
-Cam(Rectangle vr, Renderer *r, Projection p, double fov, double clipn, double clipf)
+Cam(Rectangle vr, Renderer *r, Projection p, double fov, double n, double f)
{
Camera *c;
c = newcamera();
- c->vp = mkviewport(vr);
+ c->view = mkviewport(vr);
c->rctl = r;
- c->projtype = p;
- c->fov = fov;
- c->clip.n = clipn;
- c->clip.f = clipf;
- reloadcamera(c);
+ configcamera(c, p, fov, n, f);
return c;
}
@@ -137,7 +133,7 @@ delcamera(Camera *c)
{
if(c == nil)
return;
- rmviewport(c->vp);
+ rmviewport(c->view);
free(c);
}
@@ -151,14 +147,14 @@ reloadcamera(Camera *c)
switch(c->projtype){
case ORTHOGRAPHIC:
- r = Dx(c->vp->r)/2;
- t = Dy(c->vp->r)/2;
+ r = Dx(c->view->r)/2;
+ t = Dy(c->view->r)/2;
l = -r;
b = -t;
orthographic(c->proj, l, r, b, t, c->clip.n, c->clip.f);
break;
case PERSPECTIVE:
- a = (double)Dx(c->vp->r)/Dy(c->vp->r);
+ a = (double)Dx(c->view->r)/Dy(c->view->r);
perspective(c->proj, c->fov, a, c->clip.n, c->clip.f);
break;
default: sysfatal("unknown projection type");
@@ -217,18 +213,18 @@ shootcamera(Camera *c, Shadertab *s)
Renderjob *job;
uvlong t0, t1;
- assert(c->vp != nil && c->rctl != nil && s != nil);
+ assert(c->view != nil && c->rctl != nil && c->scene != nil && s != nil);
job = emalloc(sizeof *job);
memset(job, 0, sizeof *job);
- job->fb = c->vp->fbctl->getbb(c->vp->fbctl);
+ job->fb = c->view->fbctl->getbb(c->view->fbctl);
cam = *c;
job->camera = &cam;
job->scene = dupscene(c->scene); /* take a snapshot */
job->shaders = s;
job->donec = chancreate(sizeof(void*), 0);
- c->vp->fbctl->reset(c->vp->fbctl);
+ c->view->fbctl->reset(c->view->fbctl);
t0 = nanosec();
sendp(c->rctl->c, job);
recvp(job->donec);
@@ -244,6 +240,7 @@ shootcamera(Camera *c, Shadertab *s)
skyboxscene->addent(skyboxscene, newentity("skybox", mdl));
}
skyboxscene->skybox = c->scene->skybox;
+ job->camera->cullmode = CullNone;
job->scene = dupscene(skyboxscene);
job->shaders = &skyboxshader;
sendp(c->rctl->c, job);
@@ -251,7 +248,7 @@ shootcamera(Camera *c, Shadertab *s)
delscene(job->scene);
}
t1 = nanosec();
- c->vp->fbctl->swap(c->vp->fbctl);
+ c->view->fbctl->swap(c->view->fbctl);
updatestats(c, t1-t0);
updatetimes(c, job);
diff --git a/graphics.h b/graphics.h
index f09c6cf..3c170f7 100644
--- a/graphics.h
+++ b/graphics.h
@@ -277,7 +277,7 @@ struct Viewport
struct Camera
{
RFrame3; /* VCS */
- Viewport *vp;
+ Viewport *view;
Scene *scene;
Renderer *rctl;
double fov; /* vertical FOV */
diff --git a/xform.c b/xform.c
index c661688..0efbbe3 100644
--- a/xform.c
+++ b/xform.c
@@ -124,7 +124,7 @@ ndc2vcs(Camera *c, Point3 p)
Point3
viewport2vcs(Camera *c, Point3 p)
{
- return ndc2vcs(c, viewport2ndc(c->vp->getfb(c->vp), p));
+ return ndc2vcs(c, viewport2ndc(c->view->getfb(c->view), p));
}
Point3