diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-04-30 10:46:31 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-05-02 10:36:27 -0700 |
commit | 80ed920eea46b8a7946bcbfca5d874e1a9b298aa (patch) | |
tree | 2897381f4dc10fb83b866276dd002e7896100cba /src | |
parent | c4ac389be39f9f70b3fda0b0070b5954d7c6978a (diff) |
modules/checkers: WIP experimenting with texturable settingscheckers-waves-textureable-setting
It seems like one could make good use of fine-grained dynamic
control of texturability
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/checkers/checkers.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c index 841aadd..a3c4957 100644 --- a/src/modules/checkers/checkers.c +++ b/src/modules/checkers/checkers.c @@ -28,6 +28,7 @@ #define CHECKERS_DEFAULT_DYNAMICS_RATE 1.0 #define CHECKERS_DEFAULT_SAMPLED 0 #define CHECKERS_DEFAULT_COLOR 0xffffffff +#define CHECKERS_DEFAULT_TEXTURABLE CHECKERS_TEXTURABLE_ON typedef enum checkers_pattern_t { @@ -43,6 +44,12 @@ typedef enum checkers_dynamics_t { CHECKERS_DYNAMICS_SONAR, } checkers_dynamics_t; +typedef enum checkers_texturable_t { + CHECKERS_TEXTURABLE_OFF, + CHECKERS_TEXTURABLE_ON, + CHECKERS_TEXTURABLE_RANDOM, +} checkers_texturable_t; + typedef struct checkers_setup_t { til_setup_t til_setup; unsigned size; @@ -50,6 +57,7 @@ typedef struct checkers_setup_t { checkers_dynamics_t dynamics; float rate; uint32_t color; + checkers_texturable_t texturable; unsigned sampled:1; } checkers_setup_t; @@ -66,6 +74,7 @@ static checkers_setup_t checkers_default_setup = { .rate = CHECKERS_DEFAULT_DYNAMICS_RATE, .sampled = CHECKERS_DEFAULT_SAMPLED, .color = CHECKERS_DEFAULT_COLOR, + .texturable = CHECKERS_DEFAULT_TEXTURABLE, }; @@ -173,11 +182,23 @@ static void checkers_render_fragment(void *context, unsigned ticks, unsigned cpu til_fb_fragment_clear(fragment); else { uint32_t color = ctxt->setup.color; + uint32_t flags; if (ctxt->setup.sampled && fragment->cleared) color = til_fb_fragment_get_pixel_unchecked(fragment, fragment->x + (fragment->width >> 1), fragment->y + (fragment->height >> 1)); - til_fb_fragment_fill(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, color); + switch (ctxt->setup.texturable) { + case CHECKERS_TEXTURABLE_OFF: + flags = 0; + break; + case CHECKERS_TEXTURABLE_ON: + flags = TIL_FB_DRAW_FLAG_TEXTURABLE; + break; + case CHECKERS_TEXTURABLE_RANDOM: + flags = TIL_FB_DRAW_FLAG_TEXTURABLE * (rand() % 2); + break; + } + til_fb_fragment_fill(fragment, flags, color); } } @@ -189,6 +210,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se const char *dynamics; const char *dynamics_rate; const char *sampled; + const char *texturable; const char *size_values[] = { "4", "8", @@ -227,6 +249,12 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se "on", NULL }; + const char *texturable_values[] = { + "off", + "on", + "random", + NULL + }; int r; r = til_settings_get_and_describe_value(settings, @@ -302,6 +330,20 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se if (r) return r; + r = til_settings_get_and_describe_value(settings, + &(til_setting_desc_t){ + .name = "Texturable filled checkers", + .key = "texturable", + .preferred = texturable_values[CHECKERS_DEFAULT_TEXTURABLE], + .values = texturable_values, + .annotations = NULL + }, + &texturable, + res_setting, + res_desc); + if (r) + return r; + if (res_setup) { checkers_setup_t *setup; @@ -353,6 +395,13 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se /* XXX FIXME TODO: color setting, parse web-style #rrggbb? */ setup->color = CHECKERS_DEFAULT_COLOR; + for (size_t i = 0; i < nelems(texturable_values); i++) { + if (!strcasecmp(texturable, texturable_values[i])) { + setup->texturable = i; + break; + } + } + *res_setup = &setup->til_setup; } |