Skip to content
modkitv0.2

layout.h

#include <modkit/layout.h>18 functions · 2 structs · 4 enums · 6 typedefs

Vertex layout abstraction.

Vertex layout description for GPU buffers. For low-level GPU interop, include modkit.h for the mk_layout_get_bgfx() escape hatch accessor.

Functions

mk_layout_addfunction

mk_layout_t * mk_layout_add(mk_layout_t *layout, mk_attrib_t attrib, uint8_t count, mk_attrib_type_t type, bool normalized)

Add attribute to vertex layout.

ParameterTypeDescription
layoutmk_layout_t *Layout being built
attribmk_attrib_tAttribute semantic (position, color, etc)
countuint8_tNumber of components (1-4)
typemk_attrib_type_tComponent type (float, uint8, etc)
normalizedboolWhether to normalize integer types to [0,1] or [-1,1]

Returns Pointer to layout for chaining

mk_layout_beginfunction

void mk_layout_begin(mk_layout_t *layout)

Begin vertex layout definition.

ParameterTypeDescription
layoutmk_layout_t *Pointer to layout to initialize

mk_layout_convertfunction

void mk_layout_convert(const mk_layout_t *dst_layout, void *dst_data, const mk_layout_t *src_layout, const void *src_data, uint32_t num)

Convert num vertices from src_layout/src_data into dst_layout/dst_data (e.g.

importing a mesh into a GPU layout). Buffers must hold num*stride bytes.

ParameterTypeDescription
dst_layoutconst mk_layout_t *Value for dst layout.
dst_datavoid *Value for dst data.
src_layoutconst mk_layout_t *Value for src layout.
src_dataconst void *Value for src data.
numuint32_tValue for num.

mk_layout_decodefunction

void mk_layout_decode(const mk_layout_t *layout, mk_attrib_t attrib, uint8_t *count, mk_attrib_type_t *type, bool *normalized, bool *as_int)

Decode an attribute's element count / type / normalized / as-int from a layout.

Any out pointer may be NULL.

ParameterTypeDescription
layoutconst mk_layout_t *Value for layout.
attribmk_attrib_tValue for attrib.
countuint8_t *Number of entries.
typemk_attrib_type_t *Value for type.
normalizedbool *Value for normalized.
as_intbool *Value for as int.

mk_layout_endfunction

void mk_layout_end(mk_layout_t *layout)

End vertex layout definition.

ParameterTypeDescription
layoutmk_layout_t *Layout to finalize

mk_layout_hasfunction

bool mk_layout_has(const mk_layout_t *layout, mk_attrib_t attrib)

Whether the layout contains the given attribute.

ParameterTypeDescription
layoutconst mk_layout_t *Value for layout.
attribmk_attrib_tValue for attrib.

Returns True when the operation succeeds.

mk_layout_packfunction

void mk_layout_pack(const float input[4], bool input_normalized, mk_attrib_t attrib, const mk_layout_t *layout, void *data, uint32_t index)

Pack an attribute (input is xyzw as floats) into vertex index of data according to layout.

input_normalized=true means input is already in [0,1]/[-1,1].

ParameterTypeDescription
inputconst floatValue for input.
input_normalizedboolValue for input normalized.
attribmk_attrib_tValue for attrib.
layoutconst mk_layout_t *Value for layout.
datavoid *Data buffer.
indexuint32_tZero-based index.

mk_layout_posfunction

mk_layout_t mk_layout_pos(void)

Get underlying GPU layout (escape hatch).

Only available when modkit.h is included. Create layout for position only (3 floats).

Returns The resulting handle or value.

mk_layout_pos_colorfunction

mk_layout_t mk_layout_pos_color(void)

Create layout for position + color (3 floats + 4 uint8 normalized).

Returns The resulting handle or value.

mk_layout_pos_color_barycentricfunction

mk_layout_t mk_layout_pos_color_barycentric(void)

Create layout for position + color + barycentric (for wireframe rendering).

Vertex format: float x, y, z; uint32_t abgr; float bx, by, bz;

