Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
gpu-cast.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/core/log.h"
6#include "flint/graphics/gpu/gpu-context.h"
7#include "flint/window/IWindow.h"
8
9namespace Flint {
10
19 public:
30 if (!window) {
31 FLINT_ENGINE_ERROR("Cannot get GPU context from null window");
32 return nullptr;
33 }
34
35 auto gpuContext = dynamic_cast<IGPUContext *>(window);
36
37 if (!gpuContext) {
38 FLINT_ENGINE_ERROR("Window does not support GPU context interface");
39 }
40
41 return gpuContext;
42 }
43
50 static SDL_GPUDevice *getDevice(Flint::IWindow *window) {
51 IGPUContext *ctx = getGPUContext(window);
52 return ctx ? ctx->getGPUDevice() : nullptr;
53 }
54
61 static void setGPUDevice(Flint::IWindow *window, SDL_GPUDevice *device) {
62 IGPUContext *ctx = getGPUContext(window);
63 if (ctx) {
64 ctx->setGPUDevice(device);
65 }
66 }
67
74 static SDL_GPUCommandBuffer *getCommandBuffer(Flint::IWindow *window) {
75 IGPUContext *ctx = getGPUContext(window);
76 return ctx ? ctx->getCommandBuffer() : nullptr;
77 }
78
85 static SDL_GPURenderPass *getRenderPass(Flint::IWindow *window) {
86 IGPUContext *ctx = getGPUContext(window);
87 return ctx ? ctx->getRenderPass() : nullptr;
88 }
89 };
90}
static SDL_GPUDevice * getDevice(Flint::IWindow *window)
Return the SDL_GPUDevice from window.
Definition gpu-cast.h:50
static void setGPUDevice(Flint::IWindow *window, SDL_GPUDevice *device)
Store device inside the GPU context of window.
Definition gpu-cast.h:61
static IGPUContext * getGPUContext(Flint::IWindow *window)
Cast window to IGPUContext.
Definition gpu-cast.h:29
static SDL_GPURenderPass * getRenderPass(Flint::IWindow *window)
Return the current frame's render pass from window.
Definition gpu-cast.h:85
static SDL_GPUCommandBuffer * getCommandBuffer(Flint::IWindow *window)
Return the current frame's command buffer from window.
Definition gpu-cast.h:74
Helper that extracts SDL GPU objects from an IWindow via dynamic_cast.
Definition gpu-cast.h:18
virtual void setGPUDevice(SDL_GPUDevice *device)=0
Store the SDL GPU device created by the renderer.
virtual SDL_GPUCommandBuffer * getCommandBuffer()=0
Return the current frame's command buffer.
virtual SDL_GPUDevice * getGPUDevice()=0
Return the SDL GPU device associated with this context.
virtual SDL_GPURenderPass * getRenderPass()=0
Return the current frame's render pass.
Interface that exposes low-level SDL GPU objects from a window implementation.
Definition gpu-context.h:14
Abstract interface for a platform window.
Definition IWindow.h:27