summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-16 19:23:58 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-16 19:23:58 -0700
commitdeb98475a01a5e62d39109e9b703b567612260da (patch)
tree3a97fad07c293f61888eed5d79158ef8af3b83bb
parentc67cbbba4b6d5073ae7b3050b0e0f96b3ce8ba84 (diff)
modules/moire: some simple optimizations
Major gain comes from eliminating the cosf() from the inner loop... There's still a bunch left on the table for moire but even just these changes turn 19FPS into 81FPS over here for: '--module=compose,layers=moire\\\,centers\\\=2\,moire\\\,centers\\\=2\,moire\\\,centers\\\=2\,moire\\\,centers\\\=2,texture=none' '--video=mem,size=1366x768'
-rw-r--r--src/modules/moire/moire.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c
index f8907af..973fbee 100644
--- a/src/modules/moire/moire.c
+++ b/src/modules/moire/moire.c
@@ -81,32 +81,34 @@ static void moire_render_fragment(til_module_context_t *context, til_stream_t *s
moire_context_t *ctxt = (moire_context_t *)context;
til_fb_fragment_t *fragment = *fragment_ptr;
- float xf = 2.f / (float)fragment->frame_width;
- float yf = 2.f / (float)fragment->frame_height;
- float cx, cy;
+ float xf = 2.f / (float)fragment->frame_width;
+ float yf = 2.f / (float)fragment->frame_height;
+ unsigned n_centers = ctxt->setup->n_centers;
+ moire_center_t *centers = ctxt->centers;
+ float cx, cy;
/* TODO: optimize */
cy = yf * (float)fragment->y - 1.f;
- for (int y = fragment->y; y < fragment->y + fragment->height; y++, cy += yf) {
+ for (int y = 0; y < fragment->height; y++, cy += yf) {
cx = xf * (float)fragment->x - 1.f;
- for (int x = fragment->x; x < fragment->x + fragment->width; x++, cx += xf) {
- int filled = 0;
+ for (int x = 0; x < fragment->width; x++, cx += xf) {
+ unsigned char filled = 0;
- for (unsigned i = 0; i < ctxt->setup->n_centers; i++) {
+ for (unsigned i = 0; i < n_centers; i++) {
float dx, dy;
- dx = cx - ctxt->centers[i].x;
- dy = cy - ctxt->centers[i].y;
+ dx = cx - centers[i].x;
+ dy = cy - centers[i].y;
- if (cosf(sqrtf(dx * dx + dy * dy) * 50.f) < 0.f)
+ if ((int)((sqrtf(dx * dx + dy * dy)) * 20.f) % 2)
filled ^= 1;
}
if (filled)
- til_fb_fragment_put_pixel_unchecked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, 0xffffffff);
+ til_fb_fragment_put_pixel_unchecked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, fragment->x + x, fragment->y + y, 0xffffffff);
else if (!fragment->cleared)
- til_fb_fragment_put_pixel_unchecked(fragment, 0, x, y, 0x00000000);
+ til_fb_fragment_put_pixel_unchecked(fragment, 0, fragment->x + x, fragment->y + y, 0x00000000);
}
}
}
© All Rights Reserved