From 71c7b8e553d404f80f632f0c01ed09571d6ff6d2 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 28 Mar 2026 14:14:33 +0100 Subject: [PATCH] mes comandos per a Console --- source/core/rendering/screen.cpp | 5 ++++ source/core/rendering/screen.hpp | 2 ++ .../core/rendering/sdl3gpu/sdl3gpu_shader.cpp | 5 ++++ .../core/rendering/sdl3gpu/sdl3gpu_shader.hpp | 3 ++ source/core/rendering/shader_backend.hpp | 7 +++++ source/game/ui/console.cpp | 28 +++++++++++++++++-- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index 1983e3d..6e65f26 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -529,6 +529,11 @@ void Screen::setDownscaleAlgo(int algo) { } } +auto Screen::getSsTextureSize() const -> std::pair { + if (!shader_backend_) { return {0, 0}; } + return shader_backend_->getSsTextureSize(); +} + // Activa/desactiva el supersampling global (Ctrl+F4) void Screen::toggleSupersampling() { Options::video.supersampling = !Options::video.supersampling; diff --git a/source/core/rendering/screen.hpp b/source/core/rendering/screen.hpp index 30f08fd..72b1e06 100644 --- a/source/core/rendering/screen.hpp +++ b/source/core/rendering/screen.hpp @@ -6,6 +6,7 @@ #include // Para size_t #include // Para shared_ptr, __shared_ptr_access #include // Para string +#include // Para std::pair #include // Para vector #include "utils/utils.hpp" // Para Color @@ -77,6 +78,7 @@ class Screen { [[nodiscard]] auto getGPUDriver() const -> const std::string& { return gpu_driver_; } [[nodiscard]] auto getLastFPS() const -> int { return fps_.last_value; } [[nodiscard]] auto getZoomFactor() const -> float { return zoom_factor_; } + [[nodiscard]] auto getSsTextureSize() const -> std::pair; private: // Estructuras diff --git a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp index 9dc28e9..2dbb0bf 100644 --- a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp +++ b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp @@ -924,6 +924,11 @@ namespace Rendering { downscale_algo_ = std::max(0, std::min(algo, 2)); } + auto SDL3GPUShader::getSsTextureSize() const -> std::pair { + if (ss_factor_ <= 1) { return {0, 0}; } + return {game_width_ * ss_factor_, game_height_ * ss_factor_}; + } + // --------------------------------------------------------------------------- // reinitTexturesAndBuffer — recrea scene_texture_, scaled_texture_ y // upload_buffer_ con el factor oversample_ actual. No toca pipelines ni samplers. diff --git a/source/core/rendering/sdl3gpu/sdl3gpu_shader.hpp b/source/core/rendering/sdl3gpu/sdl3gpu_shader.hpp index 06a0e11..52326ac 100644 --- a/source/core/rendering/sdl3gpu/sdl3gpu_shader.hpp +++ b/source/core/rendering/sdl3gpu/sdl3gpu_shader.hpp @@ -82,6 +82,9 @@ namespace Rendering { // Selecciona algoritmo de downscale: 0=bilinear legacy, 1=Lanczos2, 2=Lanczos3 void setDownscaleAlgo(int algo) override; + // Devuelve las dimensiones de la textura de supersampling (0,0 si SS desactivado) + [[nodiscard]] auto getSsTextureSize() const -> std::pair override; + private: static auto createShaderMSL(SDL_GPUDevice* device, const char* msl_source, diff --git a/source/core/rendering/shader_backend.hpp b/source/core/rendering/shader_backend.hpp index 2714be3..e42f955 100644 --- a/source/core/rendering/shader_backend.hpp +++ b/source/core/rendering/shader_backend.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace Rendering { @@ -105,6 +106,12 @@ namespace Rendering { virtual void setDownscaleAlgo(int /*algo*/) {} [[nodiscard]] virtual auto getDownscaleAlgo() const -> int { return 0; } + /** + * @brief Devuelve las dimensiones de la textura de supersampling. + * @return Par (ancho, alto) en píxeles; (0, 0) si SS está desactivado. + */ + [[nodiscard]] virtual auto getSsTextureSize() const -> std::pair { return {0, 0}; } + /** * @brief Verifica si el backend está usando aceleración por hardware * @return true si usa aceleración (OpenGL/Metal/Vulkan) diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index a850fb1..6ad22f2 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -74,7 +74,7 @@ static auto parseTokens(const std::string& input) -> std::vector { // Texto de ayuda común para HELP y ? static void printHelp() { SDL_Log("=== JDD CONSOLE COMMANDS ==="); - SDL_Log(" SS [ON|OFF] Supersampling (Ctrl+F4)"); + SDL_Log(" SS [ON|OFF|SIZE] Supersampling (Ctrl+F4)"); SDL_Log(" POSTFX [ON|OFF|NEXT] Post-FX / next preset (F4/Shift+F4)"); SDL_Log(" BORDER [ON|OFF] Decorative border (B)"); SDL_Log(" FULLSCREEN [ON|OFF] Fullscreen mode (F3)"); @@ -107,8 +107,30 @@ static void printHelp() { // Tabla de comandos disponibles static const std::vector COMMANDS = { - // SS [ON|OFF] — Supersampling (Ctrl+F4) - {.keyword = "SS", .execute = BOOL_TOGGLE_CMD("Supersampling", Options::video.supersampling, Screen::get()->toggleSupersampling())}, + // SS [ON|OFF|SIZE] — Supersampling (Ctrl+F4) + {.keyword = "SS", .execute = [](const std::vector& args) -> std::string { + if (!args.empty() && args[0] == "SIZE") { + if (!Options::video.supersampling) { return "Supersampling OFF"; } + const auto [w, h] = Screen::get()->getSsTextureSize(); + if (w == 0) { return "SS texture: not active"; } + return "SS texture: " + std::to_string(w) + "x" + std::to_string(h); + } + if (args.empty()) { + Screen::get()->toggleSupersampling(); + return std::string("Supersampling ") + (Options::video.supersampling ? "ON" : "OFF"); + } + if (args[0] == "ON") { + if (Options::video.supersampling) { return "Supersampling already ON"; } + Screen::get()->toggleSupersampling(); + return "Supersampling ON"; + } + if (args[0] == "OFF") { + if (!Options::video.supersampling) { return "Supersampling already OFF"; } + Screen::get()->toggleSupersampling(); + return "Supersampling OFF"; + } + return "Usage: SS [ON|OFF|SIZE]"; + }}, // POSTFX [ON|OFF|NEXT] — PostFX y presets (F4 / Shift+F4) {.keyword = "POSTFX", .execute = [](const std::vector& args) -> std::string {