Skip to content
modkitv0.2

dynbuffer.h

#include <modkit/dynbuffer.h>24 functions · 6 structs · 1 enums · 5 typedefs · 2 macros

Dynamic, transient, and instance buffer abstractions.

Extends the static buffer API with:Dynamic buffers: Persistent buffers that can be updated each frameTransient buffers: Frame-scoped temporary buffers (auto-reclaimed)Instance buffers: Per-instance data for instanced rendering Use cases:Dynamic: Particle systems, skeletal animation, streaming geometryTransient: Immediate-mode rendering, debug drawing, UIInstance: Rendering many objects with per-instance transforms/colors Example (transient buffer for immediate drawing):

Functions

mk_dibuf_createfunction

mk_dibuf_t mk_dibuf_create(uint32_t index_count, uint16_t flags)

Create empty dynamic index buffer (16-bit indices).

ParameterTypeDescription
index_countuint32_tMaximum number of indices
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic index buffer handle or MK_DIBUF_INVALID on failure

mk_dibuf_create_datafunction

mk_dibuf_t mk_dibuf_create_data(const uint16_t *data, uint32_t count, uint16_t flags)

Create dynamic index buffer with initial data (16-bit).

ParameterTypeDescription
dataconst uint16_t *Initial index data (copied)
countuint32_tNumber of indices
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic index buffer handle or MK_DIBUF_INVALID on failure

mk_dibuf_create_data32function

mk_dibuf_t mk_dibuf_create_data32(const uint32_t *data, uint32_t count, uint16_t flags)

Create dynamic index buffer with initial data (32-bit).

ParameterTypeDescription
dataconst uint32_t *Initial index data (copied)
countuint32_tNumber of indices
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic index buffer handle or MK_DIBUF_INVALID on failure

mk_dibuf_create32function

mk_dibuf_t mk_dibuf_create32(uint32_t index_count, uint16_t flags)

Create empty dynamic index buffer (32-bit indices).

ParameterTypeDescription
index_countuint32_tMaximum number of indices
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic index buffer handle or MK_DIBUF_INVALID on failure

mk_dibuf_destroyfunction

void mk_dibuf_destroy(mk_dibuf_t dibuf)

Get underlying GPU handle (escape hatch requires modkit.h).

Destroy dynamic index buffer.

ParameterTypeDescription
dibufmk_dibuf_tValue for dibuf.

mk_dibuf_is_validfunction

bool mk_dibuf_is_valid(mk_dibuf_t dibuf)

Check if dynamic index buffer handle is valid.

ParameterTypeDescription
dibufmk_dibuf_tValue for dibuf.

Returns True when the condition holds.

mk_dibuf_updatefunction

void mk_dibuf_update(mk_dibuf_t dibuf, uint32_t start_index, const uint16_t *data, uint32_t count)

Update dynamic index buffer contents (16-bit).

ParameterTypeDescription
dibufmk_dibuf_tDynamic index buffer handle
start_indexuint32_tFirst index to update
dataconst uint16_t *New index data
countuint32_tNumber of indices

mk_dibuf_update32function

void mk_dibuf_update32(mk_dibuf_t dibuf, uint32_t start_index, const uint32_t *data, uint32_t count)

Update dynamic index buffer contents (32-bit).

ParameterTypeDescription
dibufmk_dibuf_tDynamic index buffer handle
start_indexuint32_tFirst index to update
dataconst uint32_t *New index data
countuint32_tNumber of indices

mk_dvbuf_createfunction

mk_dvbuf_t mk_dvbuf_create(uint32_t vertex_count, const mk_layout_t *layout, uint16_t flags)

Create empty dynamic vertex buffer.

ParameterTypeDescription
vertex_countuint32_tMaximum number of vertices
layoutconst mk_layout_t *Vertex layout
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic vertex buffer handle or MK_DVBUF_INVALID on failure

mk_dvbuf_create_datafunction

mk_dvbuf_t mk_dvbuf_create_data(const void *data, uint32_t size, const mk_layout_t *layout, uint16_t flags)

Create dynamic vertex buffer with initial data.

ParameterTypeDescription
dataconst void *Initial vertex data (copied)
sizeuint32_tSize of data in bytes
layoutconst mk_layout_t *Vertex layout
flagsuint16_tMK_DYNBUF_* flags

