diff options
author | rodri <rgl@antares-labs.eu> | 2024-02-27 11:29:06 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-02-27 11:29:06 +0000 |
commit | e0baf147d655409b721e41b0e3effabd39a96b34 (patch) | |
tree | ddfe6bbcaa5651650e8ff1f6e0b3b4dcc0bf07ee | |
parent | c0bc9d332f3ab51a43d5e3d0da2d5a32e938b1d2 (diff) | |
download | libgraphics-e0baf147d655409b721e41b0e3effabd39a96b34.tar.gz libgraphics-e0baf147d655409b721e41b0e3effabd39a96b34.tar.bz2 libgraphics-e0baf147d655409b721e41b0e3effabd39a96b34.zip |
have separate routines for drawing and memdrawing.
-rw-r--r-- | fb.c | 14 | ||||
-rw-r--r-- | graphics.h | 7 | ||||
-rw-r--r-- | render.c | 2 | ||||
-rw-r--r-- | viewport.c | 14 |
4 files changed, 34 insertions, 3 deletions
@@ -9,7 +9,18 @@ #include "internal.h" static void -framebufctl_draw(Framebufctl *ctl, Memimage *dst) +framebufctl_draw(Framebufctl *ctl, Image *dst) +{ + Framebuf *fb; + + fb = ctl->fb[ctl->idx]; + lock(&ctl->swplk); + loadimage(dst, rectaddpt(fb->r, dst->r.min), byteaddr(fb->cb, fb->r.min), bytesperline(fb->r, fb->cb->depth)*Dy(fb->r)); + unlock(&ctl->swplk); +} + +static void +framebufctl_memdraw(Framebufctl *ctl, Memimage *dst) { lock(&ctl->swplk); memimagedraw(dst, dst->r, ctl->fb[ctl->idx]->cb, ZP, nil, ZP, SoverD); @@ -67,6 +78,7 @@ mkfbctl(Rectangle r) fc->fb[0] = mkfb(r); fc->fb[1] = mkfb(r); fc->draw = framebufctl_draw; + fc->memdraw = framebufctl_memdraw; fc->swap = framebufctl_swap; fc->reset = framebufctl_reset; return fc; @@ -39,6 +39,7 @@ struct Vertex Color c; /* shading color */ Point2 uv; /* texture coordinate */ + /* TODO these attributes should be replaced by a hash table */ double intensity; Point3 pos; }; @@ -147,7 +148,8 @@ struct Framebufctl uint idx; /* front buffer index */ Lock swplk; - void (*draw)(Framebufctl*, Memimage*); + void (*draw)(Framebufctl*, Image*); + void (*memdraw)(Framebufctl*, Memimage*); void (*swap)(Framebufctl*); void (*reset)(Framebufctl*); }; @@ -156,6 +158,9 @@ struct Viewport { RFrame; Framebufctl *fbctl; + + void (*draw)(Viewport*, Image*); + void (*memdraw)(Viewport*, Memimage*); }; struct Camera @@ -434,7 +434,7 @@ shaderunit(void *arg) t[0][i].c.r = (*ep)->mtl != nil? (*ep)->mtl->Kd.r: 1; t[0][i].c.g = (*ep)->mtl != nil? (*ep)->mtl->Kd.g: 1; t[0][i].c.b = (*ep)->mtl != nil? (*ep)->mtl->Kd.b: 1; - t[0][i].c.a = /*(*ep)->mtl != nil? (*ep)->mtl->d:*/ 1; + t[0][i].c.a = 1; } vsp.v = &t[0][0]; @@ -8,6 +8,18 @@ #include "graphics.h" #include "internal.h" +static void +viewport_draw(Viewport *v, Image *dst) +{ + v->fbctl->draw(v->fbctl, dst); +} + +static void +viewport_memdraw(Viewport *v, Memimage *dst) +{ + v->fbctl->memdraw(v->fbctl, dst); +} + Viewport * mkviewport(Rectangle r) { @@ -18,6 +30,8 @@ mkviewport(Rectangle r) v->bx = Vec2(1,0); v->by = Vec2(0,1); v->fbctl = mkfbctl(r); + v->draw = viewport_draw; + v->memdraw = viewport_memdraw; return v; } |