From 7f26b8dbd04756068d6236f78511b72d2f62811d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 16 Apr 2026 13:40:21 +0200 Subject: [PATCH] opcions per defecte d'emscripten --- source/core/rendering/screen.cpp | 30 ++++++++++++++++++++++++++++-- source/core/rendering/screen.hpp | 1 + source/main.cpp | 9 +++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index 6701387..5e12249 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -42,10 +42,9 @@ Screen::Screen() { window_ = SDL_CreateWindow(Locale::get("window.title"), w, h, fullscreen_ ? SDL_WINDOW_FULLSCREEN : 0); renderer_ = SDL_CreateRenderer(window_, nullptr); - SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH, GAME_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX); texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, GAME_WIDTH, GAME_HEIGHT); - SDL_SetTextureScaleMode(texture_, SDL_SCALEMODE_NEAREST); + applyFallbackPresentation(); // Inicialitza backend GPU si l'acceleració està activada initShaders(); @@ -204,6 +203,8 @@ void Screen::toggleAspectRatio() { Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3; if (shader_backend_) { shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3); + } else { + applyFallbackPresentation(); } if (!fullscreen_) { adjustWindowSize(); @@ -214,6 +215,8 @@ void Screen::toggleIntegerScale() { Options::video.integer_scale = !Options::video.integer_scale; if (shader_backend_) { shader_backend_->setScaleMode(Options::video.integer_scale); + } else { + applyFallbackPresentation(); } } @@ -228,6 +231,8 @@ void Screen::toggleStretchFilter() { Options::video.stretch_filter_linear = !Options::video.stretch_filter_linear; if (shader_backend_) { shader_backend_->setStretchFilter(Options::video.stretch_filter_linear); + } else { + applyFallbackPresentation(); } } @@ -383,6 +388,27 @@ void Screen::updateRenderInfo() { 0b1001); } +void Screen::applyFallbackPresentation() { + // Fallback SDL_Renderer (p.ex. emscripten/WebGL2 sense shaders GPU): tria + // el mode de presentació lògica segons 4:3 i integer_scale, i aplica el + // filtre de la textura segons stretch_filter_linear. Sense açò, el path + // fallback mostrava sempre LETTERBOX i ignorava les tres flags. + SDL_ScaleMode scale = Options::video.stretch_filter_linear ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST; + if (texture_) SDL_SetTextureScaleMode(texture_, scale); + + SDL_RendererLogicalPresentation mode; + if (Options::video.aspect_ratio_4_3) { + // La finestra ja té aspect 4:3 (alçada × 1.2); STRETCH estira la + // textura 320×200 fins a omplir-la exactament. + mode = SDL_LOGICAL_PRESENTATION_STRETCH; + } else if (Options::video.integer_scale) { + mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE; + } else { + mode = SDL_LOGICAL_PRESENTATION_LETTERBOX; + } + SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH, GAME_HEIGHT, mode); +} + void Screen::adjustWindowSize() { int w = GAME_WIDTH * zoom_; // Si 4:3 actiu, l'alçada visual és 240 per zoom (200 * 1.2) diff --git a/source/core/rendering/screen.hpp b/source/core/rendering/screen.hpp index 9c3a404..400ce4f 100644 --- a/source/core/rendering/screen.hpp +++ b/source/core/rendering/screen.hpp @@ -53,6 +53,7 @@ class Screen { void adjustWindowSize(); void calculateMaxZoom(); void initShaders(); + void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer static Screen* instance_; diff --git a/source/main.cpp b/source/main.cpp index b89fb3b..99502dc 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -39,6 +39,15 @@ SDL_AppResult SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) { Options::setConfigFile(std::string(file_getconfigfolder()) + "config.yaml"); Options::loadFromFile(); +#ifdef __EMSCRIPTEN__ + // MEMFS no persistix entre recàrregues: força valors sensats per a web. + Options::window.fullscreen = false; + Options::window.zoom = 1; + Options::video.aspect_ratio_4_3 = true; + Options::video.integer_scale = true; + Options::video.stretch_filter_linear = true; +#endif + // Carrega textos (idioma per defecte: valencià) Locale::load("locale/ca.yaml");