ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
Buffer Struct Reference

An SDL_GPUBuffer (vertex, index, indirect, storage, etc.) and its metadata. More...

#include <Buffer.h>

Inheritance diagram for Buffer:

Public Member Functions

BufferinitWithConstMem (Buffer *self, RenderDevice *device, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size)
 Initializes this Buffer and uploads mem in a single call.
 
BufferinitWithData (Buffer *self, RenderDevice *device, SDL_GPUBufferUsageFlags usage, const Data *data)
 Initializes this Buffer and uploads the contents of an Objectively Data.
 
BufferinitWithDevice (Buffer *self, RenderDevice *device, const SDL_GPUBufferCreateInfo *info)
 Initializes this Buffer, creating its SDL_GPUBuffer.
 
void setName (Buffer *self, const char *name)
 Assigns a debug label to this buffer, visible in GPU capture tools.
 
void upload (Buffer *self, const void *data, Uint32 size, Uint32 offset, bool cycle)
 Uploads raw CPU data into this buffer.
 
Class * _Buffer (void)
 The Buffer archetype.
 

Data Fields

Object object
 The superclass.
 
SDL_GPUBuffer * buffer
 The underlying SDL buffer.
 
SDL_GPUBufferUsageFlags usage
 The usage flags the buffer was created with.
 
Uint32 size
 The size of the buffer, in bytes.
 
ident data
 User data.
 

Protected Attributes

BufferInterface * interface
 The interface.
 

Detailed Description

An SDL_GPUBuffer (vertex, index, indirect, storage, etc.) and its metadata.

Buffer owns its underlying SDL_GPUBuffer and releases it in dealloc, so a Buffer is freed with release like any other Objectively object — there is no separate device-level release call:

Buffer *vertices = $(renderDevice, createBufferWithConstMem,
SDL_GPU_BUFFERUSAGE_VERTEX, data, sizeof(data));
$(pass, bindVertexBuffers, 0, &(SDL_GPUBufferBinding) { .buffer = vertices->buffer }, 1);
release(vertices);
static Buffer * createBufferWithConstMem(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size)
Definition RenderDevice.c:228
static void bindVertexBuffers(const RenderPass *self, Uint32 firstSlot, const SDL_GPUBufferBinding *bindings, Uint32 num)
Definition RenderPass.c:103
An SDL_GPUBuffer (vertex, index, indirect, storage, etc.) and its metadata.
Definition Buffer.h:60
SDL_GPUBuffer * buffer
The underlying SDL buffer.
Definition Buffer.h:76
ident data
User data.
Definition Buffer.h:97

Use upload to re-populate a dynamic buffer (sprites, UI, particles) each frame.

Member Function Documentation

◆ _Buffer()

Class * _Buffer ( void  )

The Buffer archetype.

Returns
The Buffer Class.

◆ initWithConstMem()

Buffer * initWithConstMem ( Buffer self,
RenderDevice device,
SDL_GPUBufferUsageFlags  usage,
const void *  mem,
Uint32  size 
)

Initializes this Buffer and uploads mem in a single call.

Convenience initializer that creates a buffer sized to size via initWithDevice, then uploads mem with upload. The returned buffer is immediately GPU-resident.

Parameters
selfThe Buffer.
deviceThe RenderDevice used to create and release the buffer. Retained.
usageBuffer usage flags (e.g. SDL_GPU_BUFFERUSAGE_VERTEX).
memCPU pointer to the source data. Must not be NULL.
sizeNumber of bytes to allocate and upload.
Returns
The initialized Buffer, or NULL on failure.

◆ initWithData()

Buffer * initWithData ( Buffer self,
RenderDevice device,
SDL_GPUBufferUsageFlags  usage,
const Data *  data 
)

Initializes this Buffer and uploads the contents of an Objectively Data.

Convenience initializer over initWithConstMem for data loaded via the Objectively Resource system.

Parameters
selfThe Buffer.
deviceThe RenderDevice used to create and release the buffer. Retained.
usageBuffer usage flags (e.g. SDL_GPU_BUFFERUSAGE_VERTEX).
dataSource data object. Must not be NULL.
Returns
The initialized Buffer, or NULL on failure.

◆ initWithDevice()

Buffer * initWithDevice ( Buffer self,
RenderDevice device,
const SDL_GPUBufferCreateInfo *  info 
)

Initializes this Buffer, creating its SDL_GPUBuffer.

This is the designated initializer. The buffer's contents are uninitialised; use upload to populate it.

Parameters
selfThe Buffer.
deviceThe RenderDevice used to create and release the buffer. Retained.
infoBuffer creation parameters (usage flags, size).
Returns
The initialized Buffer, or NULL on failure.

◆ setName()

void setName ( Buffer self,
const char *  name 
)

Assigns a debug label to this buffer, visible in GPU capture tools.

Parameters
selfThe Buffer.
nameA null-terminated debug name string.

◆ upload()

void upload ( Buffer self,
const void *  data,
Uint32  size,
Uint32  offset,
bool  cycle 
)

Uploads raw CPU data into this buffer.

Acquires a command buffer, creates a temporary transfer buffer, records a copy pass, submits, and releases the transfer buffer. Use this for dynamic buffers re-uploaded each frame. To batch multiple uploads into one command buffer, use CopyPass::uploadData instead.

Parameters
selfThe Buffer.
dataCPU pointer to the source data. Must not be NULL.
sizeNumber of bytes to upload.
offsetByte offset into this buffer where the data is written.
cycleWhen true, the buffer is cycled to avoid pipeline stalls.

Field Documentation

◆ buffer

SDL_GPUBuffer* Buffer::buffer

The underlying SDL buffer.

◆ data

ident Buffer::data

User data.

◆ interface

BufferInterface* Buffer::interface
protected

The interface.

◆ object

Object Buffer::object

The superclass.

◆ size

Uint32 Buffer::size

The size of the buffer, in bytes.

◆ usage

SDL_GPUBufferUsageFlags Buffer::usage

The usage flags the buffer was created with.


The documentation for this struct was generated from the following files: