Fase 7b+c: swap atomico a SDL3 GPU (Vulkan/Metal, sin SDL_Renderer)
El runtime de rendering pasa a SDL3 GPU. SDL_Renderer eliminado por completo del proyecto: SDLManager posee un GpuFrameRenderer y todo el resto del codigo habla con un Rendering::Renderer* opaco (alias del GpuFrameRenderer). Cambios principales: - core/rendering/render_context.hpp: alias central `using Rendering::Renderer = GPU::GpuFrameRenderer;` — punto unico de indireccion entre el juego y el backend de dibujo. - core/rendering/sdl_manager.hpp/cpp: deja de tener SDL_Renderer*; contiene un Rendering::Renderer gpu_renderer_. iniciar() ahora hace GpuDevice::init + pipeline; clear() llama beginFrame; present() llama endFrame. Letterbox se aplica via setViewport tras cada begin del render pass. toggleVSync() usa SDL_SetGPUSwapchainParameters. - core/rendering/line_renderer.hpp/cpp: la firma cambia a `linea(Renderer*, x1,y1,x2,y2, brightness, thickness)`. La implementacion deja de usar SDL_RenderLine: empuja la linea como quad extrudido al batch del GpuFrameRenderer. Se anade un grosor global configurable via setLineThickness (default 1.5 px). Ya no se aplica transform_x/y porque el shader hace logical->NDC y el viewport hace el letterbox. - gpu_frame_renderer: anade setViewport (aplicable mid-frame), setVSync (PRESENTMODE_VSYNC/IMMEDIATE) y applyViewport interno que re-aplica el viewport tras reabrir el render pass en flushBatch. - Sed sweep masivo en 19 archivos: SDL_Renderer* -> Rendering::Renderer* en headers y .cpp de entities, effects, graphics y title. Los archivos solo propagan el puntero — solo line_renderer consume sus metodos. SDL_Renderer queda eliminado del proyecto. Smoke test xvfb: backend Vulkan detectado, binario arranca, carga todos los shapes/audio/title, TitleScene inicializa, termina limpio con "Adeu!". stderr vacio. Validacion visual pendiente en hardware real (xvfb VMware sin 3D no muestra el swapchain Vulkan). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,38 +1,51 @@
|
||||
// line_renderer.cpp - Implementació de renderizado de línies
|
||||
// line_renderer.cpp - Implementación de renderizado de líneas (SDL3 GPU)
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
|
||||
#include "core/rendering/coordinate_transform.hpp"
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Color global compartit (actualitzat per ColorOscillator via SDLManager)
|
||||
// Color global compartido (actualizado por ColorOscillator via SDLManager).
|
||||
SDL_Color g_current_line_color = {255, 255, 255, 255};
|
||||
|
||||
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness) {
|
||||
// Grosor global por defecto. Configurable via setLineThickness.
|
||||
// 1.5 da una línea visible y crujiente; 1.0 se ve demasiado fino en pantallas grandes.
|
||||
float g_current_line_thickness = 1.5F;
|
||||
|
||||
void linea(Renderer* renderer,
|
||||
int x1, int y1, int x2, int y2,
|
||||
float brightness,
|
||||
float thickness) {
|
||||
if (renderer == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transformar coordenades lògiques (640x480) a físiques (resolució real)
|
||||
const float SCALE = g_current_scale_factor;
|
||||
const int PX1 = transform_x(x1, SCALE);
|
||||
const int PY1 = transform_y(y1, SCALE);
|
||||
const int PX2 = transform_x(x2, SCALE);
|
||||
const int PY2 = transform_y(y2, SCALE);
|
||||
// Coords lógicas (1280×720). El shader hace el mapeo a NDC; el viewport
|
||||
// del SDLManager hace el letterbox a píxeles físicos.
|
||||
const float FX1 = static_cast<float>(x1);
|
||||
const float FY1 = static_cast<float>(y1);
|
||||
const float FX2 = static_cast<float>(x2);
|
||||
const float FY2 = static_cast<float>(y2);
|
||||
|
||||
// Aplicar brightness al color oscil·lat global
|
||||
const auto R = static_cast<uint8_t>(g_current_line_color.r * brightness);
|
||||
const auto G = static_cast<uint8_t>(g_current_line_color.g * brightness);
|
||||
const auto B = static_cast<uint8_t>(g_current_line_color.b * brightness);
|
||||
// Color: aplicar brightness al color oscilatorio global. Convertir 0..255 → 0..1.
|
||||
const float R = (static_cast<float>(g_current_line_color.r) * brightness) / 255.0F;
|
||||
const float G = (static_cast<float>(g_current_line_color.g) * brightness) / 255.0F;
|
||||
const float B = (static_cast<float>(g_current_line_color.b) * brightness) / 255.0F;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, R, G, B, 255);
|
||||
SDL_RenderLine(renderer, static_cast<float>(PX1), static_cast<float>(PY1),
|
||||
static_cast<float>(PX2), static_cast<float>(PY2));
|
||||
const float W = (thickness > 0.0F) ? thickness : g_current_line_thickness;
|
||||
|
||||
renderer->pushLine(FX1, FY1, FX2, FY2, W, R, G, B, 1.0F);
|
||||
}
|
||||
|
||||
void setLineColor(SDL_Color color) { g_current_line_color = color; }
|
||||
|
||||
void setLineThickness(float thickness) {
|
||||
if (thickness > 0.0F) {
|
||||
g_current_line_thickness = thickness;
|
||||
}
|
||||
}
|
||||
|
||||
auto getLineThickness() -> float { return g_current_line_thickness; }
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
Reference in New Issue
Block a user