Meshes
Functions for creating and drawing 3D geometry.
vio_mesh
VioMesh|false vio_mesh(VioContext $context, array $config)Create a mesh from vertex data.
Config:
| Key | Type | Required | Description |
|---|---|---|---|
vertices | float[] | Yes | Flat array of vertex data |
layout | array | Yes | Vertex attribute layout |
indices | int[] | No | Index buffer data |
topology | int | No | Primitive topology (default: VIO_TRIANGLES) |
Layout Format
Simple – auto-assigned locations starting at 0:
"layout" => [VIO_FLOAT3, VIO_FLOAT2, VIO_FLOAT3]
// location 0: vec3 (12 bytes)
// location 1: vec2 (8 bytes)
// location 2: vec3 (12 bytes)Explicit – specify locations manually:
"layout" => [
["location" => 0, "components" => 3],
["location" => 2, "components" => 2],
]Vertex Format Constants
| Constant | Components | Size |
|---|---|---|
VIO_FLOAT1 | 1 float | 4 bytes |
VIO_FLOAT2 | 2 floats | 8 bytes |
VIO_FLOAT3 | 3 floats | 12 bytes |
VIO_FLOAT4 | 4 floats | 16 bytes |
VIO_INT1 | 1 int | 4 bytes |
VIO_INT2 | 2 ints | 8 bytes |
VIO_INT3 | 3 ints | 12 bytes |
VIO_INT4 | 4 ints | 16 bytes |
Vertex data is always uploaded as 32-bit floats, and only VIO_FLOAT1 – VIO_FLOAT4 set the component count – in a flat layout any other value (the VIO_INT* constants included) counts as 3 floats. VIO_UINT1 – VIO_UINT4 are deliberately not PHP constants (there is no integer vertex path; see Vertex Formats).
Indices
indices are stored as uint16 when every index is < 65536 (half the index bandwidth), otherwise as uint32 – on every backend. 'index_type' => VIO_INDEX_UINT32 forces 32-bit indices. 'adjacency' => true builds VIO_TRIANGLES_ADJACENCY indices for geometry shaders.
vio_mesh_index_bytes
int vio_mesh_index_bytes(VioMesh $mesh)Bytes per index of the mesh's index buffer: 2 (uint16), 4 (uint32), 0 when the mesh is not indexed.
$small = vio_mesh($ctx, ['vertices' => $v, 'indices' => [0, 1, 2], 'layout' => [VIO_FLOAT3]]);
vio_mesh_index_bytes($small); // 2
$wide = vio_mesh($ctx, ['vertices' => $v, 'indices' => [0, 1, 2], 'layout' => [VIO_FLOAT3],
'index_type' => VIO_INDEX_UINT32]);
vio_mesh_index_bytes($wide); // 4Topology Constants
| Constant | Description |
|---|---|
VIO_TRIANGLES | Every 3 vertices form a triangle |
VIO_TRIANGLE_STRIP | Each new vertex forms a triangle with previous two |
VIO_TRIANGLE_FAN | Triangles share the first vertex |
VIO_LINES | Every 2 vertices form a line |
VIO_LINE_STRIP | Connected line segments |
VIO_POINTS | Individual points |
VIO_PATCHES | Tessellation patches (pipelines with tessellation stages) |
VIO_LINES_ADJACENCY, VIO_LINE_STRIP_ADJACENCY, VIO_TRIANGLES_ADJACENCY, VIO_TRIANGLE_STRIP_ADJACENCY | Primitives with adjacency for geometry shaders |
For draws whose arguments come from a GPU buffer, batched submission and recorded bundles see Batches, Bundles & Indirect Draws; for mesh / task shaders see Mesh Shaders.
vio_draw
void vio_draw(VioContext $context, VioMesh $mesh)Draw a mesh using the currently bound pipeline.
vio_draw_instanced
void vio_draw_instanced(VioContext $context, VioMesh $mesh, float[] $matrices, int $instanceCount)Draw a mesh multiple times with per-instance model matrices.
$matrices– Flat array of4x4matrices (16 floats per instance)$instanceCount– Number of instances to draw
$matrices = [];
for ($i = 0; $i < 100; $i++) {
// Identity matrix translated by ($i * 2, 0, 0)
array_push($matrices,
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
$i * 2, 0, 0, 1
);
}
vio_draw_instanced($ctx, $mesh, $matrices, 100);vio_draw_3d
void vio_draw_3d(VioContext $context)Flush/finalize 3D draw calls for the current frame.