diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 5e84519f..f6042898 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -23,6 +23,9 @@ psxrecomp_add_runtime_target(psx-runtime # (docs/ENHANCEMENTS.md G1.10). Titles get their _pgxp the same way. if(BUILD_TESTING) + add_executable(video_texture_filter_test tests/test_video_texture_filter.c src/video_texture_filter.c) + target_include_directories(video_texture_filter_test PRIVATE include) + add_test(NAME video_texture_filter_test COMMAND video_texture_filter_test) add_executable(mod_netplay_test tests/test_mod_netplay.c src/mod_netplay.c src/netplay_state_digest.c src/crc32.c src/psx_sha256.c) target_include_directories(mod_netplay_test PRIVATE include) diff --git a/runtime/include/video_texture_filter.h b/runtime/include/video_texture_filter.h new file mode 100644 index 00000000..885b3413 --- /dev/null +++ b/runtime/include/video_texture_filter.h @@ -0,0 +1,23 @@ +/* video_texture_filter.h - the one texture-filter enum for settings.toml, + * the launcher handoff and live apply. */ +#ifndef PSX_VIDEO_TEXTURE_FILTER_H +#define PSX_VIDEO_TEXTURE_FILTER_H +#ifdef __cplusplus +extern "C" { +#endif + +/* 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 value to the enum: in-range values pass through (xBR included), + * anything else is nearest, the native default. Older launchers send 0/1. */ +int psx_texture_filter_from_ui(int value); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index fb0b1988..af0abbde 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -432,6 +432,7 @@ set(PSXRECOMP_RUNTIME_SOURCES ${PSXRECOMP_ROOT}/runtime/src/bios_hle.c ${PSXRECOMP_ROOT}/runtime/src/bios_hle_plan.c ${PSXRECOMP_ROOT}/runtime/src/savestate.c + ${PSXRECOMP_ROOT}/runtime/src/video_texture_filter.c ${PSXRECOMP_ROOT}/runtime/src/psx_savestate_menu.c ${PSXRECOMP_ROOT}/runtime/src/psx_rewind.c ${PSXRECOMP_ROOT}/runtime/src/host_osd.c diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index cf33df28..de26182c 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -115,6 +115,7 @@ extern "C" void psx_event_step_conservative_env_init(void); #include "mod_local_input_policy.h" #include "mod_session_baseline.h" #include "mod_runtime.h" +#include "video_texture_filter.h" #include "host_launch_timing.h" #include "mod_packages.h" #include "present_image_ring.h" @@ -17929,10 +17930,10 @@ int main(int argc, char** argv) { } seed.has_aspect_ratio = true; /* has_texture_filter is on (PSX profile) so the launcher edits - * ls.texture_filter directly (0=nearest,1=bilinear); ls.linear_filter + * ls.texture_filter as the [video] enum (psx_texture_filter_from_ui: 0 nearest, 1 bilinear, 3 xBR); ls.linear_filter * is the legacy fallback field for consoles without the cap and is * left unused here. */ - seed.texture_filter = ls.texture_filter ? 1 : 0; seed.has_texture_filter = true; + seed.texture_filter = psx_texture_filter_from_ui(ls.texture_filter); seed.has_texture_filter = true; seed.fmv_filter = launcher_fmv_filter_to_cfg(ls.fmv_filter); seed.has_fmv_filter = true; { @@ -20545,7 +20546,7 @@ soft_return_lobby: #endif us.antialiasing = ls.antialiasing != 0; us.has_antialiasing = true; - us.texture_filter = ls.texture_filter; + us.texture_filter = psx_texture_filter_from_ui(ls.texture_filter); us.has_texture_filter = true; us.fmv_filter = launcher_fmv_filter_to_cfg(ls.fmv_filter); us.has_fmv_filter = true; @@ -20621,7 +20622,7 @@ soft_return_lobby: g_video_internal_res = ir.preset; g_video_scale = ir.scale; g_video_aa = ls.antialiasing; - g_video_texfilter = ls.texture_filter; + g_video_texfilter = psx_texture_filter_from_ui(ls.texture_filter); g_video_fmv_filter = launcher_fmv_filter_to_cfg(ls.fmv_filter); g_video_geometry_correction = ls.geometry_correction ? 1 : 0; g_video_perspective_texturing = ls.perspective_texturing ? 1 : 0; diff --git a/runtime/src/video_texture_filter.c b/runtime/src/video_texture_filter.c new file mode 100644 index 00000000..026cf7d6 --- /dev/null +++ b/runtime/src/video_texture_filter.c @@ -0,0 +1,7 @@ +/* video_texture_filter.c - see video_texture_filter.h. */ +#include "video_texture_filter.h" + +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/tests/test_video_texture_filter.c b/runtime/tests/test_video_texture_filter.c new file mode 100644 index 00000000..a38c9da3 --- /dev/null +++ b/runtime/tests/test_video_texture_filter.c @@ -0,0 +1,18 @@ +/* video_texture_filter_test: launcher texture-filter values to the enum. */ +#include "video_texture_filter.h" + +#include + +static int fails = 0; +#define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++fails; } } while (0) + +int main(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(2) == PSX_TEXTURE_FILTER_STABLE_WORLD); + CHECK(psx_texture_filter_from_ui(3) == PSX_TEXTURE_FILTER_XBR); /* was collapsed to bilinear */ + CHECK(psx_texture_filter_from_ui(9) == PSX_TEXTURE_FILTER_NEAREST); + CHECK(psx_texture_filter_from_ui(-1) == PSX_TEXTURE_FILTER_NEAREST); + if (!fails) printf("video_texture_filter_test: ok\n"); + return fails ? 1 : 0; +}