Skip to content
modkitv0.2

geometry.h

#include <modkit/geometry.h>37 functions · 13 structs · 1 enums · 13 typedefs · 1 macros

Reusable shape geometry (the three.js BufferGeometry analog).

A geometry is a reusable shape: a vertex buffer (+ optional index buffer), its layout, counts, and topology. It is decoupled from how it's shaded pair any geometry with any pipeline/material and a transform via mk_draw_desc/mk_mesh. Two layers:Low-level builders (mk_*_sizes / mk_*_build): the single source of truth for primitive shape math. They fill caller-owned arrays (sokol_shape style), so they're allocation-agnostic and reusable the draw3d immediate API and the high-level constructors below both call these.High-level handles (mk_geometry_create + mk_geometry_box/sphere/...): upload a built shape to a GPU buffer and hand back a reusable mk_geometry_t. Generator vertex format (mk_geometry_vertex / mk_geometry_vertex_layout): POSITION f32x3, NORMAL f32x3, TANGENT f32x4, TEXCOORD0 f32x2, TEXCOORD1 f32x2, COLOR0 u8x4 normalized. One format serves the unlit, lit, and PBR materials. The tangent (xyz + sign in .w) is for normal mapping; primitive builders fill it (mk_geometry_create computes it for the built-in shapes), the model loader supplies glTF/MikkTSpace tangents. TEXCOORD1 (u1,v1) is a second UV set for KHR_texture_transform maps authored on UV1 (e.g. a baked occlusion atlas); primitive builders default it to (u,v) only the glTF loader ever fills it with real second-UV-set data.

Functions

mk_box_buildfunction

mk_geometry_counts mk_box_build(const mk_box_params *, mk_geometry_buffer *)

Build box.

ParameterTypeDescription
const mk_box_params *
mk_geometry_buffer *

Returns The resulting value.

mk_box_sizesfunction

mk_geometry_counts mk_box_sizes(const mk_box_params *)

Perform the box sizes operation.

ParameterTypeDescription
const mk_box_params *

Returns The resulting value.

mk_capsule_buildfunction

mk_geometry_counts mk_capsule_build(const mk_capsule_params *, mk_geometry_buffer *)

Build capsule.

ParameterTypeDescription
const mk_capsule_params *
mk_geometry_buffer *

Returns The resulting value.

mk_capsule_sizesfunction

mk_geometry_counts mk_capsule_sizes(const mk_capsule_params *)

Perform the capsule sizes operation.

ParameterTypeDescription
const mk_capsule_params *

Returns The resulting value.

mk_cone_buildfunction

mk_geometry_counts mk_cone_build(const mk_cone_params *, mk_geometry_buffer *)

Build cone.

ParameterTypeDescription
const mk_cone_params *
mk_geometry_buffer *

Returns The resulting value.

mk_cone_sizesfunction

mk_geometry_counts mk_cone_sizes(const mk_cone_params *)

Perform the cone sizes operation.

ParameterTypeDescription
const mk_cone_params *

Returns The resulting value.

mk_cylinder_buildfunction

mk_geometry_counts mk_cylinder_build(const mk_cylinder_params *, mk_geometry_buffer *)

Build cylinder.

ParameterTypeDescription
const mk_cylinder_params *
mk_geometry_buffer *

Returns The resulting value.

mk_cylinder_sizesfunction

mk_geometry_counts mk_cylinder_sizes(const mk_cylinder_params *)

Perform the cylinder sizes operation.

ParameterTypeDescription
const mk_cylinder_params *

Returns The resulting value.

mk_geometry_applyfunction

void mk_geometry_apply(mk_geometry_t, struct mk_draw_desc *out)

Apply geometry.

ParameterTypeDescription
mk_geometry_t
outstruct mk_draw_desc *Value for out.

mk_geometry_boundsfunction

bool mk_geometry_bounds(mk_geometry_t, mk_aabb *out_bounds)

Perform the geometry bounds operation.

ParameterTypeDescription
mk_geometry_t
out_boundsmk_aabb *Receives the bounds.

