SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::VertexFormatRegistry Class Reference

#include <VertexLayout.hpp>

Static Public Member Functions

static const VertexLayoutDescGet (VertexFormatHandle handle)
static VertexFormatHandle Register (const VertexLayoutDesc &desc)
static void Shutdown ()
 Clears the registry; call only during application teardown.

Detailed Description

Global registry of custom vertex layouts. Register returns a stable handle.

This is how a game teaches the renderer about its own geometry. Call Register() once per layout during startup, keep the returned VertexFormatHandle, and pass it to MeshBatch::CreateMesh(). The handle travels on the resulting MeshHandle, and the backend uses it to pick the pipeline for every pass the format participates in.

Handles are stable for the lifetime of the process and start at 1; handle 0 is reserved for the engine's built-in vertex layout. Register() does not validate the descriptor. A zero stride or an empty attribute list is caught later, at pipeline creation.

Register once and reuse the handle. Registering the same descriptor repeatedly creates a new handle and a new set of pipelines each time. Shutdown() is for application teardown only, and pointers returned by Get() stay valid until it runs.

// Startup: register the format your game uses
class VoxelVertexFormat {
public:
static Sleak::VertexFormatHandle Handle() {
return handle;
}
private:
static Sleak::VertexFormatHandle Register() {
desc.stride = sizeof(VoxelVertex);
desc.attributes = MakeVoxelAttributes();
desc.shaderStem = "flat_shader";
}
};
// Mesh creation: key the buffers to that handle
Sleak::MeshHandle mesh = Sleak::MeshBatch::CreateMesh(
VoxelVertexFormat::Handle(),
verts.data(), verts.size() * sizeof(VoxelVertex),
indices.data(), indices.size());
// Teardown
static MeshHandle CreateMesh(VertexGroup &vertices, IndexGroup &indices)
Create GPU vertex+index buffers from CPU mesh data.
Definition MeshBatch.cpp:22
static VertexFormatHandle Register(const VertexLayoutDesc &desc)
static void Shutdown()
Clears the registry; call only during application teardown.
uint32_t VertexFormatHandle
std::vector< VertexAttribute > attributes
See also
VertexLayoutDesc, VertexFormatHandle, MeshBatch, MeshHandle

Definition at line 139 of file VertexLayout.hpp.

Member Function Documentation

◆ Get()

const VertexLayoutDesc * Sleak::VertexFormatRegistry::Get ( VertexFormatHandle handle)
static

Returns nullptr for handle 0 or an unknown handle. The returned pointer stays valid until Shutdown(), which is intended for application teardown only.

Definition at line 19 of file VertexLayout.cpp.

◆ Register()

VertexFormatHandle Sleak::VertexFormatRegistry::Register ( const VertexLayoutDesc & desc)
static

Definition at line 13 of file VertexLayout.cpp.

◆ Shutdown()

void Sleak::VertexFormatRegistry::Shutdown ( )
static

Clears the registry; call only during application teardown.

Definition at line 27 of file VertexLayout.cpp.