summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fb.c14
-rw-r--r--graphics.h7
-rw-r--r--render.c2
-rw-r--r--viewport.c14
4 files changed, 34 insertions, 3 deletions
diff --git a/fb.c b/fb.c
index a7a5122..17496ac 100644
--- a/fb.c
+++ b/fb.c
@@ -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;
diff --git a/graphics.h b/graphics.h
index e98ae9a..1e04c13 100644
--- a/graphics.h
+++ b/graphics.h
@@ -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
diff --git a/render.c b/render.c
index d4e63ac..8f3a41e 100644
--- a/render.c
+++ b/render.c
@@ -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];
diff --git a/viewport.c b/viewport.c
index 81e1653..0e9b9c5 100644
--- a/viewport.c
+++ b/viewport.c
@@ -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;
}