diff options
author | rodri <rgl@antares-labs.eu> | 2024-07-15 20:06:47 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-07-15 20:06:47 +0000 |
commit | ac662557dc246b04ad1b9fa755a40ed0ec05d386 (patch) | |
tree | c858909b501bd3210dc3c13340b9085d0ccc6923 | |
parent | 5f10c82aad318fc9091c9bd612e89fda1a77009f (diff) | |
download | libgraphics-ac662557dc246b04ad1b9fa755a40ed0ec05d386.tar.gz libgraphics-ac662557dc246b04ad1b9fa755a40ed0ec05d386.tar.bz2 libgraphics-ac662557dc246b04ad1b9fa755a40ed0ec05d386.zip |
fix stack overflow, skybox fov sensibility and scene duplication.
putting the duplicate camera in a local variable turned
out to be a bad idea. bring the dynamic version back.
the skybox rendering was affected by the camera fov, which
made it look like it was not really at infinity, so set it
always to 90°.
-rw-r--r-- | camera.c | 15 | ||||
-rw-r--r-- | graphics.h | 1 | ||||
-rw-r--r-- | scene.c | 4 | ||||
-rw-r--r-- | texture.c | 25 |
4 files changed, 30 insertions, 15 deletions
@@ -19,9 +19,9 @@ skyboxvs(VSparams *sp) addvattr(sp->v, "dir", VAPoint, &sp->v->p); /* only rotate along with the camera */ - p = sp->v->p; p.w = 0; - p = world2vcs(sp->su->camera, p); p.w = 1; - p = vcs2clip(sp->su->camera, p); + p = sp->v->p; + p.w = 0; p = world2vcs(sp->su->camera, p); + p.w = 1; p = vcs2clip(sp->su->camera, p); /* force the cube to always be on the far plane */ p.z = -p.w; return p; @@ -208,7 +208,6 @@ shootcamera(Camera *c, Shadertab *s) { static Scene *skyboxscene; static Shadertab skyboxshader = { nil, skyboxvs, skyboxfs }; - Camera cam; Model *mdl; Renderjob *job; uvlong t0, t1; @@ -218,8 +217,8 @@ shootcamera(Camera *c, Shadertab *s) job = emalloc(sizeof *job); memset(job, 0, sizeof *job); job->fb = c->view->fbctl->getbb(c->view->fbctl); - cam = *c; - job->camera = &cam; + job->camera = emalloc(sizeof *c); + *job->camera = *c; job->scene = dupscene(c->scene); /* take a snapshot */ job->shaders = s; job->donec = chancreate(sizeof(void*), 0); @@ -239,8 +238,9 @@ shootcamera(Camera *c, Shadertab *s) mdl = mkskyboxmodel(); skyboxscene->addent(skyboxscene, newentity("skybox", mdl)); } - skyboxscene->skybox = c->scene->skybox; job->camera->cullmode = CullNone; + job->camera->fov = 90*DEG; + reloadcamera(job->camera); job->scene = dupscene(skyboxscene); job->shaders = &skyboxshader; sendp(c->rctl->c, job); @@ -254,5 +254,6 @@ shootcamera(Camera *c, Shadertab *s) updatetimes(c, job); chanfree(job->donec); + free(job->camera); free(job); } @@ -360,6 +360,7 @@ Color neartexsampler(Texture*, Point2); Color bilitexsampler(Texture*, Point2); Color sampletexture(Texture*, Point2, Color(*)(Texture*, Point2)); Cubemap *readcubemap(char*[6]); +Cubemap *dupcubemap(Cubemap*); void freecubemap(Cubemap*); Color samplecubemap(Cubemap*, Point3, Color(*)(Texture*, Point2)); @@ -322,8 +322,7 @@ dupmodel(Model *m) return nil; nm = newmodel(); - if(m->tex != nil) - nm->tex = duptexture(m->tex); + nm->tex = duptexture(m->tex); if(m->nmaterials > 0){ nm->nmaterials = m->nmaterials; nm->materials = emalloc(nm->nmaterials*sizeof(*nm->materials)); @@ -456,6 +455,7 @@ dupscene(Scene *s) if(s->nents > 0) for(e = s->ents.next; e != &s->ents; e = e->next) ns->addent(ns, dupentity(e)); + ns->skybox = dupcubemap(s->skybox); return ns; } @@ -125,14 +125,9 @@ alloctexture(int type, Memimage *i) Texture * duptexture(Texture *t) { - Texture *nt; - if(t == nil) return nil; - - nt = alloctexture(t->type, nil); - nt->image = dupmemimage(t->image); - return nt; + return alloctexture(t->type, dupmemimage(t->image)); } void @@ -172,6 +167,24 @@ readcubemap(char *paths[6]) return cm; } +Cubemap * +dupcubemap(Cubemap *cm) +{ + Cubemap *ncm; + int i; + + if(cm == nil) + return nil; + + ncm = emalloc(sizeof *ncm); + memset(ncm, 0, sizeof *ncm); + if(cm->name != nil) + ncm->name = strdup(cm->name); + for(i = 0; i < 6; i++) + ncm->faces[i] = duptexture(cm->faces[i]); + return ncm; +} + void freecubemap(Cubemap *cm) { |