Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
IndexBuffer.hpp
1#pragma once
2
3#include <Infinity/Types/Core/Data.hpp>
4#include <Infinity/Types/Core/Value.hpp>
5#include <Infinity/Types/Containers/Array.hpp>
6#include <Infinity/Types/Core/Span.hpp>
7
9{
88 class INFINITY_API_PUBLIC IndexBuffer : public Core::Data
89 {
90 public:
95 enum class IndexType {
96 UInt16,
97 UInt32
98 };
99
104 enum class Topology {
105 Triangles,
106 Lines,
107 TriangleStrip,
108 Quads
109 };
110
111 public:
118 IndexType type = IndexType::UInt16;
119
126 Topology topology = Topology::Triangles;
127
136
143
151 IndexBuffer(const size_t size, IndexType type = IndexType::UInt16, Topology topology = Topology::Triangles);
152
159 IndexBuffer(const Containers::Array<uint16_t>& indices, Topology topology = Topology::Triangles);
160
167 IndexBuffer(const Containers::Array<uint32_t>& indices, Topology topology = Topology::Triangles);
168
172 virtual ~IndexBuffer();
173
174 std::unique_ptr<Core::Base> clone() const override;
175
184 void reserve(size_t capacity);
185
191 void clear();
192
201 uint32_t operator[](size_t index) const;
202
211 uint32_t at(size_t index) const;
212
219 void setIndex(size_t index, uint32_t value);
220
228 void pushIndex(uint16_t index);
229
237 void pushIndex(uint32_t index);
238
248 void pushTriangle(uint16_t v0, uint16_t v1, uint16_t v2);
249
259 void pushTriangle(uint32_t v0, uint32_t v1, uint32_t v2);
260
273 void pushQuad(uint16_t v0, uint16_t v1, uint16_t v2, uint16_t v3);
274
283 void pushQuad(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3);
284
293 void pushLine(uint16_t v0, uint16_t v1);
294
301 void pushLine(uint32_t v0, uint32_t v1);
302
309
316
324 Core::span<const uint16_t> asUInt16Buffer() const;
325
333 Core::span<uint16_t> asUInt16Buffer();
334
342 Core::span<const uint32_t> asUInt32Buffer() const;
343
351 Core::span<uint32_t> asUInt32Buffer();
352
361 size_t count() const;
362
368 const Infinity::Types::TypeID& typeId() const override;
369
370 private:
371 size_t _indexCount = 0;
372 };
373}
374
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Base class for complex data types with memory wrapping and property support.
Definition Data.hpp:49
Container for mesh index data defining vertex connectivity and topology.
Definition IndexBuffer.hpp:89
IndexBuffer(const size_t size, IndexType type=IndexType::UInt16, Topology topology=Topology::Triangles)
Constructs an index buffer with pre-allocated capacity.
void clear()
Removes all indices from the buffer.
Topology
Primitive topology defining how indices form geometry.
Definition IndexBuffer.hpp:104
Core::span< const uint16_t > asUInt16Buffer() const
Gets a const span view of the data as 16-bit indices.
void pushQuad(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3)
Appends indices for a quad (as two triangles).
IndexBuffer(const Containers::Array< uint32_t > &indices, Topology topology=Topology::Triangles)
Constructs an index buffer from a 32-bit index array.
void pushTriangle(uint32_t v0, uint32_t v1, uint32_t v2)
Appends three 32-bit indices forming a triangle.
IndexBuffer(const Containers::Array< uint16_t > &indices, Topology topology=Topology::Triangles)
Constructs an index buffer from a 16-bit index array.
Core::span< uint16_t > asUInt16Buffer()
Gets a mutable span view of the data as 16-bit indices.
void pushIndices(const Containers::Array< uint32_t > &indices)
Appends multiple 32-bit indices from an array.
void pushLine(uint32_t v0, uint32_t v1)
Appends two 32-bit indices forming a line segment.
Core::span< uint32_t > asUInt32Buffer()
Gets a mutable span view of the data as 32-bit indices.
void pushLine(uint16_t v0, uint16_t v1)
Appends two 16-bit indices forming a line segment.
void pushIndices(const Containers::Array< uint16_t > &indices)
Appends multiple 16-bit indices from an array.
std::unique_ptr< Core::Base > clone() const override
Core::span< const uint32_t > asUInt32Buffer() const
Gets a const span view of the data as 32-bit indices.
uint32_t operator[](size_t index) const
Accesses an index value (unchecked).
const Infinity::Types::TypeID & typeId() const override
Gets the TypeID for IndexBuffer.
void setIndex(size_t index, uint32_t value)
Sets the value of an existing index.
void pushTriangle(uint16_t v0, uint16_t v1, uint16_t v2)
Appends three 16-bit indices forming a triangle.
Containers::Array< uint8_t > data
Raw index data storage.
Definition IndexBuffer.hpp:135
void pushIndex(uint32_t index)
Appends a single 32-bit index.
void pushQuad(uint16_t v0, uint16_t v1, uint16_t v2, uint16_t v3)
Appends indices for a quad (as two triangles).
uint32_t at(size_t index) const
Accesses an index value (checked).
void reserve(size_t capacity)
Pre-allocates storage for a specified number of indices.
void pushIndex(uint16_t index)
Appends a single 16-bit index.
IndexType
Index data format determining maximum vertex count.
Definition IndexBuffer.hpp:95
size_t count() const
Gets the number of indices in the buffer.
Definition IndexBuffer.hpp:9
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71