Geometry
The [Geometry](/reference/geometries/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()](/reference/geometries/geometry#function-create-514cfb38)
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()
vglx::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. |
Constructs a Geometry object with vertex and index data.
Factories preferred
Geometry::Create() auto
static auto vglx::Geometry::Create()
Creates a shared pointer to a Geometry object.
Geometry::Create() auto
static auto vglx::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. |
Creates a shared pointer to a Geometry object with vertex and index data.
Properties
primitive GeometryPrimitiveType
GeometryPrimitiveType primitive { GeometryPrimitiveType::Triangles }
Primitive type used for rendering.
renderer_id unsigned int
unsigned int renderer_id { 0 }
GPU renderer identifier. Used internally by the renderer.
Functions
Attributes() const auto &
const auto & vglx::Geometry::Attributes() const
Returns all defined vertex attributes.
Box3 vglx::Geometry::BoundingBox()
Returns the geometry's bounding box (computed on demand). If not cached, it will be computed from the position data.
Sphere vglx::Geometry::BoundingSphere()
Returns the geometry's bounding sphere (computed on demand). If not cached, it will be computed from the position data.
HasAttribute() bool
bool vglx::Geometry::HasAttribute(VertexAttributeType type) const
Parameter | Description |
---|---|
type | Attribute type to query. |
Returns whether a given attribute type is present.
SetAttribute() void
void vglx::Geometry::SetAttribute(const GeometryAttribute &attribute)
Parameter | Description |
---|---|
attribute | The attribute to register. |
Adds a vertex attribute.
Stride() size_t
size_t vglx::Geometry::Stride() const
Returns the vertex stride in floats (sum of all active attribute sizes).
VertexCount() size_t
size_t vglx::Geometry::VertexCount() const
Returns the number of vertices (size / stride).
VertexData() const auto &
const auto & vglx::Geometry::VertexData() const
Returns raw vertex data.