summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-14 15:16:41 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-14 15:16:41 (GMT)
commitbd851663c9e901c34a33eb9f725a5d6b1f7dee4a (patch)
tree94e682580c517375d8f6c9788c349d46ff7237a1 /meme/gui.c
parent57e0603cd3cf68f8adaefb32eec7efd17c43f99b (diff)
downloadmisc-bd851663c9e901c34a33eb9f725a5d6b1f7dee4a.zip
misc-bd851663c9e901c34a33eb9f725a5d6b1f7dee4a.tar.gz
misc-bd851663c9e901c34a33eb9f725a5d6b1f7dee4a.tar.bz2
meme/gui.c (surface_draw): pre-compute depth gradient
The run-time saving seems negligible but this also allows us to use more expensive mapping functions.
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 8298970..c6c8b4a 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -146,6 +146,29 @@ static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y)
}
+/* ----- Depth gradient ---------------------------------------------------- */
+
+
+static Uint32 *z_grad;
+
+
+static void setup_z_grad(void)
+{
+ int i;
+ int div;
+ uint8_t col;
+
+ if (z_grad)
+ return;
+ z_grad = calloc(3*(z_max-z_min)+1, sizeof(Uint32));
+ div = 3*(z_max-z_min);
+ for (i = 0; i <= 3*(z_max-z_min); i++) {
+ col = i*DEPTH_RANGE/div + DEPTH_OFFSET;
+ z_grad[i] = col * 0x1010100 + 0xff;
+ }
+}
+
+
/* ----- Draw the mesh ----------------------------------------------------- */
@@ -154,9 +177,9 @@ static void surface_draw(SDL_Surface *s)
const struct facet *f;
Sint16 xa, ya, xb, yb, xc, yc;
int a, b, c;
- int z3;
- uint8_t col;
-
+ int z_off = z_min*3;
+
+ setup_z_grad();
for (f = facets; f; f = f->next) {
a = coord(f->v[0]->x, f->v[0]->y, &xa, &ya);
if (a < 0)
@@ -170,11 +193,8 @@ static void surface_draw(SDL_Surface *s)
if (!(a || b || c))
continue;
- z3 = f->v[0]->z + f->v[1]->z + f->v[2]->z - z_min*3;
- col = z3*DEPTH_RANGE/3/(z_max-z_min) + DEPTH_OFFSET;
-
filledTrigonColor(s, xa, ya, xb, yb, xc, yc,
- col * 0x1010100 + 0xff);
+ z_grad[f->v[0]->z + f->v[1]->z + f->v[2]->z - z_off]);
}
}