Returns True when the operation succeeds.

mk_geometry_boxfunction

mk_geometry_t mk_geometry_box(const mk_box_params *)

Primitive constructors build + upload, return a static geometry.

ParameterTypeDescription
const mk_box_params *

Returns The resulting handle or value.

mk_geometry_capsulefunction

mk_geometry_t mk_geometry_capsule(const mk_capsule_params *)

Perform the geometry capsule operation.

ParameterTypeDescription
const mk_capsule_params *

Returns The resulting handle or value.

mk_geometry_conefunction

mk_geometry_t mk_geometry_cone(const mk_cone_params *)

Perform the geometry cone operation.

ParameterTypeDescription
const mk_cone_params *

Returns The resulting handle or value.

mk_geometry_createfunction

mk_geometry_t mk_geometry_create(const mk_geometry_desc *desc)

Create a static geometry from raw data.

ParameterTypeDescription
descconst mk_geometry_desc *Configuration descriptor.

Returns The resulting handle or value.

mk_geometry_cylinderfunction

mk_geometry_t mk_geometry_cylinder(const mk_cylinder_params *)

Perform the geometry cylinder operation.

ParameterTypeDescription
const mk_cylinder_params *

Returns The resulting handle or value.

mk_geometry_destroyfunction

void mk_geometry_destroy(mk_geometry_t)

Destroy the geometry.

ParameterTypeDescription
mk_geometry_t

mk_geometry_gridfunction

mk_geometry_t mk_geometry_grid(const mk_grid_params *)

Perform the geometry grid operation.

ParameterTypeDescription
const mk_grid_params *

Returns The resulting handle or value.

mk_geometry_index_countfunction

uint32_t mk_geometry_index_count(mk_geometry_t)

Perform the geometry index count operation.

ParameterTypeDescription
mk_geometry_t

Returns The resulting value.

mk_geometry_is_validfunction

bool mk_geometry_is_valid(mk_geometry_t g)

Test whether the geometry is valid.

ParameterTypeDescription
gmk_geometry_tValue for g.

Returns True when the condition holds.

mk_geometry_pinfunction

bool mk_geometry_pin(mk_geometry_t g)

Perform the geometry pin operation.

ParameterTypeDescription
gmk_geometry_tValue for g.

Returns True when the operation succeeds.

mk_geometry_planefunction

mk_geometry_t mk_geometry_plane(const mk_plane_params *)

Perform the geometry plane operation.

ParameterTypeDescription
const mk_plane_params *

Returns The resulting handle or value.

mk_geometry_spherefunction

mk_geometry_t mk_geometry_sphere(const mk_sphere_params *)

Perform the geometry sphere operation.

ParameterTypeDescription
const mk_sphere_params *

Returns The resulting handle or value.

mk_geometry_system_initfunction

void mk_geometry_system_init(void)

Initialize the geometry system.

mk_geometry_system_shutdownfunction

void mk_geometry_system_shutdown(void)

Perform the geometry system shutdown operation.

mk_geometry_topologyfunction

mk_topology_t mk_geometry_topology(mk_geometry_t)

Perform the geometry topology operation.

ParameterTypeDescription
mk_geometry_t

Returns The resulting handle or value.

mk_geometry_torusfunction

mk_geometry_t mk_geometry_torus(const mk_torus_params *)

Perform the geometry torus operation.

ParameterTypeDescription
const mk_torus_params *

Returns The resulting handle or value.

mk_geometry_unpinfunction

void mk_geometry_unpin(mk_geometry_t g)

Perform the geometry unpin operation.

ParameterTypeDescription
gmk_geometry_tValue for g.

mk_geometry_vertex_countfunction

uint32_t mk_geometry_vertex_count(mk_geometry_t)

Perform the geometry vertex count operation.

ParameterTypeDescription
mk_geometry_t

Returns The resulting value.

mk_geometry_vertex_layoutfunction

mk_layout_t mk_geometry_vertex_layout(void)

The layout the builders emit and the default 3D materials expect.

Returns The resulting handle or value.