Returns Dynamic vertex buffer handle or MK_DVBUF_INVALID on failure

mk_dvbuf_destroyfunction

void mk_dvbuf_destroy(mk_dvbuf_t dvbuf)

Get underlying GPU handle (escape hatch requires modkit.h).

Destroy dynamic vertex buffer.

ParameterTypeDescription
dvbufmk_dvbuf_tValue for dvbuf.

mk_dvbuf_is_validfunction

bool mk_dvbuf_is_valid(mk_dvbuf_t dvbuf)

Check if dynamic vertex buffer handle is valid.

ParameterTypeDescription
dvbufmk_dvbuf_tValue for dvbuf.

Returns True when the condition holds.

mk_dvbuf_updatefunction

void mk_dvbuf_update(mk_dvbuf_t dvbuf, uint32_t start_vertex, const void *data, uint32_t size)

Update dynamic vertex buffer contents.

If MK_DYNBUF_ALLOW_RESIZE is set and data exceeds buffer size, buffer will grow.

ParameterTypeDescription
dvbufmk_dvbuf_tDynamic vertex buffer handle
start_vertexuint32_tFirst vertex to update
dataconst void *New vertex data
sizeuint32_tSize of data in bytes

mk_dynbuffer_system_initfunction

void mk_dynbuffer_system_init(void)

Initialize the dynbuffer system.

mk_dynbuffer_system_shutdownfunction

void mk_dynbuffer_system_shutdown(void)

Perform the dynbuffer system shutdown operation.

mk_instance_allocfunction

bool mk_instance_alloc(mk_instance_buf_t *ibuf, uint32_t count, uint16_t stride)

Allocate instance data buffer.

Buffer is valid only for the current frame.

ParameterTypeDescription
ibufmk_instance_buf_t *Output instance buffer struct
countuint32_tNumber of instances
strideuint16_tBytes per instance (must be multiple of 16)

Returns true on success

mk_instance_availfunction

bool mk_instance_avail(uint32_t count, uint16_t stride)

Check if instance buffer allocation is possible.

ParameterTypeDescription
countuint32_tNumber of instances
strideuint16_tBytes per instance (must be multiple of 16)

Returns true if allocation would succeed

mk_tibuf_allocfunction

bool mk_tibuf_alloc(mk_tibuf_t *tibuf, uint32_t count)

Allocate transient index buffer (16-bit indices).

Buffer is valid only for the current frame.

ParameterTypeDescription
tibufmk_tibuf_t *Output transient buffer struct
countuint32_tNumber of indices

Returns true on success, false if not enough transient memory

mk_tibuf_alloc32function

bool mk_tibuf_alloc32(mk_tibuf32_t *tibuf, uint32_t count)

Allocate transient index buffer (32-bit indices).

ParameterTypeDescription
tibufmk_tibuf32_t *Output transient buffer struct
countuint32_tNumber of indices

Returns true on success, false if not enough transient memory

mk_tibuf_availfunction

bool mk_tibuf_avail(uint32_t count, bool is_32bit)

Check if transient index buffer allocation is possible.

ParameterTypeDescription
countuint32_tNumber of indices needed
is_32bitbooltrue for 32-bit indices, false for 16-bit

Returns true if allocation would succeed

mk_transient_allocfunction

bool mk_transient_alloc(mk_tvbuf_t *tvbuf, uint32_t vertex_count, const mk_layout_t *layout, mk_tibuf_t *tibuf, uint32_t index_count)

Allocate both vertex and index transient buffers atomically.

Either both succeed or both fail.

ParameterTypeDescription
tvbufmk_tvbuf_t *Output transient vertex buffer
vertex_countuint32_tNumber of vertices
layoutconst mk_layout_t *Vertex layout
tibufmk_tibuf_t *Output transient index buffer (16-bit)
index_countuint32_tNumber of indices

Returns true on success

mk_transient_availfunction

bool mk_transient_avail(uint32_t vertex_count, const mk_layout_t *layout, uint32_t index_count, bool is_index_32bit)

Check if both vertex and index transient buffers can be allocated atomically.

ParameterTypeDescription
vertex_countuint32_tNumber of vertices
layoutconst mk_layout_t *Vertex layout
index_countuint32_tNumber of indices
is_index_32bitbooltrue for 32-bit indices

