refactor(core/rendering): Screen desacoblat de SDL3GPUShader concret (COUP-02a)

Screen ja no inclou sdl3gpu/sdl3gpu_shader.hpp ni instancia la classe
concreta. S'afegeix la fàbrica Rendering::makeDefaultShaderBackend()
declarada a shader_backend.hpp i implementada a sdl3gpu_shader.cpp
(únic fitxer que encara coneix la classe concreta).

Per a que Screen no necessite static_cast, releaseWindow() passa a ser
mètode virtual pur de la interfície ShaderBackend (abans només existia
a SDL3GPUShader). SDL3GPUShader::releaseWindow marca override.

Build + smoke 5s xvfb OK (exit 124).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
JailDesignerandClaude Opus 4.7 committed 2026-04-20 09:36:11 +02:00
1 parent a63deac6a3
commit 029907d5a0
5 files changed
+21 -7

No files matched your search

+4 -3
View File
@@ -22,7 +22,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | DONE | | DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | DONE |
| CONV-03 | Shaders MSL como raw strings en `.cpp` + helpers duplicados | DONE | | CONV-03 | Shaders MSL como raw strings en `.cpp` + helpers duplicados | DONE |
| DUP-03 | Familia `Text::write*` con bucle UTF-8 repetido 5 veces | DONE | | DUP-03 | Familia `Text::write*` con bucle UTF-8 repetido 5 veces | DONE |
| COUP-02 | `Screen` instancia `SDL3GPUShader` directamente + `Surface` → `Screen::get()` | PENDING | | COUP-02 | `Screen` instancia `SDL3GPUShader` directamente + `Surface` → `Screen::get()` | WIP (a: DONE, b: PENDING) |
--- ---
@@ -72,7 +72,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|----|---------------|----------|-----------|--------|-------| |----|---------------|----------|-----------|--------|-------|
| COUP-01a | `notifier.hpp:9` | `core/rendering/notifier.hpp` incluye `game/ui/notification_presets.hpp` | Crítico | DONE | helper `Notification::notify()` en `game/ui` | | COUP-01a | `notifier.hpp:9` | `core/rendering/notifier.hpp` incluye `game/ui/notification_presets.hpp` | Crítico | DONE | helper `Notification::notify()` en `game/ui` |
| COUP-01b | `render_info.cpp:12-13` | `core/rendering/render_info.cpp` incluye `game/options.hpp` + `game/ui/ui_palette.hpp` | Crítico | DONE | `RenderInfo::Frame` injectada; Options.buildRenderInfoFrame() | | COUP-01b | `render_info.cpp:12-13` | `core/rendering/render_info.cpp` incluye `game/options.hpp` + `game/ui/ui_palette.hpp` | Crítico | DONE | `RenderInfo::Frame` injectada; Options.buildRenderInfoFrame() |
| COUP-02 | `screen.cpp:13-14,109` | `Screen` instancia `SDL3GPUShader` concreto | Importante | PENDING | factory/registry | | COUP-02a | `screen.cpp:13-14,109` | `Screen` instancia `SDL3GPUShader` concreto | Importante | DONE | `Rendering::makeDefaultShaderBackend()` factory |
| COUP-03 | `surface.cpp:81-83,110-112` | `Surface::render` usa `Screen::get()` global | Importante | PENDING | pasar destino por parámetro | | COUP-03 | `surface.cpp:81-83,110-112` | `Surface::render` usa `Screen::get()` global | Importante | PENDING | pasar destino por parámetro |
| COUP-04 | `notifier.cpp:19`, `render_info.cpp:52` | `Resource::Cache::get().getSurface("8bithud.gif")` con string literal | Importante | PENDING | inyectar la surface | | COUP-04 | `notifier.cpp:19`, `render_info.cpp:52` | `Resource::Cache::get().getSurface("8bithud.gif")` con string literal | Importante | PENDING | inyectar la surface |
| COUP-05 | `animated_sprite.cpp:9,95-116` | parser YAML incrustado en sprite | Importante | PENDING | `AnimationLoader` en `core/resources` | | COUP-05 | `animated_sprite.cpp:9,95-116` | parser YAML incrustado en sprite | Importante | PENDING | `AnimationLoader` en `core/resources` |
@@ -124,4 +124,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
- `9395520` — COUP-01b: `RenderInfo` desacoblat de `game/options` + `game/ui/ui_palette` - `9395520` — COUP-01b: `RenderInfo` desacoblat de `game/options` + `game/ui/ui_palette`
- `d479475` — DUP-02: `Surface::render` delega a `renderWithColorReplace` - `d479475` — DUP-02: `Surface::render` delega a `renderWithColorReplace`
- `5f46fb2` — CONV-03 + DUP-04 + DUP-05 + PATCH-07: shaders MSL i helpers extrets a `sdl3gpu/msl/` i `sdl3gpu/shader_factory.hpp` - `5f46fb2` — CONV-03 + DUP-04 + DUP-05 + PATCH-07: shaders MSL i helpers extrets a `sdl3gpu/msl/` i `sdl3gpu/shader_factory.hpp`
- `<pendent>` — DUP-03 + HC-01: `Text` amb `resolveGlyph` i constants `INK_COLOR_INDEX` / `DEFAULT_TEXT_COLOR` - `a63deac` — DUP-03 + HC-01: `Text` amb `resolveGlyph` i constants `INK_COLOR_INDEX` / `DEFAULT_TEXT_COLOR`
- `<pendent>` — COUP-02a: `Screen` desacoblat de `SDL3GPUShader` via `makeDefaultShaderBackend()`
+2 -3
View File
@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#include <ranges> #include <ranges>
#include "core/rendering/sdl3gpu/sdl3gpu_shader.hpp"
#include "utils/defines.hpp" #include "utils/defines.hpp"
namespace { namespace {
@@ -74,7 +73,7 @@ void Screen::destroySdl() {
// 2) Destruir el GPU device (vkDestroyInstance amb Wayland encara viu). // 2) Destruir el GPU device (vkDestroyInstance amb Wayland encara viu).
// 3) Destruir la finestra SDL (tanca la surface de Wayland al final). // 3) Destruir la finestra SDL (tanca la surface de Wayland al final).
if (shader_backend_ != nullptr) { if (shader_backend_ != nullptr) {
static_cast<Rendering::SDL3GPUShader*>(shader_backend_.get())->releaseWindow(); shader_backend_->releaseWindow();
} }
shader_backend_.reset(); shader_backend_.reset();
if (game_texture_ != nullptr) { if (game_texture_ != nullptr) {
@@ -106,7 +105,7 @@ void Screen::createSdl() {
// Primer intent: path SDL3 GPU. Si falla, fallback automàtic a SDL_Renderer. // Primer intent: path SDL3 GPU. Si falla, fallback automàtic a SDL_Renderer.
if (config_.gpu_acceleration) { if (config_.gpu_acceleration) {
auto backend = std::make_unique<Rendering::SDL3GPUShader>(); auto backend = Rendering::makeDefaultShaderBackend();
backend->setPreferredDriver(config_.preferred_driver); backend->setPreferredDriver(config_.preferred_driver);
backend->setVSync(config_.vsync); backend->setVSync(config_.vsync);
if (backend->init(window_, canvas_width_, canvas_height_)) { if (backend->init(window_, canvas_width_, canvas_height_)) {
@@ -307,4 +307,8 @@ namespace Rendering {
window_ = nullptr; window_ = nullptr;
} }
auto makeDefaultShaderBackend() -> std::unique_ptr<ShaderBackend> {
return std::make_unique<SDL3GPUShader>();
}
} // namespace Rendering } // namespace Rendering
@@ -60,7 +60,7 @@ namespace Rendering {
// Allibera la finestra del device sense destruir el device. Cal cridar-ho // Allibera la finestra del device sense destruir el device. Cal cridar-ho
// abans de SDL_DestroyWindow perquè el VkSurface tancat no sobrevisca la // abans de SDL_DestroyWindow perquè el VkSurface tancat no sobrevisca la
// finestra de Wayland (vkDestroyInstance cridaria Wayland amb surface invàlida). // finestra de Wayland (vkDestroyInstance cridaria Wayland amb surface invàlida).
void releaseWindow(); void releaseWindow() override;
[[nodiscard]] auto isReady() const -> bool override { return is_ready_; } [[nodiscard]] auto isReady() const -> bool override { return is_ready_; }
[[nodiscard]] auto getDriverName() const -> std::string override { return driver_name_; } [[nodiscard]] auto getDriverName() const -> std::string override { return driver_name_; }
+10
View File
@@ -3,6 +3,7 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <cstdint> #include <cstdint>
#include <memory>
#include <string> #include <string>
#include "utils/defaults.hpp" #include "utils/defaults.hpp"
@@ -90,8 +91,17 @@ namespace Rendering {
// Destrueix tots els recursos GPU (pipeline, textura, buffer, sampler, device). // Destrueix tots els recursos GPU (pipeline, textura, buffer, sampler, device).
virtual void cleanup() = 0; virtual void cleanup() = 0;
// Allibera la finestra del device sense destruir el device. Cal cridar-ho
// ABANS de SDL_DestroyWindow per evitar que vkDestroyInstance intente
// alliberar una Wayland surface ja desapareguda.
virtual void releaseWindow() = 0;
[[nodiscard]] virtual auto isReady() const -> bool = 0; [[nodiscard]] virtual auto isReady() const -> bool = 0;
[[nodiscard]] virtual auto getDriverName() const -> std::string = 0; [[nodiscard]] virtual auto getDriverName() const -> std::string = 0;
}; };
// Fàbrica: construeix el backend per defecte del projecte (SDL3 GPU).
// Screen l'invoca sense conèixer la classe concreta.
[[nodiscard]] auto makeDefaultShaderBackend() -> std::unique_ptr<ShaderBackend>;
} // namespace Rendering } // namespace Rendering