diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/submit/submit.c | 77 | ||||
-rw-r--r-- | src/rototiller.c | 2 |
2 files changed, 59 insertions, 20 deletions
diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c index 1d0fea1..3fc2ddd 100644 --- a/src/modules/submit/submit.c +++ b/src/modules/submit/submit.c @@ -22,6 +22,7 @@ #include "fb.h" #include "rototiller.h" +#include "settings.h" #include "util.h" #include "grid/grid.h" @@ -56,6 +57,9 @@ typedef struct submit_context_t { } submit_context_t; +static int bilerp_setting; + + /* convert a color into a packed, 32-bit rgb pixel value (taken from libs/ray/ray_color.h) */ static inline uint32_t color_to_uint32(color_t color) { uint32_t pixel; @@ -181,7 +185,24 @@ static inline uint32_t sample_grid(submit_context_t *ctxt, float x, float y) } -static void draw_grid(submit_context_t *ctxt, fb_fragment_t *fragment, uint32_t (*sampler)(submit_context_t *ctxt, float x, float y)) +static void draw_grid(submit_context_t *ctxt, fb_fragment_t *fragment) +{ + float xscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_width; + float yscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_height; + + for (int y = 0; y < fragment->height; y++) { + for (int x = 0; x < fragment->width; x++) { + uint32_t color; + + /* TODO: this could be optimized a bit! i.e. don't recompute the y for every x etc. */ + color = sample_grid(ctxt, .5f + ((float)(fragment->x + x)) * xscale, .5f + ((float)(fragment->y + y)) * yscale); + fb_fragment_put_pixel_unchecked(fragment, fragment->x + x, fragment->y + y, color); + } + } +} + + +static void draw_grid_bilerp(submit_context_t *ctxt, fb_fragment_t *fragment) { float xscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_width; float yscale = ((float)GRID_SIZE - 1.f) / (float)fragment->frame_height; @@ -191,7 +212,7 @@ static void draw_grid(submit_context_t *ctxt, fb_fragment_t *fragment, uint32_t uint32_t color; /* TODO: this could be optimized a bit! i.e. don't recompute the y for every x etc. */ - color = sampler(ctxt, .5f + ((float)(fragment->x + x)) * xscale, .5f + ((float)(fragment->y + y)) * yscale); + color = sample_grid_bilerp(ctxt, .5f + ((float)(fragment->x + x)) * xscale, .5f + ((float)(fragment->y + y)) * yscale); fb_fragment_put_pixel_unchecked(fragment, fragment->x + x, fragment->y + y, color); } } @@ -294,15 +315,46 @@ static void submit_render_fragment(void *context, fb_fragment_t *fragment) { submit_context_t *ctxt = context; - draw_grid(ctxt, fragment, sample_grid); + if (!bilerp_setting) + draw_grid(ctxt, fragment); + else + draw_grid_bilerp(ctxt, fragment); } -static void submit_softly_render_fragment(void *context, fb_fragment_t *fragment) +static int submit_setup(const settings_t *settings, setting_desc_t **next_setting) { - submit_context_t *ctxt = context; + const char *bilerp; + + bilerp = settings_get_value(settings, "bilerp"); + if (!bilerp) { + const char *values[] = { + "off", + "on", + NULL + }; + int r; + + r = setting_desc_clone(&(setting_desc_t){ + .name = "Bilinear Interpolation of Cell Colors", + .key = "bilerp", + .regex = NULL, + .preferred = values[0], + .values = values, + .annotations = NULL + }, next_setting); + if (r < 0) + return r; + + return 1; + } + + if (!strcasecmp(bilerp, "on")) + bilerp_setting = 1; + else + bilerp_setting = 0; - draw_grid(ctxt, fragment, sample_grid_bilerp); + return 0; } @@ -315,16 +367,5 @@ rototiller_module_t submit_module = { .description = "Cellular automata conquest game sim (threaded (poorly))", .author = "Vito Caputo <vcaputo@pengaru.com>", .license = "GPLv3", -}; - - -rototiller_module_t submit_softly_module = { - .create_context = submit_create_context, - .destroy_context = submit_destroy_context, - .prepare_frame = submit_prepare_frame, - .render_fragment = submit_softly_render_fragment, - .name = "submit-softly", - .description = "Bilinearly interpolated version of submit (threaded (poorly))", - .author = "Vito Caputo <vcaputo@pengaru.com>", - .license = "GPLv3", + .setup = submit_setup, }; diff --git a/src/rototiller.c b/src/rototiller.c index 47a74cf..e638fb6 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -41,7 +41,6 @@ extern rototiller_module_t ray_module; extern rototiller_module_t sparkler_module; extern rototiller_module_t stars_module; extern rototiller_module_t submit_module; -extern rototiller_module_t submit_softly_module; static rototiller_module_t *modules[] = { &roto32_module, @@ -52,7 +51,6 @@ static rototiller_module_t *modules[] = { &plasma_module, &julia_module, &submit_module, - &submit_softly_module, &flui2d_module, &pixbounce_module, }; |