mk_grid_buildfunction

mk_geometry_counts mk_grid_build(const mk_grid_params *, mk_geometry_buffer *)

Build grid.

ParameterTypeDescription
const mk_grid_params *
mk_geometry_buffer *

Returns The resulting value.

mk_grid_sizesfunction

mk_geometry_counts mk_grid_sizes(const mk_grid_params *)

Perform the grid sizes operation.

ParameterTypeDescription
const mk_grid_params *

Returns The resulting value.

mk_plane_buildfunction

mk_geometry_counts mk_plane_build(const mk_plane_params *, mk_geometry_buffer *)

Build plane.

ParameterTypeDescription
const mk_plane_params *
mk_geometry_buffer *

Returns The resulting value.

mk_plane_sizesfunction

mk_geometry_counts mk_plane_sizes(const mk_plane_params *)

Perform the plane sizes operation.

ParameterTypeDescription
const mk_plane_params *

Returns The resulting value.

mk_sphere_buildfunction

mk_geometry_counts mk_sphere_build(const mk_sphere_params *, mk_geometry_buffer *)

Build sphere.

ParameterTypeDescription
const mk_sphere_params *
mk_geometry_buffer *

Returns The resulting value.

mk_sphere_sizesfunction

mk_geometry_counts mk_sphere_sizes(const mk_sphere_params *)

Perform the sphere sizes operation.

ParameterTypeDescription
const mk_sphere_params *

Returns The resulting value.

mk_torus_buildfunction

mk_geometry_counts mk_torus_build(const mk_torus_params *, mk_geometry_buffer *)

Build torus.

ParameterTypeDescription
const mk_torus_params *
mk_geometry_buffer *

Returns The resulting value.

mk_torus_sizesfunction

mk_geometry_counts mk_torus_sizes(const mk_torus_params *)

Perform the torus sizes operation.

ParameterTypeDescription
const mk_torus_params *

Returns The resulting value.

Structs

mk_box_paramsstruct

Data for box params.

FieldTypeDescription
wfloatWidth; zero selects the unit default.
hfloatHeight; zero selects the unit default.
dfloatDepth; zero selects the unit default.
coloruint32_tRGBA color; zero selects opaque white.

mk_capsule_paramsstruct

Data for capsule params.

FieldTypeDescription
radiusfloatCap and body radius.
heightfloatTotal capsule height.
segmentsintRadial segments; zero selects the automatic default.
coloruint32_tRGBA color; zero selects opaque white.

mk_cone_paramsstruct

Data for cone params.

FieldTypeDescription
radiusfloatBase radius; zero selects the unit default.
heightfloatHeight; zero selects the unit default.
segmentsintRadial segments; zero selects the automatic default.
coloruint32_tRGBA color; zero selects opaque white.

mk_cylinder_paramsstruct

Data for cylinder params.

FieldTypeDescription
radiusfloatRadius; zero selects the unit default.
heightfloatHeight; zero selects the unit default.
segmentsintRadial segments; zero selects the automatic default.
coloruint32_tRGBA color; zero selects opaque white.

mk_geometry_bufferstruct

Data for geometry buffer.

FieldTypeDescription
verticesmk_geometry_vertex *caller-owned, >= counts.vertices
vertex_capuint32_tThe vertex cap.
indicesuint16_t *caller-owned, >= counts.indices
index_capuint32_tThe index cap.
base_vertexuint32_tadded to every emitted index

mk_geometry_countsstruct

Data for geometry counts.

FieldTypeDescription
verticesuint32_tNumber of vertices.
indicesuint32_tNumber of indices.

mk_geometry_descstruct

Data for geometry desc.

FieldTypeDescription
nameconst char *debug, NULL ok
verticesconst void *vertex bytes
vertex_sizeuint32_ttotal bytes
layoutconst mk_layout_t *NULL => mk_geometry_vertex_layout().
indicesconst uint16_t *NULL => non-indexed.
index_countuint32_tThe index count.
topologymk_topology_t0 => TRIANGLES
boundsconst mk_aabb *optional; default vertex format is computed

