From a7f0a18e6d4d951823c1074afd9e5780ff40aec4 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 28 Mar 2026 00:37:52 +0100 Subject: [PATCH] canvis de upscale i downscale en consola --- source/core/rendering/screen.cpp | 6 +++- source/core/rendering/shader_backend.hpp | 2 ++ source/game/defaults.hpp | 2 ++ source/game/options.cpp | 18 ++++++++++++ source/game/options.hpp | 8 +++-- source/game/ui/console.cpp | 37 ++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index cadc837..4d48208 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -536,12 +536,14 @@ auto loadData(const std::string& filepath) -> std::vector { } void Screen::setLinearUpscale(bool linear) { + Options::video.linear_upscale = linear; if (shader_backend_ && shader_backend_->isHardwareAccelerated()) { shader_backend_->setLinearUpscale(linear); } } void Screen::setDownscaleAlgo(int algo) { + Options::video.downscale_algo = algo; if (shader_backend_ && shader_backend_->isHardwareAccelerated()) { shader_backend_->setDownscaleAlgo(algo); } @@ -580,9 +582,11 @@ void Screen::initShaders() { shader_backend_->init(window_, tex, "", ""); gpu_driver_ = shader_backend_->getDriverName(); - // Propagar flags de vsync e integer scale al backend GPU + // Propagar flags de vsync, integer scale, upscale y downscale al backend GPU shader_backend_->setVSync(Options::video.vertical_sync); shader_backend_->setScaleMode(Options::video.integer_scale); + shader_backend_->setLinearUpscale(Options::video.linear_upscale); + shader_backend_->setDownscaleAlgo(Options::video.downscale_algo); if (Options::video.postfx) { applyCurrentPostFXPreset(); diff --git a/source/core/rendering/shader_backend.hpp b/source/core/rendering/shader_backend.hpp index 34ab0df..e6e33f5 100644 --- a/source/core/rendering/shader_backend.hpp +++ b/source/core/rendering/shader_backend.hpp @@ -95,6 +95,7 @@ namespace Rendering { * Por defecto NEAREST (false). Solo tiene efecto con supersampling activo. */ virtual void setLinearUpscale(bool /*linear*/) {} + [[nodiscard]] virtual auto isLinearUpscale() const -> bool { return false; } /** * @brief Selecciona el algoritmo de downscale tras el PostFX (SS activo). @@ -102,6 +103,7 @@ namespace Rendering { * 1 = Lanczos2 (ventana 2, ~25 muestras), 2 = Lanczos3 (ventana 3, ~49 muestras). */ virtual void setDownscaleAlgo(int /*algo*/) {} + [[nodiscard]] virtual auto getDownscaleAlgo() const -> int { return 0; } /** * @brief Verifica si el backend está usando aceleración por hardware diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index e0fc5ab..5964755 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -30,6 +30,8 @@ namespace Defaults::Video { constexpr bool INTEGER_SCALE = true; // Escalado entero activado por defecto constexpr bool KEEP_ASPECT = true; // Mantener aspecto activado por defecto constexpr const char* PALETTE_NAME = "zx-spectrum"; // Paleta por defecto + constexpr bool LINEAR_UPSCALE = false; // Upscale NEAREST por defecto + constexpr int DOWNSCALE_ALGO = 1; // Downscale Lanczos2 por defecto } // namespace Defaults::Video namespace Defaults::Border { diff --git a/source/game/options.cpp b/source/game/options.cpp index f4f5942..cdb098e 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -388,6 +388,22 @@ namespace Options { } } + if (vid.contains("linear_upscale")) { + try { + video.linear_upscale = vid["linear_upscale"].get_value(); + } catch (...) { + video.linear_upscale = Defaults::Video::LINEAR_UPSCALE; + } + } + + if (vid.contains("downscale_algo")) { + try { + video.downscale_algo = vid["downscale_algo"].get_value(); + } catch (...) { + video.downscale_algo = Defaults::Video::DOWNSCALE_ALGO; + } + } + loadPaletteFromYaml(vid); } @@ -644,6 +660,8 @@ namespace Options { file << " vertical_sync: " << (video.vertical_sync ? "true" : "false") << "\n"; file << " integer_scale: " << (video.integer_scale ? "true" : "false") << "\n"; file << " keep_aspect: " << (video.keep_aspect ? "true" : "false") << "\n"; + file << " linear_upscale: " << (video.linear_upscale ? "true" : "false") << "\n"; + file << " downscale_algo: " << video.downscale_algo << " # 0=bilinear, 1=Lanczos2, 2=Lanczos3\n"; file << " palette: " << video.palette << "\n"; file << " border:\n"; file << " enabled: " << (video.border.enabled ? "true" : "false") << "\n"; diff --git a/source/game/options.hpp b/source/game/options.hpp index ce6a48e..d28b7a4 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -84,9 +84,11 @@ namespace Options { bool supersampling{Defaults::Video::SUPERSAMPLING}; // Indica si el supersampling 3× está activo bool integer_scale{Defaults::Video::INTEGER_SCALE}; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa bool keep_aspect{Defaults::Video::KEEP_ASPECT}; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa - Border border{}; // Borde de la pantalla - std::string palette{Defaults::Video::PALETTE_NAME}; // Paleta de colores a usar en el juego - std::string info; // Información sobre el modo de vídeo + bool linear_upscale{Defaults::Video::LINEAR_UPSCALE}; // Upscale LINEAR (true) o NEAREST (false) + int downscale_algo{Defaults::Video::DOWNSCALE_ALGO}; // 0=bilinear, 1=Lanczos2, 2=Lanczos3 + Border border{}; // Borde de la pantalla + std::string palette{Defaults::Video::PALETTE_NAME}; // Paleta de colores a usar en el juego + std::string info; // Información sobre el modo de vídeo }; // Estructura para las opciones de musica diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index fcb7ccc..dcaad9a 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -69,6 +69,8 @@ static void printHelp() { SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)"); SDL_Log(" ZOOM [UP|DOWN] Window zoom (F1/F2)"); SDL_Log(" INTSCALE [ON|OFF] Integer scaling (F7)"); + SDL_Log(" UPSCALE [NEAREST|LINEAR] SS upscale filter (toggle if no arg)"); + SDL_Log(" DOWNSCALE [BILINEAR|LANCZOS2|LANCZOS3] SS downscale algorithm"); SDL_Log(" VSYNC [ON|OFF] Vertical sync"); SDL_Log(" PALETTE [NEXT|PREV] Color palette (F5/F6)"); #ifdef _DEBUG @@ -173,6 +175,41 @@ static const std::vector COMMANDS = { return std::string("IntScale ") + (Options::video.integer_scale ? "ON" : "OFF"); }}, + // UPSCALE [NEAREST|LINEAR] — Filtro de upscale en supersampling + {.keyword = "UPSCALE", .execute = [](const std::vector& args) -> std::string { + if (args.empty()) { + Screen::get()->setLinearUpscale(!Options::video.linear_upscale); + return std::string("Upscale: ") + (Options::video.linear_upscale ? "Linear" : "Nearest"); + } + if (args[0] == "NEAREST") { + if (!Options::video.linear_upscale) { return "Upscale already Nearest"; } + Screen::get()->setLinearUpscale(false); return "Upscale: Nearest"; + } + if (args[0] == "LINEAR") { + if (Options::video.linear_upscale) { return "Upscale already Linear"; } + Screen::get()->setLinearUpscale(true); return "Upscale: Linear"; + } + return "Usage: UPSCALE [NEAREST|LINEAR]"; + }}, + + // DOWNSCALE [BILINEAR|LANCZOS2|LANCZOS3] — Algoritmo de downscale en supersampling + {.keyword = "DOWNSCALE", .execute = [](const std::vector& args) -> std::string { + static const std::array NAMES = {"Bilinear", "Lanczos2", "Lanczos3"}; + if (args.empty()) { + return std::string("Downscale: ") + std::string(NAMES[static_cast(Options::video.downscale_algo)]); + } + int algo = -1; + if (args[0] == "BILINEAR") { algo = 0; } + if (args[0] == "LANCZOS2") { algo = 1; } + if (args[0] == "LANCZOS3") { algo = 2; } + if (algo == -1) { return "Usage: DOWNSCALE [BILINEAR|LANCZOS2|LANCZOS3]"; } + if (Options::video.downscale_algo == algo) { + return std::string("Downscale already ") + std::string(NAMES[static_cast(algo)]); + } + Screen::get()->setDownscaleAlgo(algo); + return std::string("Downscale: ") + std::string(NAMES[static_cast(algo)]); + }}, + // VSYNC [ON|OFF] — Sincronización vertical {.keyword = "VSYNC", .execute = BOOL_TOGGLE_CMD("VSync", Options::video.vertical_sync,