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/gui.cpp | 27 +++++++++++++++++++++++++-- src/hl2h.cpp | 15 ++++++++++----- src/menu.cpp | 2 +- 3 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui.cpp b/src/gui.cpp index 88e5521..e8bcac7 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -419,8 +419,9 @@ static void build_cards() { "Weapon model field of view (20-120; stock 54).", 20, 120, &g_fov_viewmodel); add_slider(view, "Gamma x10", - "mat_monitorgamma x10: 16 = 1.6, 30 = 3.0, stock is 22.", 16, 30, - &g_gamma); + "mat_monitorgamma x10: 16 = 1.6, 26 = 2.6 (engine max), stock " + "is 22.", + 16, 26, &g_gamma); add_card(2, &g_fullbright, "Fullbright", "Ignore world lighting so dark areas are visible.", true); @@ -2240,6 +2241,28 @@ SDL_WarpMouseGlobal(int x, int y) { real_warp_global(x, y); } +// Diagnostic: tell whether mat_monitorgamma reaches the SDL gamma ramp at all. +static int (*real_set_gamma_ramp)(void *, const unsigned short *, + const unsigned short *, + const unsigned short *) = nullptr; + +extern "C" __attribute__((visibility("default"))) int +SDL_SetWindowGammaRamp(void *window, const unsigned short *r, + const unsigned short *g, const unsigned short *b) { + if (!real_set_gamma_ramp) + real_set_gamma_ramp = (int (*)(void *, const unsigned short *, + const unsigned short *, + const unsigned short *))dlsym( + RTLD_NEXT, "SDL_SetWindowGammaRamp"); + static int logs = 0; + if (logs < 12) { + logs++; + logf("gamma: SDL_SetWindowGammaRamp mid=%u/%u/%u", r ? r[128] : 0, + g ? g[128] : 0, b ? b[128] : 0); + } + return real_set_gamma_ramp ? real_set_gamma_ramp(window, r, g, b) : -1; +} + static unsigned int (*real_get_rel_mouse)(int *, int *) = nullptr; static int (*real_poll_event)(void *) = nullptr; 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; } } diff --git a/src/menu.cpp b/src/menu.cpp index ead5f2d..248aa48 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -407,7 +407,7 @@ static bool config_load() { } else if (strcmp(key, "gamma") == 0) { dst = &g_gamma; lo = 16; - hi = 30; + hi = 26; // the engine clamps mat_monitorgamma at 2.6 stock = 22; } if (dst) { -- cgit v1.2.3