Returns The resulting handle or value.

mk_layout_pos_color_texcoordfunction

mk_layout_t mk_layout_pos_color_texcoord(void)

Create layout for position + color + texcoord.

Returns The resulting handle or value.

mk_layout_pos_texcoordfunction

mk_layout_t mk_layout_pos_texcoord(void)

Create layout for position + texcoord (3 floats + 2 floats).

Returns The resulting handle or value.

mk_layout_pos_uv_colorfunction

mk_layout_t mk_layout_pos_uv_color(void)

Create layout for position + texcoord + color (for 2D sprites).

Returns The resulting handle or value.

mk_layout_skipfunction

mk_layout_t * mk_layout_skip(mk_layout_t *layout, uint8_t bytes)

Skip bytes in vertex layout (for padding/alignment).

ParameterTypeDescription
layoutmk_layout_t *Layout being built
bytesuint8_tNumber of bytes to skip

Returns Pointer to layout for chaining

mk_layout_stridefunction

uint16_t mk_layout_stride(const mk_layout_t *layout)

Get stride (bytes per vertex) of layout.

ParameterTypeDescription
layoutconst mk_layout_t *Value for layout.

Returns The resulting value.

mk_layout_unpackfunction

void mk_layout_unpack(float output[4], mk_attrib_t attrib, const mk_layout_t *layout, const void *data, uint32_t index)

Unpack an attribute from vertex index of data into output (xyzw floats).

ParameterTypeDescription
outputfloatValue for output.
attribmk_attrib_tValue for attrib.
layoutconst mk_layout_t *Value for layout.
dataconst void *Data buffer.
indexuint32_tZero-based index.

mk_topology_convertfunction

uint32_t mk_topology_convert(mk_topology_convert_t conversion, void *dst, uint32_t dst_size, const void *indices, uint32_t num_indices, bool index32)

Convert an index buffer between topologies (e.g.

tri-list -> line-list for wireframe, or flip winding). Pass dst=NULL, dst_size=0 to query the required destination index count. Returns the number of destination indices.

ParameterTypeDescription
conversionmk_topology_convert_tValue for conversion.
dstvoid *Value for dst.
dst_sizeuint32_tDst size in bytes.
indicesconst void *Value for indices.
num_indicesuint32_tValue for num indices.
index32boolValue for index32.

Returns The resulting value.

mk_topology_sort_tri_listfunction

void mk_topology_sort_tri_list(mk_topology_sort_t sort, void *dst, uint32_t dst_size, const float dir[3], const float pos[3], const void *vertices, uint32_t stride, const void *indices, uint32_t num_indices, bool index32)

Sort a triangle-list index buffer back-to-front (or front-to-back) for a given view direction/position.

dst must hold num_indices indices.

ParameterTypeDescription
sortmk_topology_sort_tValue for sort.
dstvoid *Value for dst.
dst_sizeuint32_tDst size in bytes.
dirconst floatValue for dir.
posconst floatValue for pos.
verticesconst void *Value for vertices.
strideuint32_tValue for stride.
indicesconst void *Value for indices.
num_indicesuint32_tValue for num indices.
index32boolValue for index32.

Structs

mk_layoutstruct

Data for layout.

FieldTypeDescription
_internalmk_layout_data_tThe internal.

mk_layout_datastruct

Internal layout data (matches GPU backend ABI).

FieldTypeDescription
_hashuint32_tThe hash.
strideuint16_tThe stride.
_offsetuint16_tThe offset.
_attribsuint16_tThe attribs.

Enums

mk_attribenum

Values for attrib.

