5#include "flint/camera/camera.h"
6#include "flint/core/asset-loader.h"
7#include "flint/graphics/drawable.h"
8#include "flint/graphics/pipelines/batch-pipeline.h"
9#include "flint/graphics/pipelines/primitives-pipeline.h"
10#include "flint/graphics/pipelines/ui-pipeline.h"
11#include "flint/graphics/types/color.h"
12#include "flint/window/IWindow.h"
14#include <SDL3/SDL_gpu.h>
15#include <SDL3/SDL_render.h>
85 void submit(std::shared_ptr<const Drawable> drawable, DrawLayer layer = DrawLayer::Midground);
96 [[deprecated(
"Use submit(std::shared_ptr<const Drawable>, DrawLayer) instead.")]]
97 void submit(
const Drawable *drawable, DrawLayer layer = DrawLayer::Midground);
122 return std::make_unique<Shader>(m_gpuDevice, m_shaderFormat);
130 [[nodiscard]] std::vector<char>
loadShader(
const std::string &basePath)
const;
141 return m_shaderFormat;
151 [[deprecated(
"Do not query getRenderPass() during emission. Use RenderQueue::custom() for "
152 "custom GPU draw passes.")]] [[nodiscard]] SDL_GPURenderPass *
162 if (mode != SDL_GPU_PRESENTMODE_VSYNC &&
163 !SDL_WindowSupportsGPUPresentMode(m_gpuDevice, m_sdlWindow, mode)) {
164 FLINT_ENGINE_WARN(
"Present mode {} unsupported, falling back to VSYNC",
165 static_cast<int>(mode));
166 mode = SDL_GPU_PRESENTMODE_VSYNC;
168 if (!SDL_SetGPUSwapchainParameters(m_gpuDevice, m_sdlWindow,
169 SDL_GPU_SWAPCHAINCOMPOSITION_SDR, mode)) {
170 FLINT_ENGINE_ERROR(
"SDL_SetGPUSwapchainParameters failed: {}", SDL_GetError());
182 "Do not query getCommandBuffer() during emission. Use RenderQueue::deferUpload() or "
183 "RenderQueue::custom().")]] [[nodiscard]] SDL_GPUCommandBuffer *
185 return m_commandBuffer;
190 return m_currentCameraView;
200 return m_assetLoader;
205 return m_defaultViewport;
219 return m_primitivePipeline;
224 return m_defaultWhiteTexture;
229 SDL_Window *m_sdlWindow =
nullptr;
230 ShaderFormat m_shaderFormat;
231 SDL_GPURenderPass *m_renderPass =
nullptr;
232 SDL_GPUDevice *m_gpuDevice =
nullptr;
233 SDL_GPUCommandBuffer *m_commandBuffer =
nullptr;
234 SDL_GPUTexture *m_swapTexture =
nullptr;
235 Uint32 m_swapWidth = 0, m_swapHeight = 0;
237 std::vector<DrawCommand> m_commands;
240 UIPipeline m_uiPipeline;
241 BatchPipeline m_batchPipeline;
242 PrimitivePipeline m_primitivePipeline;
244 Color m_clearColor = {0, 0, 0, 255};
246 SDL_GPUTexture *m_defaultWhiteTexture =
nullptr;
247 SDL_GPUSampler *m_defaultSampler =
nullptr;
248 SDL_GPUViewport m_defaultViewport{};
250 IAssetLoader &m_assetLoader;
252 std::unique_ptr<FrameData>
259 bool uploadFrameBuffers();
271 void ensureBuffer(SDL_GPUBuffer *&buffer, Uint32 &capacity, Uint32 neededBytes,
272 SDL_GPUBufferUsageFlags usage,
const char *debugName);
278 void resetFrameData();
283 void destroyFrameBuffers();
285 void createDefaultViewport(SDL_GPURenderPass *renderPass);
286 bool createDefaultTexture();
287 void initializePipelines();
288 void cleanupPipelines();
Interface for objects that contribute ordered work to a rendered frame.
ShaderFormat getShaderFormat() const
Get the active GPU shader format.
void setCamera(const Camera &camera)
Update the active camera view transform used for batch coordinate projection.
PrimitivePipeline & getPrimitivePipeline()
Return reference to the primitive point/line pipeline wrapper.
void draw(const std::function< void(RenderQueue &)> &overlayEmit={})
Execute all queued draw commands in layer and submission order.
SDL_GPURenderPass * getRenderPass() const
Return the current frame's active SDL GPU render pass handle.
IAssetLoader & getAssetLoader() const
Return reference to the core asset loader.
SDL_GPUCommandBuffer * getCommandBuffer() const
Return the current frame's active SDL GPU command buffer handle.
SDL_GPUTexture * getWhiteTexture()
Return shared 1x1 fallback white GPU texture handle.
std::unique_ptr< Shader > createShader() const
Factory method creating a new Shader instance bound to this GPU device.
void setViewport(const SDL_GPUViewport &viewport)
Set or override the default rendering viewport.
void submit(const Drawable *drawable, DrawLayer layer=DrawLayer::Midground)
Queue a raw Drawable pointer for rendering in the current frame.
UIPipeline & getUIPipeline()
Return reference to the UI pipeline wrapper.
void setClearColor(Color color)
Set the RGBA clear color applied at the start of each frame.
bool beginFrame()
Acquire the next swapchain texture and prepare the initial GPU command buffer.
void submit(std::shared_ptr< const Drawable > drawable, DrawLayer layer=DrawLayer::Midground)
Queue a shared Drawable for rendering in the current frame.
GPURenderer(IWindow *window, IAssetLoader &assetLoader, ShaderFormat shaderFormat)
Construct the renderer and initialize the underlying GPU device for the window.
void endFrame()
Close active render passes, submit the command buffer to the GPU, and present.
std::vector< char > loadShader(const std::string &basePath) const
Load raw shader bytecode bytes from the asset loader.
const FloatRect & getCurrentCameraView() const
Return the camera view rectangle used for the current frame projection.
std::string getShaderPath(const std::string &basePath) const
Get the full asset path for a shader base name including system format extension.
void setGPUPresentMode(SDL_GPUPresentMode mode)
Configure GPU swapchain presentation mode for the window.
const SDL_GPUViewport & getDefaultViewport() const
Return default full-screen viewport bounds.
SDL_GPUDevice * getGPUDevice() const
Return the native SDL GPU device owned by this renderer.
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
SDL_Renderer * getSDLRenderer() const
Return legacy SDL_Renderer handle if running alongside an SDL software fallback pass.
Abstract interface for loading raw asset data by path.
Abstract interface for a platform window.
Batches drawables into sorted geometry, primitive, and custom execution passes for GPURenderer.
Alpha-blended pipeline for rendering UI elements (text, panels, icons).
RGBA color with 8-bit unsigned components.