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

Owns an SDL GPU texture and its associated sampler. More...

#include <flint/graphics/gpu/gpu-texture.h>

+ Collaboration diagram for Flint::GPUTexture:

Public Member Functions

 GPUTexture (const GPUTexture &)=delete
 
GPUTexture & operator= (const GPUTexture &)=delete
 
 GPUTexture (GPUTexture &&other) noexcept
 Move constructor; transfers GPU ownership from the other.
 
GPUTexture & operator= (GPUTexture &&other) noexcept
 Move-assignment; releases current resources then steals from the other.
 
bool loadFromMemory (SDL_GPUDevice *device, const void *data, size_t size)
 Upload an image from memory to the GPU.
 
void free ()
 
SDL_GPUTexture * getTexture () const
 Return the underlying SDL GPU texture handle.
 
SDL_GPUSampler * getSampler () const
 Return the sampler created alongside this texture.
 
int getWidth () const
 Return the texture width in pixels.
 
int getHeight () const
 Return the texture height in pixels.
 

Static Public Member Functions

static GPUTexture fromRenderer (SDL_GPUDevice *device, const void *data, size_t size)
 Factory: create a GPUTexture by loading from memory.
 

Detailed Description

Owns an SDL GPU texture and its associated sampler.

Loads image data from memory, uploads it to the GPU via a transfer buffer, and creates a nearest-neighbor sampler. Move-only; copying is deleted.

Definition at line 21 of file gpu-texture.h.

Constructor & Destructor Documentation

◆ ~GPUTexture()

virtual Flint::GPUTexture::~GPUTexture ( )
inlinevirtual

Definition at line 25 of file gpu-texture.h.

◆ GPUTexture()

Flint::GPUTexture::GPUTexture ( GPUTexture && other)
inlinenoexcept

Move constructor; transfers GPU ownership from the other.

Definition at line 33 of file gpu-texture.h.

Member Function Documentation

◆ free()

void Flint::GPUTexture::free ( )
inline

Definition at line 211 of file gpu-texture.h.

◆ fromRenderer()

static GPUTexture Flint::GPUTexture::fromRenderer ( SDL_GPUDevice * device,
const void * data,
size_t size )
inlinestatic

Factory: create a GPUTexture by loading from memory.

Parameters
deviceSDL GPU device.
dataRaw image file bytes.
sizeSize of data in bytes.
Returns
A fully initialized GPUTexture (moved out).
Exceptions
std::runtime_errorif loading fails.

Definition at line 259 of file gpu-texture.h.

◆ getHeight()

int Flint::GPUTexture::getHeight ( ) const
inline

Return the texture height in pixels.

Definition at line 246 of file gpu-texture.h.

◆ getSampler()

SDL_GPUSampler * Flint::GPUTexture::getSampler ( ) const
inline

Return the sampler created alongside this texture.

Definition at line 236 of file gpu-texture.h.

◆ getTexture()

SDL_GPUTexture * Flint::GPUTexture::getTexture ( ) const
inline

Return the underlying SDL GPU texture handle.

Definition at line 231 of file gpu-texture.h.

◆ getWidth()

int Flint::GPUTexture::getWidth ( ) const
inline

Return the texture width in pixels.

Definition at line 241 of file gpu-texture.h.

◆ loadFromMemory()

bool Flint::GPUTexture::loadFromMemory ( SDL_GPUDevice * device,
const void * data,
size_t size )
inline

Upload an image from memory to the GPU.

Decodes the image with SDL_image and converts it to RGBA32 if it isn't already, so any source format (RGB, palettized, greyscale, etc.) uploads correctly. Allocates a 2-D R8G8B8A8_UNORM texture, copies the pixels row by row into a transfer buffer (handling source row padding), uploads, and creates a nearest-neighbor clamp-to-edge sampler.

Parameters
deviceSDL GPU device to use for resource creation.
dataPointer to raw image file bytes (e.g. PNG, BMP, etc.).
sizeNumber of bytes in data.
Returns
true on success, false if any GPU operation fails.

Definition at line 79 of file gpu-texture.h.

◆ operator=()

GPUTexture & Flint::GPUTexture::operator= ( GPUTexture && other)
inlinenoexcept

Move-assignment; releases current resources then steals from the other.

Definition at line 47 of file gpu-texture.h.


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