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.
| Parameter | Type | Description |
|---|
layout | mk_layout_t * | Layout being built |
attrib | mk_attrib_t | Attribute semantic (position, color, etc) |
count | uint8_t | Number of components (1-4) |
type | mk_attrib_type_t | Component type (float, uint8, etc) |
normalized | bool | Whether 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.
| Parameter | Type | Description |
|---|
layout | mk_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.
| Parameter | Type | Description |
|---|
dst_layout | const mk_layout_t * | Value for dst layout. |
dst_data | void * | Value for dst data. |
src_layout | const mk_layout_t * | Value for src layout. |
src_data | const void * | Value for src data. |
num | uint32_t | Value 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.
| Parameter | Type | Description |
|---|
layout | const mk_layout_t * | Value for layout. |
attrib | mk_attrib_t | Value for attrib. |
count | uint8_t * | Number of entries. |
type | mk_attrib_type_t * | Value for type. |
normalized | bool * | Value for normalized. |
as_int | bool * | Value for as int. |
mk_layout_endfunction
void mk_layout_end(mk_layout_t *layout)
End vertex layout definition.
| Parameter | Type | Description |
|---|
layout | mk_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.
| Parameter | Type | Description |
|---|
layout | const mk_layout_t * | Value for layout. |
attrib | mk_attrib_t | Value 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].
| Parameter | Type | Description |
|---|
input | const float | Value for input. |
input_normalized | bool | Value for input normalized. |
attrib | mk_attrib_t | Value for attrib. |
layout | const mk_layout_t * | Value for layout. |
data | void * | Data buffer. |
index | uint32_t | Zero-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).
| Parameter | Type | Description |
|---|
layout | mk_layout_t * | Layout being built |
bytes | uint8_t | Number 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.
| Parameter | Type | Description |
|---|
layout | const 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).
| Parameter | Type | Description |
|---|
output | float | Value for output. |
attrib | mk_attrib_t | Value for attrib. |
layout | const mk_layout_t * | Value for layout. |
data | const void * | Data buffer. |
index | uint32_t | Zero-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.
| Parameter | Type | Description |
|---|
conversion | mk_topology_convert_t | Value for conversion. |
dst | void * | Value for dst. |
dst_size | uint32_t | Dst size in bytes. |
indices | const void * | Value for indices. |
num_indices | uint32_t | Value for num indices. |
index32 | bool | Value 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.
| Parameter | Type | Description |
|---|
sort | mk_topology_sort_t | Value for sort. |
dst | void * | Value for dst. |
dst_size | uint32_t | Dst size in bytes. |
dir | const float | Value for dir. |
pos | const float | Value for pos. |
vertices | const void * | Value for vertices. |
stride | uint32_t | Value for stride. |
indices | const void * | Value for indices. |
num_indices | uint32_t | Value for num indices. |
index32 | bool | Value for index32. |