mk_geometry_tstruct

Data for geometry.

FieldTypeDescription
iduint32_tThe ID.

mk_geometry_vertexstruct

Data for geometry vertex.

FieldTypeDescription
xfloatPosition X coordinate.
yfloatPosition Y coordinate.
zfloatPosition Z coordinate.
nxfloatNormal X component.
nyfloatNormal Y component.
nzfloatNormal Z component.
txfloatTangent X component.
tyfloatTangent Y component.
tzfloatTangent Z component.
twfloatTangent handedness sign.
ufloatPrimary texture U coordinate.
vfloatPrimary texture V coordinate.
u1floatSecondary texture U coordinate; defaults to u when unavailable.
v1floatSecondary texture V coordinate; defaults to v when unavailable.
abgruint32_tPacked ABGR vertex color.

mk_grid_paramsstruct

Data for grid params.

FieldTypeDescription
sizefloatTotal grid width and depth.
divisionsintNumber of cells per axis.
coloruint32_tPacked RGBA line color.

mk_plane_paramsstruct

Data for plane params.

FieldTypeDescription
widthfloatWidth; zero selects the unit default.
depthfloatDepth; zero selects the unit default.
x_divintSubdivisions along X; zero selects the automatic default.
z_divintSubdivisions along Z; zero selects the automatic default.
coloruint32_tRGBA color; zero selects opaque white.

mk_sphere_paramsstruct

Data for sphere params.

FieldTypeDescription
radiusfloatThe radius.
segmentsintThe segments.
coloruint32_tThe color.

mk_torus_paramsstruct

Data for torus params.

FieldTypeDescription
major_rfloatDistance from the center to the tube center.
minor_rfloatTube radius.
major_segintSegments around the major ring.
minor_segintSegments around the tube.
coloruint32_tRGBA color; zero selects opaque white.

Enums

mk_topologyenum

Primitive topology.

Note: bgfx encodes topology in the pipeline STATE word (MK_STATE_PT_*), not the buffer this is advisory. A LINES geometry (grid) must be drawn with a lines-state pipeline/material.

ValueDescription
MK_TOPOLOGY_TRIANGLESSelects triangles.
MK_TOPOLOGY_LINESSelects lines.

Typedefs

mk_box_paramstypedef

typedef struct mk_box_params mk_box_params

Data for box params.

mk_capsule_paramstypedef

typedef struct mk_capsule_params mk_capsule_params

Data for capsule params.

mk_cone_paramstypedef

typedef struct mk_cone_params mk_cone_params

Data for cone params.

mk_cylinder_paramstypedef

typedef struct mk_cylinder_params mk_cylinder_params

Data for cylinder params.

mk_geometry_buffertypedef

typedef struct mk_geometry_buffer mk_geometry_buffer

Data for geometry buffer.

mk_geometry_countstypedef

typedef struct mk_geometry_counts mk_geometry_counts

Data for geometry counts.

mk_geometry_desctypedef

typedef struct mk_geometry_desc mk_geometry_desc

Data for geometry desc.

mk_geometry_vertextypedef

typedef struct mk_geometry_vertex mk_geometry_vertex

Data for geometry vertex.

mk_grid_paramstypedef

typedef struct mk_grid_params mk_grid_params

Data for grid params.

LINES

mk_plane_paramstypedef

typedef struct mk_plane_params mk_plane_params

Data for plane params.

mk_sphere_paramstypedef

typedef struct mk_sphere_params mk_sphere_params

Data for sphere params.

mk_topology_ttypedef

typedef enum mk_topology mk_topology_t

Primitive topology.

Note: bgfx encodes topology in the pipeline STATE word (MK_STATE_PT_*), not the buffer this is advisory. A LINES geometry (grid) must be drawn with a lines-state pipeline/material.

mk_torus_paramstypedef

typedef struct mk_torus_params mk_torus_params

Data for torus params.

Macros

MK_GEOMETRY_INVALIDdefine

MK_GEOMETRY_INVALID

Invalid sentinel for geometry.