From 5bc97393aee4124b00db3ab4fbe8d6e26ba88069 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 14:07:49 +0100 Subject: Gamma: clamp slider to the engine's 2.6 cap, defer readback The engine clamps mat_monitorgamma at 2.6, so the 2.8..3.0 end of the slider did nothing. Read the value back one tick later (ClientCmd is queued) and interpose SDL_SetWindowGammaRamp to see whether the engine pushes a ramp at all. --- src/hl2h.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/hl2h.cpp') diff --git a/src/hl2h.cpp b/src/hl2h.cpp index f7106cd..1fc7096 100644 --- a/src/hl2h.cpp +++ b/src/hl2h.cpp @@ -674,13 +674,18 @@ static void view_settings_apply(void *ent) { last_vm = g_fov_viewmodel; } static int last_gamma = 22; + static int pending_gamma = -1; if (g_gamma != last_gamma) { char cmd[48]; snprintf(cmd, sizeof(cmd), "mat_monitorgamma %d.%d", g_gamma / 10, g_gamma % 10); console_cmd(cmd); - // Read back through ICvar to tell an ignored command from an OS gamma - // ramp that the compositor discards. + pending_gamma = g_gamma; + last_gamma = g_gamma; + } + if (pending_gamma >= 0) { + // ClientCmd is queued, so read the cvar on the next tick to see the value + // the engine actually accepted (it clamps mat_monitorgamma at 2.6). float got = -1.0f; if (g_iface.cvar) { using FindFn = void *(*)(void *, const char *); @@ -689,9 +694,9 @@ static void view_settings_apply(void *ent) { if (v) got = *(float *)((uintptr_t)v + 0x2c); // ConVar m_Value.f } - logf("view: gamma request %d.%d, cvar reports %.2f", g_gamma / 10, - g_gamma % 10, got); - last_gamma = g_gamma; + logf("view: gamma request %d.%d, cvar reports %.2f", pending_gamma / 10, + pending_gamma % 10, got); + pending_gamma = -1; } } -- cgit v1.2.3