From 537150365ba535302dc4d82095138051dd7cf4ec Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 6 Mar 2025 13:29:39 +0100 Subject: [PATCH] Retocat el render path d'Screen --- source/screen.cpp | 89 +++++++++++++++++++++++++---------------------- source/screen.h | 12 +++++-- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/source/screen.cpp b/source/screen.cpp index 723d8f9..f61d1fd 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -127,23 +127,14 @@ void Screen::start() // Vuelca el contenido del renderizador en pantalla void Screen::render() { - // Renderiza sobre game_surface_ los overlays - renderNotifications(); + // Renderiza todos los overlays + renderOverlays(); - // Si está el borde activo, vuelca gameCanvas sobre borderCanvas - if (options.video.border.enabled) - { - setRendererSurface(border_surface_); - game_surface_->render(options.video.border.width, options.video.border.height); - border_surface_->copyToTexture(renderer_, border_texture_); - } - else - { - game_surface_->copyToTexture(renderer_, game_texture_); - } + // Copia la surface a la textura + surfaceToTexture(); - // Muestra el contenido por pantalla - renderPresent(); + // Copia la textura al renderizador + textureToRenderer(); } // Establece el modo de video @@ -245,32 +236,6 @@ void Screen::renderNotifications() } } -// Muestra el contenido de Screen por pantalla -void Screen::renderPresent() -{ - SDL_SetRenderTarget(renderer_, nullptr); - SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(renderer_); - - if (options.video.shaders) - { - // Aplica shaders y renderiza el contenido - shader::render(); - } - else - { - if (options.video.border.enabled) - { - SDL_RenderCopy(renderer_, border_texture_, nullptr, nullptr); - } - else - { - SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_rect_); - } - SDL_RenderPresent(renderer_); - } -} - // Cambia el estado de los shaders void Screen::toggleShaders() { @@ -396,4 +361,46 @@ void Screen::processPaletteList() { palette = getFileName(palette); } +} + +// Copia la surface a la textura +void Screen::surfaceToTexture() +{ + // Si está el borde activo, vuelca gameCanvas sobre borderCanvas + if (options.video.border.enabled) + { + setRendererSurface(border_surface_); + game_surface_->render(options.video.border.width, options.video.border.height); + border_surface_->copyToTexture(renderer_, border_texture_); + } + else + { + game_surface_->copyToTexture(renderer_, game_texture_); + } +} + +// Copia la textura al renderizador +void Screen::textureToRenderer() +{ + + SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); + SDL_RenderClear(renderer_); + + if (options.video.shaders) + { + shader::render(); + } + else + { + SDL_Texture *texture_to_render = options.video.border.enabled ? border_texture_ : game_texture_; + SDL_RenderCopy(renderer_, texture_to_render, nullptr, nullptr); + SDL_RenderPresent(renderer_); + } +} + +// Renderiza todos los overlays +void Screen::renderOverlays() +{ + renderNotifications(); } \ No newline at end of file diff --git a/source/screen.h b/source/screen.h index 7ff0427..3dec929 100644 --- a/source/screen.h +++ b/source/screen.h @@ -46,9 +46,6 @@ private: // Dibuja las notificaciones void renderNotifications(); - // Muestra el contenido de Screen por pantalla - void renderPresent(); - // Calcula el tamaño de la ventana void adjustWindowSize(); @@ -64,6 +61,15 @@ private: // Extrae los nombres de las paletas void processPaletteList(); + // Copia la surface a la textura + void surfaceToTexture(); + + // Copia la textura al renderizador + void textureToRenderer(); + + // Renderiza todos los overlays + void renderOverlays(); + // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer);