Skip to content

Geometry

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

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.

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

Constructs a Geometry object with vertex and index data.

cpp
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.

Factories preferred


Geometry::Create() auto

Creates a shared pointer to a Geometry object.

cpp
static auto Geometry::Create();

Geometry::Create() auto

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

cpp
static auto 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.

Properties

primitive GeometryPrimitiveType

Primitive type used for rendering.

cpp
GeometryPrimitiveType primitive {GeometryPrimitiveType::Triangles};

renderer_id unsigned int

GPU renderer identifier. Used internally by the renderer.

cpp
unsigned int renderer_id {0};

Functions

Attributes() const auto &

Returns all defined vertex attributes.

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

BoundingBox() Box3

Returns the geometry's bounding box (computed on demand).

If not cached, it will be computed from the position data.

cpp
Box3 Geometry::BoundingBox();

BoundingSphere() Sphere

Returns the geometry's bounding sphere (computed on demand).

If not cached, it will be computed from the position data.

cpp
Sphere Geometry::BoundingSphere();

HasAttribute() bool

Returns whether a given attribute type is present.

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

IndexCount() size_t

Returns the number of indices.

cpp
size_t Geometry::IndexCount() const;

IndexData() const auto &

Returns raw index data.

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

SetAttribute() void

Adds a vertex attribute.

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

Stride() size_t

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

cpp
size_t Geometry::Stride() const;

VertexCount() size_t

Returns the number of vertices (size / stride).

cpp
size_t Geometry::VertexCount() const;

VertexData() const auto &

Returns raw vertex data.

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

Released under the MIT License.