From 1bf0d11c9eb2e44ce2acf773202957aad5bb1e97 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 9 Sep 2023 20:00:05 -0700 Subject: [PATCH] Fix regression: Linear filter persistence This fixes #1013 by axing the use of SDL_HINT_RENDER_SCALE_QUALITY and instead using SDL_SetTextureScaleMode. The hint is unwieldy to use, and since #923, has resulted in a regression where starting the game in filtered mode then switching to nearest results in scaled textures still being filtered. The proper solution is to use SDL_SetTextureScaleMode on the two textures that are drawn to the final screen: gameTexture and tempShakeTexture. --- desktop_version/src/Graphics.cpp | 10 +++++++++ desktop_version/src/Screen.cpp | 37 +++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 0bc960f9..015e4c43 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -194,6 +194,16 @@ void Graphics::create_buffers(void) #undef CREATE_SCROLL_TEXTURE #undef CREATE_TEXTURE #undef CREATE_TEXTURE_WITH_DIMENSIONS + + SDL_SetTextureScaleMode( + gameTexture, + gameScreen.isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest + ); + + SDL_SetTextureScaleMode( + tempShakeTexture, + gameScreen.isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest + ); } void Graphics::destroy_buffers(void) diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 52762ff2..9d9ca56a 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -39,11 +39,6 @@ void Screen::init(const struct ScreenSettings* settings) badSignalEffect = settings->badSignal; vsync = settings->useVsync; - SDL_SetHintWithPriority( - SDL_HINT_RENDER_SCALE_QUALITY, - isFiltered ? "linear" : "nearest", - SDL_HINT_OVERRIDE - ); SDL_SetHintWithPriority( SDL_HINT_RENDER_VSYNC, vsync ? "1" : "0", @@ -313,12 +308,10 @@ void Screen::toggleScalingMode(void) void Screen::toggleLinearFilter(void) { isFiltered = !isFiltered; - SDL_SetHintWithPriority( - SDL_HINT_RENDER_SCALE_QUALITY, - isFiltered ? "linear" : "nearest", - SDL_HINT_OVERRIDE - ); + SDL_DestroyTexture(graphics.gameTexture); + SDL_DestroyTexture(graphics.tempShakeTexture); + graphics.gameTexture = SDL_CreateTexture( m_renderer, SDL_PIXELFORMAT_ARGB8888, @@ -327,11 +320,35 @@ void Screen::toggleLinearFilter(void) SCREEN_HEIGHT_PIXELS ); + graphics.tempShakeTexture = SDL_CreateTexture( + m_renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_TARGET, + SCREEN_WIDTH_PIXELS, + SCREEN_HEIGHT_PIXELS + ); + if (graphics.gameTexture == NULL) { vlog_error("Could not create game texture: %s", SDL_GetError()); return; } + + if (graphics.tempShakeTexture == NULL) + { + vlog_error("Could not create temp shake texture: %s", SDL_GetError()); + return; + } + + SDL_SetTextureScaleMode( + graphics.gameTexture, + isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest + ); + + SDL_SetTextureScaleMode( + graphics.tempShakeTexture, + isFiltered ? SDL_ScaleModeLinear : SDL_ScaleModeNearest + ); } void Screen::toggleVSync(void)