From a4a35b7e5879987169d288b76323d775af7e22d2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 12 May 2024 15:32:21 +1000 Subject: [PATCH] GPU: Add Bilinear (Integer) scaling option --- src/core/gpu.cpp | 11 +++++++---- src/core/settings.cpp | 6 ++++-- src/core/types.h | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 4e09fb8d8..be09e322f 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -1987,6 +1987,7 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle& draw_r break; case DisplayScalingMode::BilinearSmooth: + case DisplayScalingMode::BlinearInteger: texture_filter_linear = true; break; @@ -2297,6 +2298,8 @@ Common::Rectangle GPU::CalculateDrawRect(s32 window_width, s32 window_hei float* out_top_padding, float* out_scale, float* out_x_scale, bool apply_aspect_ratio /* = true */) const { + const bool integer_scale = (g_settings.display_scaling == DisplayScalingMode::NearestInteger || + g_settings.display_scaling == DisplayScalingMode::BlinearInteger); const float window_ratio = static_cast(window_width) / static_cast(window_height); const float x_scale = apply_aspect_ratio ? @@ -2325,12 +2328,12 @@ Common::Rectangle GPU::CalculateDrawRect(s32 window_width, s32 window_hei { // align in middle vertically scale = static_cast(window_width) / display_width; - if (g_settings.display_scaling == DisplayScalingMode::NearestInteger) + if (integer_scale) scale = std::max(std::floor(scale), 1.0f); if (out_left_padding) { - if (g_settings.display_scaling == DisplayScalingMode::NearestInteger) + if (integer_scale) *out_left_padding = std::max((static_cast(window_width) - display_width * scale) / 2.0f, 0.0f); else *out_left_padding = 0.0f; @@ -2359,7 +2362,7 @@ Common::Rectangle GPU::CalculateDrawRect(s32 window_width, s32 window_hei { // align in middle horizontally scale = static_cast(window_height) / display_height; - if (g_settings.display_scaling == DisplayScalingMode::NearestInteger) + if (integer_scale) scale = std::max(std::floor(scale), 1.0f); if (out_left_padding) @@ -2384,7 +2387,7 @@ Common::Rectangle GPU::CalculateDrawRect(s32 window_width, s32 window_hei if (out_top_padding) { - if (g_settings.display_scaling == DisplayScalingMode::NearestInteger) + if (integer_scale) *out_top_padding = std::max((static_cast(window_height) - (display_height * scale)) / 2.0f, 0.0f); else *out_top_padding = 0.0f; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index b98013082..5398c5daa 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -1417,15 +1417,17 @@ const char* Settings::GetDisplayAlignmentDisplayName(DisplayAlignment alignment) static constexpr const std::array s_display_scaling_names = { "Nearest", - "BilinearSmooth", "NearestInteger", + "BilinearSmooth", "BilinearSharp", + "BilinearInteger", }; static constexpr const std::array s_display_scaling_display_names = { TRANSLATE_NOOP("DisplayScalingMode", "Nearest-Neighbor"), - TRANSLATE_NOOP("DisplayScalingMode", "Bilinear (Smooth)"), TRANSLATE_NOOP("DisplayScalingMode", "Nearest-Neighbor (Integer)"), + TRANSLATE_NOOP("DisplayScalingMode", "Bilinear (Smooth)"), TRANSLATE_NOOP("DisplayScalingMode", "Bilinear (Sharp)"), + TRANSLATE_NOOP("DisplayScalingMode", "Bilinear (Integer)"), }; std::optional Settings::ParseDisplayScaling(const char* str) diff --git a/src/core/types.h b/src/core/types.h index 1227afbd6..108db954f 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -155,9 +155,10 @@ enum class DisplayAlignment : u8 enum class DisplayScalingMode : u8 { Nearest, - BilinearSmooth, NearestInteger, + BilinearSmooth, BilinearSharp, + BlinearInteger, Count };