Skip to content

Geometry

Represents GPU-ready geometry data including vertex and index buffers.

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.

cpp
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()

cpp
vglx::Geometry::Geometry(const std::vector< float > &vertex_data, const std::vector< unsigned int > &index_data)
ParameterDescription
vertex_dataFlat float array of interleaved vertex attributes.
index_dataOptional index buffer for indexed rendering.

Constructs a Geometry object with vertex and index data.

Factories preferred


Geometry::Create() auto

cpp
static auto vglx::Geometry::Create()

Creates a shared pointer to a Geometry object.

Geometry::Create() auto

cpp
static auto vglx::Geometry::Create(const std::vector< float > &vertex_data, const std::vector< unsigned int > &index_data={})
ParameterDescription
vertex_dataFlat float array of interleaved vertex attributes.
index_dataOptional index buffer for indexed rendering.

Creates a shared pointer to a Geometry object with vertex and index data.

Properties

primitive GeometryPrimitiveType

cpp
GeometryPrimitiveType primitive { GeometryPrimitiveType::Triangles }

Primitive type used for rendering.

renderer_id unsigned int

cpp
unsigned int renderer_id { 0 }

GPU renderer identifier. Used internally by the renderer.

Functions

Attributes() const auto &

cpp
const auto & vglx::Geometry::Attributes() const

Returns all defined vertex attributes.

BoundingBox() Box3

cpp
Box3 vglx::Geometry::BoundingBox()

Returns the geometry's bounding box (computed on demand). If not cached, it will be computed from the position data.

BoundingSphere() Sphere

cpp
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

cpp
bool vglx::Geometry::HasAttribute(VertexAttributeType type) const
ParameterDescription
typeAttribute type to query.

Returns whether a given attribute type is present.

IndexCount() size_t

cpp
size_t vglx::Geometry::IndexCount() const

Returns the number of indices.

IndexData() const auto &

cpp
const auto & vglx::Geometry::IndexData() const

Returns raw index data.

SetAttribute() void

cpp
void vglx::Geometry::SetAttribute(const GeometryAttribute &attribute)
ParameterDescription
attributeThe attribute to register.

Adds a vertex attribute.

Stride() size_t

cpp
size_t vglx::Geometry::Stride() const

Returns the vertex stride in floats (sum of all active attribute sizes).

VertexCount() size_t

cpp
size_t vglx::Geometry::VertexCount() const

Returns the number of vertices (size / stride).

VertexData() const auto &

cpp
const auto & vglx::Geometry::VertexData() const

Returns raw vertex data.

Released under the MIT License.