Returns true if both allocations would succeed

mk_tvbuf_allocfunction

bool mk_tvbuf_alloc(mk_tvbuf_t *tvbuf, uint32_t count, const mk_layout_t *layout)

Allocate transient vertex buffer.

Buffer is valid only for the current frame.

ParameterTypeDescription
tvbufmk_tvbuf_t *Output transient buffer struct
countuint32_tNumber of vertices
layoutconst mk_layout_t *Vertex layout

Returns true on success, false if not enough transient memory

mk_tvbuf_availfunction

bool mk_tvbuf_avail(uint32_t count, const mk_layout_t *layout)

Check if transient vertex buffer allocation is possible.

ParameterTypeDescription
countuint32_tNumber of vertices needed
layoutconst mk_layout_t *Vertex layout

Returns true if allocation would succeed

Structs

mk_dibuf_tstruct

Data for dibuf.

FieldTypeDescription
iduint32_tThe ID.

mk_dvbuf_tstruct

Data for dvbuf.

FieldTypeDescription
iduint32_tThe ID.

mk_instance_bufstruct

Instance data buffer.

Per-instance data for instanced rendering. Stride must be multiple of 16.

FieldTypeDescription
datavoid *CPU-writable instance data.
countuint32_tNumber of instances.
strideuint16_tBytes per instance (multiple of 16).
_internalunion mk_instance_buf::@365225262327344304125045337276011011335066021305Internal do not access.
_internal._alignvoid *The align.
_internal._opaqueuint8_tThe opaque.

mk_tibufstruct

Transient index buffer.

Valid only for the current frame. Indices are 16-bit.

FieldTypeDescription
datauint16_t *CPU-writable index data (16-bit).
countuint32_tNumber of indices allocated.
_internalunion mk_tibuf::@226146376246123362237165171363065375320222344271Internal do not access.
_internal._alignvoid *The align.
_internal._opaqueuint8_tThe opaque.

mk_tibuf32struct

Transient index buffer (32-bit indices).

FieldTypeDescription
datauint32_t *CPU-writable index data (32-bit).
countuint32_tNumber of indices allocated.
_internalunion mk_tibuf32::@376274157360050201207120053063225054355364177344Internal do not access.
_internal._alignvoid *The align.
_internal._opaqueuint8_tThe opaque.

mk_tvbufstruct

Transient vertex buffer.

Valid only for the current frame. Data pointer can be written directly.

FieldTypeDescription
datavoid *CPU-writable vertex data.
sizeuint32_tSize in bytes.
countuint32_tNumber of vertices allocated.
_internalunion mk_tvbuf::@071177170151334233015227041315140243164116124022Internal do not access.
_internal._alignvoid *The align.
_internal._opaqueuint8_tThe opaque.

Enums

mk_dynbuf_flagsenum

Dynamic buffer flags.

ValueDescription
MK_DYNBUF_NONESelects none.
MK_DYNBUF_COMPUTE_READAllow compute shader read.
MK_DYNBUF_COMPUTE_WRITEAllow compute shader write.
MK_DYNBUF_ALLOW_RESIZEAllow buffer to grow on update.

Typedefs

mk_dynbuf_flags_ttypedef

typedef enum mk_dynbuf_flags mk_dynbuf_flags_t

Dynamic buffer flags.

mk_instance_buf_ttypedef

typedef struct mk_instance_buf mk_instance_buf_t

Instance data buffer.

Per-instance data for instanced rendering. Stride must be multiple of 16.

mk_tibuf_ttypedef

typedef struct mk_tibuf mk_tibuf_t

Transient index buffer.

Valid only for the current frame. Indices are 16-bit.

mk_tibuf32_ttypedef

typedef struct mk_tibuf32 mk_tibuf32_t

Transient index buffer (32-bit indices).

mk_tvbuf_ttypedef

typedef struct mk_tvbuf mk_tvbuf_t

Transient vertex buffer.

Valid only for the current frame. Data pointer can be written directly.

Macros

MK_DIBUF_INVALIDdefine

MK_DIBUF_INVALID

Invalid sentinel for dibuf.

MK_DVBUF_INVALIDdefine

MK_DVBUF_INVALID

Invalid sentinel for dvbuf.