ValueDescription
MK_ATTRIB_POSITIONSelects position.
MK_ATTRIB_NORMALSelects normal.
MK_ATTRIB_TANGENTSelects tangent.
MK_ATTRIB_BITANGENTSelects bitangent.
MK_ATTRIB_COLOR0Selects color0.
MK_ATTRIB_COLOR1Selects color1.
MK_ATTRIB_COLOR2Selects color2.
MK_ATTRIB_COLOR3Selects color3.
MK_ATTRIB_INDICESSelects indices.
MK_ATTRIB_WEIGHTSelects weight.
MK_ATTRIB_TEXCOORD0Selects texcoord0.
MK_ATTRIB_TEXCOORD1Selects texcoord1.
MK_ATTRIB_TEXCOORD2Selects texcoord2.
MK_ATTRIB_TEXCOORD3Selects texcoord3.
MK_ATTRIB_TEXCOORD4Selects texcoord4.
MK_ATTRIB_TEXCOORD5Selects texcoord5.
MK_ATTRIB_TEXCOORD6Selects texcoord6.
MK_ATTRIB_TEXCOORD7Selects texcoord7.
MK_ATTRIB_TEXCOORD8Selects texcoord8.
MK_ATTRIB_TEXCOORD9Selects texcoord9.
MK_ATTRIB_TEXCOORD10Selects texcoord10.
MK_ATTRIB_TEXCOORD11Selects texcoord11.
MK_ATTRIB_TEXCOORD12Selects texcoord12.
MK_ATTRIB_TEXCOORD13Selects texcoord13.
MK_ATTRIB_TEXCOORD14Selects texcoord14.
MK_ATTRIB_TEXCOORD15Selects texcoord15.
MK_ATTRIB_COUNTSelects count.

mk_attrib_typeenum

Values for attrib type.

ValueDescription
MK_ATTRIB_TYPE_INT8Selects int8.
MK_ATTRIB_TYPE_UINT8Selects uint8.
MK_ATTRIB_TYPE_UINT10Selects uint10.
MK_ATTRIB_TYPE_INT16Selects int16.
MK_ATTRIB_TYPE_UINT16Selects uint16.
MK_ATTRIB_TYPE_HALFSelects half.
MK_ATTRIB_TYPE_FLOATSelects float.
MK_ATTRIB_TYPE_INT32Selects int32.
MK_ATTRIB_TYPE_UINT32Selects uint32.
MK_ATTRIB_TYPE_COUNTSelects count.

mk_topology_convertenum

Values for topology convert.

ValueDescription
MK_TOPOLOGY_CONVERT_TRI_LIST_FLIP_WINDINGSelects tri list flip winding.
MK_TOPOLOGY_CONVERT_TRI_STRIP_FLIP_WINDINGSelects tri strip flip winding.
MK_TOPOLOGY_CONVERT_TRI_LIST_TO_LINE_LISTSelects tri list to line list.
MK_TOPOLOGY_CONVERT_TRI_STRIP_TO_TRI_LISTSelects tri strip to tri list.
MK_TOPOLOGY_CONVERT_LINE_STRIP_TO_LINE_LISTSelects line strip to line list.

mk_topology_sortenum

Values for topology sort.

ValueDescription
MK_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MINSelects direction front to back min.
MK_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_AVGSelects direction front to back avg.
MK_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MAXSelects direction front to back max.
MK_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MINSelects direction back to front min.
MK_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_AVGSelects direction back to front avg.
MK_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MAXSelects direction back to front max.
MK_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MINSelects distance front to back min.
MK_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_AVGSelects distance front to back avg.
MK_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MAXSelects distance front to back max.
MK_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MINSelects distance back to front min.
MK_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_AVGSelects distance back to front avg.
MK_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MAXSelects distance back to front max.

Typedefs

mk_attrib_ttypedef

typedef enum mk_attrib mk_attrib_t

Values for attrib.

mk_attrib_type_ttypedef

typedef enum mk_attrib_type mk_attrib_type_t

Values for attrib type.

mk_layout_data_ttypedef

typedef struct mk_layout_data mk_layout_data_t

Internal layout data (matches GPU backend ABI).

mk_layout_ttypedef

typedef struct mk_layout mk_layout_t

Data for layout.

mk_topology_convert_ttypedef

typedef enum mk_topology_convert mk_topology_convert_t

Values for topology convert.

mk_topology_sort_ttypedef

typedef enum mk_topology_sort mk_topology_sort_t

Values for topology sort.