From 49750572eeea8c8290e9b4baf749e80b23bc7cc5 Mon Sep 17 00:00:00 2001 From: MaikelChan Date: Sun, 24 Oct 2021 20:18:16 +0200 Subject: [PATCH] Change texture filtering without restarting. --- SpaceCadetPinball/options.cpp | 3 ++- SpaceCadetPinball/render.cpp | 31 ++++++++++++++++++++----------- SpaceCadetPinball/render.h | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 5dd9d5d..d78850a 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -3,6 +3,7 @@ #include "fullscrn.h" #include "midi.h" +#include "render.h" #include "Sound.h" #include "winmain.h" @@ -246,7 +247,7 @@ void options::toggle(Menu1 uIDCheckItem) break; case Menu1::WindowLinearFilter: Options.LinearFiltering ^= true; - winmain::Restart(); + render::recreate_screen_texture(); break; default: break; diff --git a/SpaceCadetPinball/render.cpp b/SpaceCadetPinball/render.cpp index ed4d05a..ee0cc5b 100644 --- a/SpaceCadetPinball/render.cpp +++ b/SpaceCadetPinball/render.cpp @@ -42,17 +42,7 @@ void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int h else gdrv::fill_bitmap(vscreen, vscreen->Width, vscreen->Height, 0, 0, 0); - { - UsingSdlHint hint{SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest"}; - vScreenTex = SDL_CreateTexture - ( - winmain::Renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, - width, height - ); - SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE); - } + recreate_screen_texture(); } void render::uninit() @@ -69,6 +59,25 @@ void render::uninit() dirty_list.clear(); sprite_list.clear(); SDL_DestroyTexture(vScreenTex); + vScreenTex = nullptr; +} + +void render::recreate_screen_texture() +{ + if (vScreenTex != nullptr) + { + SDL_DestroyTexture(vScreenTex); + } + + UsingSdlHint hint{ SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest" }; + vScreenTex = SDL_CreateTexture + ( + winmain::Renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + vscreen_rect.Width, vscreen_rect.Height + ); + SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE); } void render::update() diff --git a/SpaceCadetPinball/render.h b/SpaceCadetPinball/render.h index ba794f4..5e66ade 100644 --- a/SpaceCadetPinball/render.h +++ b/SpaceCadetPinball/render.h @@ -35,6 +35,7 @@ public: static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height); static void uninit(); + static void recreate_screen_texture(); static void update(); static void sprite_modified(render_sprite_type_struct* sprite); static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,