Geometry
The Geometry class is the fundamental unit of renderable mesh data in VGLX. It contains raw vertex data, optional indices, and layout metadata. Geometry can be rendered using different primitive types (triangles, lines, etc.) and may expose bounds such as bounding boxes and spheres for culling or physics.
Instances are typically created using the static Create() methods and then configured with attribute metadata via SetAttribute.
auto geometry = vglx::Geometry::Create({
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
});
geometry->SetAttribute({GeometryAttributeType::Position, 3});
Add(Mesh::Create(geometry, UnlitMaterial::Create(0xFF0133)));Construction
Constructors
Geometry()
Constructs a Geometry object with vertex and index data.
Geometry::Geometry(const std::vector<float> & vertex_data, const std::vector<unsigned int> & index_data);| Parameter | Description |
|---|---|
| vertex_data | Flat float array of interleaved vertex attributes. |
| index_data | Optional index buffer for indexed rendering. |
Factories preferred
Geometry::Create() auto
Creates a shared pointer to a Geometry object.
static auto Geometry::Create();Geometry::Create() auto
Creates a shared pointer to a Geometry object with vertex and index data.
static auto Geometry::Create(const std::vector<float> & vertex_data, const std::vector<unsigned int> & index_data={});| Parameter | Description |
|---|---|
| vertex_data | Flat float array of interleaved vertex attributes. |
| index_data | Optional index buffer for indexed rendering. |
Properties
primitive GeometryPrimitiveType
Primitive type used for rendering.
GeometryPrimitiveType primitive {GeometryPrimitiveType::Triangles};renderer_id unsigned int
GPU renderer identifier. Used internally by the renderer.
unsigned int renderer_id {0};Functions
Attributes() const auto &
Returns all defined vertex attributes.
const auto& Geometry::Attributes() const;Returns the geometry's bounding box (computed on demand).
If not cached, it will be computed from the position data.
Box3 Geometry::BoundingBox();Returns the geometry's bounding sphere (computed on demand).
If not cached, it will be computed from the position data.
Sphere Geometry::BoundingSphere();HasAttribute() bool
Returns whether a given attribute type is present.
bool Geometry::HasAttribute(VertexAttributeType type) const;| Parameter | Description |
|---|---|
| type | Attribute type to query. |
IndexCount() size_t
Returns the number of indices.
size_t Geometry::IndexCount() const;IndexData() const auto &
Returns raw index data.
const auto& Geometry::IndexData() const;SetAttribute() void
Adds a vertex attribute.
void Geometry::SetAttribute(const GeometryAttribute& attribute);| Parameter | Description |
|---|---|
| attribute | The attribute to register. |
Stride() size_t
Returns the vertex stride in floats (sum of all active attribute sizes).
size_t Geometry::Stride() const;VertexCount() size_t
Returns the number of vertices (size / stride).
size_t Geometry::VertexCount() const;VertexData() const auto &
Returns raw vertex data.
const auto& Geometry::VertexData() const;