Geometry
Geometry is the core unit of renderable mesh data in VGLX. It stores raw vertex and index buffers along with attribute metadata that describes how the data should be interpreted by the renderer (positions, normals, UVs, tangents, per-instance data, and so on).
A geometry can be rendered using different primitive types (triangles, lines, line loops) and provides access to derived bounding volumes such as axis-aligned bounding boxes and bounding spheres, useful for frustum culling or collision queries.
Instances are usually created via the static Geometry::Create factory methods and configured with vertex attributes using Geometry::SetAttribute.
auto geometry = vglx::Geometry::Create({
// 3 vertices, XYZ position only:
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
});
geometry->SetAttribute({vglx::Geometry::VertexAttributeType::Position, 3});
auto material = vglx::PhongMaterial::Create(0x049EF4);
my_scene->Add(vglx::Mesh::Create(geometry, material));Construction
Constructors
Geometry()
Constructs a geometry from vertex and index data.
The vertex buffer is populated from vertex_data, and the optional index buffer from index_data. Attribute metadata must be configured separately using SetAttribute.
Geometry::Geometry(const std::vector<float> & vertex_data, const std::vector<unsigned int> & index_data);| Parameter | Description |
|---|---|
| vertex_data | Interleaved vertex data stored as floats. |
| index_data | Optional index buffer (empty for non-indexed geometry). |
Factories preferred
Creates a shared instance of an empty Geometry.
The resulting geometry has no vertex or index data and must be populated and configured before rendering.
static std::shared_ptr<Geometry> Geometry::Create();Creates a shared instance of Geometry from vertex and index data.
static std::shared_ptr<Geometry> Geometry::Create(const std::vector<float> & vertex_data, const std::vector<unsigned int> & index_data={});| Parameter | Description |
|---|---|
| vertex_data | Interleaved vertex data stored as floats. |
| index_data | Optional index data; leave empty for non-indexed geometry. |
Types
Geometry::PrimitiveType enum
Primitive topology used when rendering this geometry.
Controls how the vertex and index data are interpreted by the renderer.
| Value | Description |
|---|---|
| Triangles | Render as triangle list. |
| Lines | Render as line list. |
| LineLoop | Render as a closed line loop. |
Geometry::VertexAttributeType enum
Enumerates supported vertex attribute semantics.
Each value identifies the purpose of a vertex attribute stream, such as positions, normals, UVs, or per-instance transforms. Attributes are described via Geometry::VertexAttribute and stored in the attributes array.
| Value | Description |
|---|---|
| Position | Vertex position in object space. |
| Normal | Vertex normal in object space. |
| UV | Texture coordinates. |
| Tangent | Tangent vector for normal mapping. |
| Color | Per-vertex color. |
| InstanceColor | Per-instance color. |
| InstanceTransform | Per-instance transform matrix. |
| None | Sentinel value indicating no attribute. |
Geometry::VertexAttribute struct
Describes a single vertex attribute stream.
Each attribute entry specifies the semantic type and the number of components per vertex item_size (for example, 3 for a vec3 position). Attributes are stored in a fixed-size array indexed by Geometry::VertexAttributeType.
| Parameter | Description |
|---|---|
| item_size unsigned int | Number of float components per vertex. |
| type VertexAttributeType | Attribute semantic. |
AttributesType typedef
Convenience alias for the attribute array type.
using vglx::Geometry::AttributesType = std::array<vglx::Geometry::VertexAttribute, AttributesLength>Properties
AttributesLength int
Total number of supported attribute slots.
int AttributesLength {std::to_underlying(VertexAttributeType::None)};primitive PrimitiveType
Primitive topology used by this geometry (triangles by default).
PrimitiveType primitive {PrimitiveType::Triangles};renderer_id unsigned int
Renderer-specific identifier for the underlying GPU resource.
unsigned int renderer_id {0};Functions
Attributes() constAttributesType&
Returns the array of vertex attribute descriptors.
The array is indexed by Geometry::VertexAttributeType values in the range [0, AttributesLength).
const AttributesType& Geometry::Attributes() const;Returns an axis-aligned bounding box enclosing the geometry.
The bounding box is computed lazily from the vertex positions and cached internally. Subsequent calls reuse the cached result until the geometry data changes.
Box3 Geometry::BoundingBox();Returns a bounding sphere enclosing the geometry.
The bounding sphere is computed lazily from the vertex positions and cached internally. Subsequent calls reuse the cached result until the geometry data changes.
Sphere Geometry::BoundingSphere();HasAttribute() bool
Checks whether an attribute of the given type is present.
bool Geometry::HasAttribute(VertexAttributeType type) const;| Parameter | Description |
|---|---|
| type | Attribute semantic to query. |
IndexCount() size_t
Returns the number of indices stored in the index buffer.
For non-indexed geometry, this value is zero.
size_t Geometry::IndexCount() const;IndexData() const std::vector<unsigned int> &
Returns a read-only reference to the index buffer.
If the geometry is non-indexed, this buffer may be empty.
const std::vector<unsigned int> & Geometry::IndexData() const;SetAttribute() void
Registers a vertex attribute on this geometry.
The attribute is stored in the internal attribute array and used by the renderer to interpret the vertex buffer layout. Multiple attributes can be configured as long as their combined stride matches the vertex data.
void Geometry::SetAttribute(const Geometry::VertexAttribute& attribute);| Parameter | Description |
|---|---|
| attribute | Vertex attribute descriptor to add or update. |
Stride() size_t
Returns the vertex stride in number of floats.
The stride is computed from the active vertex attributes and describes how many floats form a single vertex in the interleaved buffer.
size_t Geometry::Stride() const;VertexCount() size_t
Returns the number of vertices in the geometry.
The vertex count is derived from the size of the vertex buffer and the configured stride.
size_t Geometry::VertexCount() const;VertexData() const std::vector<float> &
Returns a read-only reference to the vertex buffer.
The data is stored as a flat array of floats, typically interleaved according to the configured attributes.
const std::vector<float> & Geometry::VertexData() const;