From f98dcc45225fa78341aba06137b05b9b6b89cb12 Mon Sep 17 00:00:00 2001 From: rodri Date: Thu, 29 Aug 2024 18:19:15 +0000 Subject: implement a general raster interface for the framebuffers. got a bit tired of having to add a ulong *buf every time i needed to get some data out of the shaders, so i made it possible to create as many extra buffers as needed, which then can be addressed from the fragment shader and drawn using the same drawing routines that were used for the color buffer. these so called Rasters are very similar to the OpenGL FBOs, in case you are familiar, but we address them by strings instead of numbers. and they can also be used as textures if you create one (see alloctexture) and then memdraw into it after every shot. --- viewport.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'viewport.c') diff --git a/viewport.c b/viewport.c index 5214e53..02987e2 100644 --- a/viewport.c +++ b/viewport.c @@ -9,7 +9,7 @@ #include "internal.h" static void -viewport_draw(Viewport *v, Image *dst) +viewport_draw(Viewport *v, Image *dst, char *rname) { Point off, scale; @@ -18,11 +18,11 @@ viewport_draw(Viewport *v, Image *dst) scale.x = max(v->bx.x, 1); scale.y = max(v->by.y, 1); - v->fbctl->draw(v->fbctl, dst, off, scale); + v->fbctl->draw(v->fbctl, dst, rname, off, scale); } static void -viewport_memdraw(Viewport *v, Memimage *dst) +viewport_memdraw(Viewport *v, Memimage *dst, char *rname) { Point off, scale; @@ -31,7 +31,7 @@ viewport_memdraw(Viewport *v, Memimage *dst) scale.x = max(v->bx.x, 1); scale.y = max(v->by.y, 1); - v->fbctl->memdraw(v->fbctl, dst, off, scale); + v->fbctl->memdraw(v->fbctl, dst, rname, off, scale); } static void @@ -67,6 +67,18 @@ viewport_getheight(Viewport *v) return Dy(v->r)*v->by.y; } +static void +viewport_createraster(Viewport *v, char *name, ulong chan) +{ + v->fbctl->createraster(v->fbctl, name, chan); +} + +static Raster * +viewport_fetchraster(Viewport *v, char *name) +{ + return v->fbctl->fetchraster(v->fbctl, name); +} + Viewport * mkviewport(Rectangle r) { @@ -90,6 +102,8 @@ mkviewport(Rectangle r) v->getfb = viewport_getfb; v->getwidth = viewport_getwidth; v->getheight = viewport_getheight; + v->createraster = viewport_createraster; + v->fetchraster = viewport_fetchraster; return v; } -- cgit v1.2.3