5#include "flint/camera/camera.h"
6#include "flint/core/api.h"
7#include "flint/core/asset-loader.h"
8#include "flint/graphics/drawable.h"
9#include "flint/graphics/pipelines/batch-pipeline.h"
10#include "flint/graphics/pipelines/primitives-pipeline.h"
11#include "flint/graphics/pipelines/ui-pipeline.h"
12#include "flint/graphics/types/color.h"
13#include "flint/window/IWindow.h"
15#include <SDL3/SDL_gpu.h>
16#include <SDL3/SDL_render.h>
50 ShaderFormat shaderFormat);
87 FLINT_API
void submit(std::shared_ptr<const Drawable> drawable,
88 DrawLayer layer = DrawLayer::Midground);
99 [[deprecated(
"Use submit(std::shared_ptr<const Drawable>, DrawLayer) instead.")]]
100 FLINT_API
void submit(
const Drawable *drawable, DrawLayer layer = DrawLayer::Midground);
125 return std::make_unique<Shader>(m_gpuDevice, m_shaderFormat);
133 [[nodiscard]] FLINT_API std::vector<char>
loadShader(
const std::string &basePath)
const;
140 [[nodiscard]] FLINT_API std::string
getShaderPath(
const std::string &basePath)
const;
144 return m_shaderFormat;
154 [[deprecated(
"Do not query getRenderPass() during emission. Use RenderQueue::custom() for "
155 "custom GPU draw passes.")]] [[nodiscard]] SDL_GPURenderPass *
165 if (mode != SDL_GPU_PRESENTMODE_VSYNC &&
166 !SDL_WindowSupportsGPUPresentMode(m_gpuDevice, m_sdlWindow, mode)) {
167 FLINT_ENGINE_WARN(
"Present mode {} unsupported, falling back to VSYNC",
168 static_cast<int>(mode));
169 mode = SDL_GPU_PRESENTMODE_VSYNC;
171 if (!SDL_SetGPUSwapchainParameters(m_gpuDevice, m_sdlWindow,
172 SDL_GPU_SWAPCHAINCOMPOSITION_SDR, mode)) {
173 FLINT_ENGINE_ERROR(
"SDL_SetGPUSwapchainParameters failed: {}", SDL_GetError());
185 "Do not query getCommandBuffer() during emission. Use RenderQueue::deferUpload() or "
186 "RenderQueue::custom().")]] [[nodiscard]] SDL_GPUCommandBuffer *
188 return m_commandBuffer;
193 return m_currentCameraView;
203 return m_assetLoader;
208 return m_defaultViewport;
222 return m_primitivePipeline;
227 return m_defaultWhiteTexture;
232 SDL_Window *m_sdlWindow =
nullptr;
233 ShaderFormat m_shaderFormat;
234 SDL_GPURenderPass *m_renderPass =
nullptr;
235 SDL_GPUDevice *m_gpuDevice =
nullptr;
236 SDL_GPUCommandBuffer *m_commandBuffer =
nullptr;
237 SDL_GPUTexture *m_swapTexture =
nullptr;
238 Uint32 m_swapWidth = 0, m_swapHeight = 0;
240 std::vector<DrawCommand> m_commands;
243 UIPipeline m_uiPipeline;
244 BatchPipeline m_batchPipeline;
245 PrimitivePipeline m_primitivePipeline;
247 Color m_clearColor = {0, 0, 0, 255};
249 SDL_GPUTexture *m_defaultWhiteTexture =
nullptr;
250 SDL_GPUSampler *m_defaultSampler =
nullptr;
251 SDL_GPUViewport m_defaultViewport{};
253 IAssetLoader &m_assetLoader;
255 std::unique_ptr<FrameData>
262 bool uploadFrameBuffers();
274 void ensureBuffer(SDL_GPUBuffer *&buffer, Uint32 &capacity, Uint32 neededBytes,
275 SDL_GPUBufferUsageFlags usage,
const char *debugName);
281 void resetFrameData();
286 void destroyFrameBuffers();
288 void createDefaultViewport(SDL_GPURenderPass *renderPass);
289 bool createDefaultTexture();
290 void initializePipelines();
291 void cleanupPipelines();
Interface for objects that contribute ordered work to a rendered frame.
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
FLINT_API std::vector< char > loadShader(const std::string &basePath) const
Load raw shader bytecode bytes from the asset loader.
ShaderFormat getShaderFormat() const
Get the active GPU shader format.
FLINT_API void submit(std::shared_ptr< const Drawable > drawable, DrawLayer layer=DrawLayer::Midground)
Queue a shared Drawable for rendering in the current frame.
FLINT_API 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.
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.
FLINT_API void submit(const Drawable *drawable, DrawLayer layer=DrawLayer::Midground)
Queue a raw Drawable pointer for rendering in the current frame.
FLINT_API void setClearColor(Color color)
Set the RGBA clear color applied at the start of each frame.
UIPipeline & getUIPipeline()
Return reference to the UI pipeline wrapper.
FLINT_API bool beginFrame()
Acquire the next swapchain texture and prepare the initial GPU command buffer.
FLINT_API GPURenderer(IWindow *window, IAssetLoader &assetLoader, ShaderFormat shaderFormat)
Construct the renderer and initialize the underlying GPU device for the window.
FLINT_API void setViewport(const SDL_GPUViewport &viewport)
Set or override the default rendering viewport.
FLINT_API std::string getShaderPath(const std::string &basePath) const
Get the full asset path for a shader base name including system format extension.
FLINT_API void endFrame()
Close active render passes, submit the command buffer to the GPU, and present.
const FloatRect & getCurrentCameraView() const
Return the camera view rectangle used for the current frame projection.
FLINT_API void draw(const std::function< void(RenderQueue &)> &overlayEmit={})
Execute all queued draw commands in layer and submission order.
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.
FLINT_API 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.