From 0d71ebccc8768fd92155066fdd1331321a7ac545 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 27 Oct 2019 00:02:01 +1000 Subject: [PATCH] Frontend: Add display linear filtering option --- src/core/settings.h | 1 + src/duckstation/sdl_interface.cpp | 17 +++++++++++++++++ src/duckstation/sdl_interface.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/core/settings.h b/src/core/settings.h index e45315ccd..baab818f7 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -15,6 +15,7 @@ struct Settings u32 gpu_resolution_scale = 1; u32 max_gpu_resolution_scale = 1; bool gpu_vsync = true; + bool display_linear_filtering = true; struct DebugSettings { diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index 962348ef6..d1223353f 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -187,6 +187,14 @@ void main() m_app_icon_texture = std::make_unique(APP_ICON_WIDTH, APP_ICON_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, APP_ICON_DATA, true); + // samplers + glGenSamplers(1, &m_display_nearest_sampler); + glSamplerParameteri(m_display_nearest_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(m_display_nearest_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glGenSamplers(1, &m_display_linear_sampler); + glSamplerParameteri(m_display_linear_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(m_display_linear_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + return true; } @@ -684,6 +692,7 @@ void SDLInterface::RenderDisplay() // - 20 for main menu padding const auto [vp_left, vp_top, vp_width, vp_height] = CalculateDrawRect(m_window_width, std::max(m_window_height - 20, 1), m_display_aspect_ratio); + const bool linear_filter = m_system ? m_system->GetSettings().display_linear_filtering : false; glViewport(vp_left, m_window_height - (20 + vp_top) - vp_height, vp_width, vp_height); glDisable(GL_BLEND); @@ -698,8 +707,10 @@ void SDLInterface::RenderDisplay() static_cast(m_display_texture_width) / static_cast(m_display_texture->GetWidth()), static_cast(m_display_texture_height) / static_cast(m_display_texture->GetHeight())); m_display_texture->Bind(); + glBindSampler(0, linear_filter ? m_display_linear_sampler : m_display_nearest_sampler); glBindVertexArray(m_display_vao); glDrawArrays(GL_TRIANGLES, 0, 3); + glBindSampler(0, 0); } void SDLInterface::DrawImGui() @@ -820,6 +831,12 @@ void SDLInterface::DrawMainMenuBar() if (ImGui::MenuItem("VSync", nullptr, &m_system->GetSettings().gpu_vsync)) UpdateAudioVisualSync(); + if (ImGui::MenuItem("Display Linear Filtering", nullptr, &m_system->GetSettings().display_linear_filtering)) + { + // this has to update the display texture for now.. + m_system->GetGPU()->UpdateResolutionScale(); + } + ImGui::EndMenu(); } diff --git a/src/duckstation/sdl_interface.h b/src/duckstation/sdl_interface.h index a5fb98b44..96448ab09 100644 --- a/src/duckstation/sdl_interface.h +++ b/src/duckstation/sdl_interface.h @@ -101,6 +101,8 @@ private: u32 m_display_texture_height = 0; float m_display_aspect_ratio = 1.0f; bool m_display_texture_changed = false; + GLuint m_display_nearest_sampler = false; + GLuint m_display_linear_sampler = false; std::deque m_osd_messages; std::mutex m_osd_messages_lock;