From 093323c36fa083a897dc371b36889296d1069715 Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 14 Jun 2024 18:15:52 +0000 Subject: vis: add some instrumentation to debug the framebuffers. --- dat.h | 2 ++ vis.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/dat.h b/dat.h index bad9c4d..ead68ef 100644 --- a/dat.h +++ b/dat.h @@ -29,5 +29,7 @@ enum { Sfps, Sframes, Sorient, + Spixcol, + Snorcol, Se }; diff --git a/vis.c b/vis.c index f735013..84987df 100644 --- a/vis.c +++ b/vis.c @@ -90,6 +90,7 @@ static int showskybox; static int doprof; static int inception; static int showhud; +static int shownormals; Color (*tsampler)(Memimage*,Point2); static int @@ -479,7 +480,10 @@ redraw(void) bg = eallocimage(display, UR, RGB24, 1, 0x888888FF); lockdisplay(display); - maincam->vp->draw(maincam->vp, screenb); + if(shownormals) + maincam->vp->fbctl->drawnormals(maincam->vp->fbctl, screenb); + else + maincam->vp->draw(maincam->vp, screenb); draw(screen, screen->r, bg, nil, ZP); draw(screen, screen->r, screenb, nil, ZP); if(showhud) @@ -541,6 +545,18 @@ drawproc(void *) } } +static Color +ul2col(ulong l) +{ + Color c; + + c.a = (l & 0xff)/255.0; + c.b = (l>>8 & 0xff)/255.0; + c.g = (l>>16 & 0xff)/255.0; + c.r = (l>>24 & 0xff)/255.0; + return c; +} + void lmb(void) { @@ -557,6 +573,21 @@ lmb(void) e->by = Vecquat(mulq(mulq(Δorient, Quatvec(0, e->by)), invq(Δorient))); e->bz = Vecquat(mulq(mulq(Δorient, Quatvec(0, e->bz)), invq(Δorient))); } + }else{ + Framebuf *fb; + Point p; + Color c, n; + double z; + + p = subpt(mctl->xy, screen->r.min); + qlock(maincam->vp->fbctl); + fb = maincam->vp->getfb(maincam->vp); + c = ul2col(fb->cb[p.y*Dx(fb->r) + p.x]); + n = ul2col(fb->nb[p.y*Dx(fb->r) + p.x]); + z = fb->zb[p.y*Dx(fb->r) + p.x]; + qunlock(maincam->vp->fbctl); + snprint(stats[Spixcol], sizeof(stats[Spixcol]), "c %V z %g", c, z); + snprint(stats[Snorcol], sizeof(stats[Snorcol]), "n %V", n); } } @@ -567,11 +598,13 @@ mmb(void) MOVELIGHT, TSNEAREST, TSBILINEAR, + SHOWNORMALS, }; static char *items[] = { [MOVELIGHT] "move light", [TSNEAREST] "use nearest sampler", [TSBILINEAR] "use bilinear sampler", + [SHOWNORMALS] "show normals", nil, }; static Menu menu = { .item = items }; @@ -597,6 +630,9 @@ mmb(void) case TSBILINEAR: tsampler = bilitexsampler; break; + case SHOWNORMALS: + shownormals ^= 1; + break; } qunlock(&drawlk); nbsend(drawc, nil); -- cgit v1.2.3