Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::Shader Class Reference

Owns a pair of SDL GPU shaders (vertex + fragment) tied to one SDL_GPUDevice. More...

#include <flint/graphics/shaders.h>

+ Collaboration diagram for Flint::Shader:

Public Member Functions

 Shader (SDL_GPUDevice *device, ShaderFormat format)
 Construct a Shader bound to device and configured for format binaries.
 
bool loadFromMemory (ShaderStage stage, const void *data, size_t size, Uint32 numSamplers=0, Uint32 numStorageTextures=0, Uint32 numStorageBuffers=0, Uint32 numUniformBuffers=0)
 Compile and upload a shader stage from bytecode already present in memory.
 
SDL_GPUShader * getVertexShader () const
 Return the vertex shader handle tracked by this object (nullptr if absent).
 
SDL_GPUShader * getFragmentShader () const
 Return the fragment shader handle tracked by this object (nullptr if absent).
 
SDL_GPUDevice * getDevice () const
 Return the SDL GPU device that owns these shaders (may be nullptr before init).
 
void cleanup ()
 Release both shader stages, if present, and reset their handles to nullptr.
 

Protected Attributes

SDL_GPUDevice * m_device = nullptr
 
SDL_GPUShader * m_vertexShader = nullptr
 
SDL_GPUShader * m_fragmentShader = nullptr
 
ShaderFormat m_format
 

Detailed Description

Owns a pair of SDL GPU shaders (vertex + fragment) tied to one SDL_GPUDevice.

Shaders are loaded from precompiled bytecode via loadFromMemory() and stay alive until cleanup() or destruction, guaranteeing GPU resources are reclaimed even if only one stage was created.

Definition at line 86 of file shaders.h.

Constructor & Destructor Documentation

◆ Shader()

Flint::Shader::Shader ( SDL_GPUDevice * device,
ShaderFormat format )
inline

Construct a Shader bound to device and configured for format binaries.

Parameters
deviceSDL GPU device that will own the shader objects.
formatShader bytecode format used to set entry points and SDL formats.

Definition at line 94 of file shaders.h.

◆ ~Shader()

virtual Flint::Shader::~Shader ( )
inlinevirtual

Definition at line 99 of file shaders.h.

Member Function Documentation

◆ cleanup()

void Flint::Shader::cleanup ( )
inline

Release both shader stages, if present, and reset their handles to nullptr.

Safe to call multiple times and invoked automatically by the destructor.

Definition at line 192 of file shaders.h.

◆ getDevice()

SDL_GPUDevice * Flint::Shader::getDevice ( ) const
inline

Return the SDL GPU device that owns these shaders (may be nullptr before init).

Definition at line 183 of file shaders.h.

◆ getFragmentShader()

SDL_GPUShader * Flint::Shader::getFragmentShader ( ) const
inline

Return the fragment shader handle tracked by this object (nullptr if absent).

Definition at line 178 of file shaders.h.

◆ getVertexShader()

SDL_GPUShader * Flint::Shader::getVertexShader ( ) const
inline

Return the vertex shader handle tracked by this object (nullptr if absent).

Definition at line 173 of file shaders.h.

◆ loadFromMemory()

bool Flint::Shader::loadFromMemory ( ShaderStage stage,
const void * data,
size_t size,
Uint32 numSamplers = 0,
Uint32 numStorageTextures = 0,
Uint32 numStorageBuffers = 0,
Uint32 numUniformBuffers = 0 )
inline

Compile and upload a shader stage from bytecode already present in memory.

The supplied data must remain valid for the duration of the call. Reloading a stage replaces any existing SDL shader of the same type after releasing it.

Parameters
stageWhich stage to load (Vertex or Fragment).
dataPointer to shader bytecode.
sizeSize of data in bytes.
numSamplersNumber of texture samplers declared in the shader.
numStorageTexturesNumber of storage textures declared in the shader.
numStorageBuffersNumber of storage buffers declared in the shader.
numUniformBuffersNumber of uniform buffers declared in the shader.
Returns
true if creation succeeded; false if SDL reports an error.

Definition at line 119 of file shaders.h.

Member Data Documentation

◆ m_device

SDL_GPUDevice* Flint::Shader::m_device = nullptr
protected

Definition at line 208 of file shaders.h.

◆ m_format

ShaderFormat Flint::Shader::m_format
protected

Definition at line 211 of file shaders.h.

◆ m_fragmentShader

SDL_GPUShader* Flint::Shader::m_fragmentShader = nullptr
protected

Definition at line 210 of file shaders.h.

◆ m_vertexShader

SDL_GPUShader* Flint::Shader::m_vertexShader = nullptr
protected

Definition at line 209 of file shaders.h.


The documentation for this class was generated from the following file: