diff --git a/runtime/include/host_overlay.h b/runtime/include/host_overlay.h index 2cfc9ba4..49e956b2 100644 --- a/runtime/include/host_overlay.h +++ b/runtime/include/host_overlay.h @@ -65,7 +65,7 @@ int psx_host_ui_capture_active(void); * thread only. */ typedef struct PsxHostVideoSettings { int fullscreen; /* 0 windowed, 1 borderless, 2 exclusive */ - int texture_filter; /* 0 nearest, 1 bilinear */ + int texture_filter; /* PSX_TEXTURE_FILTER_* (the [video] enum) */ int fmv_filter; /* VIDEO_FMV_FILTER_* (config value) */ int scanlines; /* 0/1 */ int scanline_strength_pct; /* 0..100 */ @@ -79,6 +79,18 @@ typedef struct PsxHostVideoSettings { int present_thread; /* restart */ } PsxHostVideoSettings; +/* Texture filter: ONE enum for settings.toml, the launcher handoff and the + * in-game menu, so they cannot drift apart (#586 added xBR; a boolean UI + * cannot represent it). Values match [video] texture_filtering and + * gr_set_texture_filter(). STABLE_WORLD is set by mods, not by settings. */ +#define PSX_TEXTURE_FILTER_NEAREST 0 +#define PSX_TEXTURE_FILTER_BILINEAR 1 +#define PSX_TEXTURE_FILTER_STABLE_WORLD 2 +#define PSX_TEXTURE_FILTER_XBR 3 +/* A launcher / menu value to the enum: in-range values pass through, and + * anything else is nearest (the native default). Older launchers send 0/1. */ +int psx_texture_filter_from_ui(int value); + #define PSX_VIDEO_RESTART_RENDERER (1u << 0) #define PSX_VIDEO_RESTART_RESOLUTION (1u << 1) #define PSX_VIDEO_RESTART_THREADS (1u << 2) diff --git a/runtime/src/host_overlay.c b/runtime/src/host_overlay.c index 12410352..ad122a9d 100644 --- a/runtime/src/host_overlay.c +++ b/runtime/src/host_overlay.c @@ -147,3 +147,8 @@ unsigned psx_host_video_restart_bits(const PsxHostVideoSettings *boot, m |= PSX_VIDEO_RESTART_THREADS; return m; } + +int psx_texture_filter_from_ui(int value) { + return (value >= PSX_TEXTURE_FILTER_NEAREST && value <= PSX_TEXTURE_FILTER_XBR) + ? value : PSX_TEXTURE_FILTER_NEAREST; +} diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 6141204a..086fb3ab 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -9753,7 +9753,7 @@ extern "C" unsigned psx_video_apply_live(const PsxHostVideoSettings *next) { if (m & PSX_VIDEO_LIVE_FULLSCREEN) (void)psx_window_fullscreen_set(sdl_window, &s_window_fullscreen, next->fullscreen); if (m & PSX_VIDEO_LIVE_TEXTURE_FILTER) { - g_video_texfilter = next->texture_filter ? 1 : 0; + g_video_texfilter = psx_texture_filter_from_ui(next->texture_filter); if (g_mod_texfilter < 0) gr_set_texture_filter(g_video_texfilter); } if (m & PSX_VIDEO_LIVE_FMV_FILTER) { diff --git a/runtime/tests/test_host_overlay.c b/runtime/tests/test_host_overlay.c index 15ffc75c..53601398 100644 --- a/runtime/tests/test_host_overlay.c +++ b/runtime/tests/test_host_overlay.c @@ -146,10 +146,20 @@ static void test_video(void) { CHECK(psx_host_video_live_changes(NULL, &b) == 0 && psx_host_video_restart_bits(&a, NULL) == 0); } +/* One texture-filter enum for settings, handoff and menu (xBR included). */ +static void test_texture_filter(void) { + CHECK(psx_texture_filter_from_ui(0) == PSX_TEXTURE_FILTER_NEAREST); + CHECK(psx_texture_filter_from_ui(1) == PSX_TEXTURE_FILTER_BILINEAR); + CHECK(psx_texture_filter_from_ui(3) == PSX_TEXTURE_FILTER_XBR); + CHECK(psx_texture_filter_from_ui(9) == PSX_TEXTURE_FILTER_NEAREST); + CHECK(psx_texture_filter_from_ui(-1) == PSX_TEXTURE_FILTER_NEAREST); +} + int main(void) { test_draw_lifetime(); test_draw_reentrant(); test_video(); + test_texture_filter(); test_sink(); test_draw(); test_pause();