[gpu] Fix WebGPU demo gamma, colors, and UI

- Default to light mode matching GL demo
- Gamma cycles between 2.2 and none (no sRGB framebuffer)
- Gamma depends on dark_mode (1/2.2 for dark, 2.2 for light)
- Add console logging for key presses
- Blur backend dropdown after selection to prevent space capture

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-03-29 15:03:33 -06:00
1 parent dbbcca47b0
commit a3dedf59b9
2 files changed
+15 -5

No files matched your search

+14 -5
View File
@@ -200,7 +200,7 @@ static int canvas_w, canvas_h;
static int css_w, css_h;
static bool needs_redraw = true;
static bool dark_mode = false;
static float gamma_val = 1.0f;
static int gamma_mode = 0; /* 0=2.2, 1=none */
static bool animate = false;
/* View state */
@@ -212,6 +212,14 @@ static float quat[4];
static float rot_axis[3] = {0, 0, 1};
static double rot_speed = 1.0;
static float
compute_gamma ()
{
if (gamma_mode == 0)
return dark_mode ? 1.f / 2.2f : 2.2f;
return 1.f; /* none */
}
static bool dragging = false;
static bool right_dragging = false;
static double last_mouse_x, last_mouse_y;
@@ -296,7 +304,7 @@ render_frame ()
compute_mvp (u.mvp);
u.viewport[0] = (float) canvas_w;
u.viewport[1] = (float) canvas_h;
u.gamma = gamma_val;
u.gamma = compute_gamma ();
u._pad = 0;
if (dark_mode)
{
@@ -467,13 +475,14 @@ on_keydown (int type, const EmscriptenKeyboardEvent *e, void *ud)
if (strcmp (e->key, "b") == 0)
{
dark_mode = !dark_mode;
printf ("Dark mode: %s\n", dark_mode ? "on" : "off");
needs_redraw = true;
}
else if (strcmp (e->key, "g") == 0)
{
if (gamma_val == 1.0f) gamma_val = 1.8f;
else if (gamma_val == 1.8f) gamma_val = 0.6f;
else gamma_val = 1.0f;
gamma_mode = (gamma_mode + 1) % 2;
const char *names[] = {"gamma 2.2", "none"};
printf ("Gamma correction: %s\n", names[gamma_mode]);
needs_redraw = true;
}
else if (strcmp (e->key, "r") == 0)
+1
View File
@@ -99,6 +99,7 @@ space: animate · b: dark mode · g: gamma · r: reset · =/-: zoom</span>
if (location.pathname.indexOf('webgpu') !== -1)
backendSel.value = 'webgpu.html';
backendSel.addEventListener('change', function () {
backendSel.blur();
location.href = backendSel.value;
});