From badf92420bf4bef70f9326f66ecb40305ae628f3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 19 Mar 2026 22:53:13 +0100 Subject: [PATCH] =?UTF-8?q?feat(engine):=20PostFX=20cycle=20+=20fixes=20de?= =?UTF-8?q?=20reinicialitzaci=C3=B3=20i=20overflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Afegir handlePostFXCycle() amb 5 presets (vinyeta/scanlines/cromàtica/complet/off) i tecla X per ciclar-los (input_handler + engine.hpp) - Augmentar MAX_SPRITES de 65536 a 200000 i afegir guard d'overflow a pushQuad() - Netejar textures/objectes UI abans de reinicialitzar (AppLogo::initialize, UIManager::initialize) per evitar leaks en toggleRealFullscreen Co-Authored-By: Claude Sonnet 4.6 --- source/engine.hpp | 4 ++++ source/gpu/gpu_sprite_batch.cpp | 1 + source/gpu/gpu_sprite_batch.hpp | 2 +- source/input/input_handler.cpp | 5 +++++ source/ui/app_logo.cpp | 5 +++++ source/ui/ui_manager.cpp | 5 +++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/source/engine.hpp b/source/engine.hpp index 34f56a2..97a3afe 100644 --- a/source/engine.hpp +++ b/source/engine.hpp @@ -75,6 +75,9 @@ class Engine { void toggleRealFullscreen(); void toggleIntegerScaling(); + // PostFX presets + void handlePostFXCycle(); + // Modo kiosko void setKioskMode(bool enabled) { kiosk_mode_ = enabled; } bool isKioskMode() const { return kiosk_mode_; } @@ -165,6 +168,7 @@ class Engine { // PostFX uniforms (passed to GPU each frame) PostFXUniforms postfx_uniforms_ = {1.5f, 0.0f, 0.0f, 0.0f}; + int postfx_effect_mode_ = 0; // Sistema de zoom dinámico int current_window_zoom_ = DEFAULT_WINDOW_ZOOM; diff --git a/source/gpu/gpu_sprite_batch.cpp b/source/gpu/gpu_sprite_batch.cpp index fd7146a..ba3348e 100644 --- a/source/gpu/gpu_sprite_batch.cpp +++ b/source/gpu/gpu_sprite_batch.cpp @@ -179,6 +179,7 @@ void GpuSpriteBatch::toNDC(float px, float py, void GpuSpriteBatch::pushQuad(float ndx0, float ndy0, float ndx1, float ndy1, float u0, float v0, float u1, float v1, float r, float g, float b, float a) { + if (vertices_.size() + 4 > static_cast(MAX_SPRITES) * 4) return; uint32_t vi = static_cast(vertices_.size()); // TL, TR, BR, BL diff --git a/source/gpu/gpu_sprite_batch.hpp b/source/gpu/gpu_sprite_batch.hpp index 0cd1a05..56ed788 100644 --- a/source/gpu/gpu_sprite_batch.hpp +++ b/source/gpu/gpu_sprite_batch.hpp @@ -27,7 +27,7 @@ struct GpuVertex { class GpuSpriteBatch { public: // Maximum sprites (background + UI overlay each count as one sprite) - static constexpr int MAX_SPRITES = 65536; + static constexpr int MAX_SPRITES = 200000; bool init(SDL_GPUDevice* device); void destroy(SDL_GPUDevice* device); diff --git a/source/input/input_handler.cpp b/source/input/input_handler.cpp index c5592dd..55aff13 100644 --- a/source/input/input_handler.cpp +++ b/source/input/input_handler.cpp @@ -280,6 +280,11 @@ bool InputHandler::processEvents(Engine& engine) { engine.toggleLogoMode(); break; + // Ciclar presets PostFX (vinyeta/scanlines/cromàtica/complet/desactivat) + case SDLK_X: + engine.handlePostFXCycle(); + break; + // Toggle Debug Display (movido de H a F12) case SDLK_F12: engine.toggleDebug(); diff --git a/source/ui/app_logo.cpp b/source/ui/app_logo.cpp index eaf83d5..01e59a2 100644 --- a/source/ui/app_logo.cpp +++ b/source/ui/app_logo.cpp @@ -36,6 +36,11 @@ AppLogo::~AppLogo() { // ============================================================================ bool AppLogo::initialize(SDL_Renderer* renderer, int screen_width, int screen_height) { + if (logo1_base_texture_) { SDL_DestroyTexture(logo1_base_texture_); logo1_base_texture_ = nullptr; } + if (logo1_native_texture_) { SDL_DestroyTexture(logo1_native_texture_); logo1_native_texture_ = nullptr; } + if (logo2_base_texture_) { SDL_DestroyTexture(logo2_base_texture_); logo2_base_texture_ = nullptr; } + if (logo2_native_texture_) { SDL_DestroyTexture(logo2_native_texture_); logo2_native_texture_ = nullptr; } + renderer_ = renderer; base_screen_width_ = screen_width; base_screen_height_ = screen_height; diff --git a/source/ui/ui_manager.cpp b/source/ui/ui_manager.cpp index bcb4a95..20b65b5 100644 --- a/source/ui/ui_manager.cpp +++ b/source/ui/ui_manager.cpp @@ -70,6 +70,11 @@ UIManager::~UIManager() { void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager, int physical_width, int physical_height, int logical_width, int logical_height) { + delete text_renderer_debug_; text_renderer_debug_ = nullptr; + delete text_renderer_notifier_; text_renderer_notifier_ = nullptr; + delete notifier_; notifier_ = nullptr; + delete help_overlay_; help_overlay_ = nullptr; + renderer_ = renderer; theme_manager_ = theme_manager; physical_window_width_ = physical_width;