7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
50 static_assert(
sizeof(std::byte) * CHAR_BIT == 8,
51 "The buffer explicitly depends on the fact that std::byte contains 8 bits.");
61 std::size_t numElements,
62 bool shouldNormalize =
false);
75 std::size_t numElements,
76 std::size_t strideOffset,
77 std::size_t strideSize,
78 bool shouldNormalize =
false);
85 void setVertices(
const std::byte* srcBytes, std::size_t numBytes, std::size_t dstOffset = 0);
96 const std::byte*
getData()
const;
125 inline constexpr static auto INVALID_STRIDE_VALUE =
static_cast<std::size_t
>(-1);
132 std::byte* u_attributeBuffer;
137 std::size_t u_strideOffset;
141 std::size_t strideSize;
146 uint8 numElements : 2;
153 uint8 shouldNormalize : 1;
158 bool isEmpty()
const;
160 bool hasStrideInfo()
const;
165 void ensureConsistentVertexLayout()
const;
169 std::array<std::underlying_type_t<EVertexAttribute>, MAX_ENTRIES> m_attributeTypeToEntryIndex;
170 std::array<Entry, MAX_ENTRIES> m_entries;
171 std::underlying_type_t<EVertexAttribute> m_numEntries;
173 std::unique_ptr<std::byte[]> m_byteBuffer;
174 std::size_t m_byteBufferSize;
182 return sizeof(*this) + m_byteBufferSize;
185inline bool IndexedVertexBuffer::Entry::isEmpty()
const
187 return numElements == 0;
190inline bool IndexedVertexBuffer::Entry::hasStrideInfo()
const
194 (u_strideOffset != INVALID_STRIDE_VALUE && strideSize != INVALID_STRIDE_VALUE) ||
195 (u_strideOffset == INVALID_STRIDE_VALUE && strideSize == INVALID_STRIDE_VALUE));
197 return u_strideOffset != INVALID_STRIDE_VALUE && strideSize != INVALID_STRIDE_VALUE;
202 return m_byteBuffer !=
nullptr;
207 return m_vertexSize > 0 ? m_byteBufferSize / m_vertexSize : 0;
222 return hasEntry(attribute);
225inline bool IndexedVertexBuffer::hasEntry(
const EVertexAttribute attribute)
const
227 return m_attributeTypeToEntryIndex[
enum_to_value(attribute)] != MAX_ENTRIES;
230inline auto IndexedVertexBuffer::getEntry(
const EVertexAttribute attribute)
const
233 const auto entryIndex = m_attributeTypeToEntryIndex[
enum_to_value(attribute)];
234 PH_ASSERT_LT(entryIndex, m_numEntries);
235 return m_entries[entryIndex];
241 return m_byteBuffer.get();
247 return m_byteBuffer.get();
252 return numElements == 0;
A general vertex buffer for storing various indexed attributes.
Definition IndexedVertexBuffer.h:49
std::size_t memoryUsage() const
Definition IndexedVertexBuffer.h:180
void declareAttribute(EVertexAttribute attribute, EVertexElement element, std::size_t numElements, bool shouldNormalize=false)
Declares a vertex attribute with default layout (AoS).
Definition IndexedVertexBuffer.cpp:51
std::byte * getData()
Access to the underlying raw byte buffer.
Definition IndexedVertexBuffer.h:238
AttributeDeclaration getAttributeDeclaration(EVertexAttribute attribute) const
Get information for a previously declared attribute. Can only be called after allocation.
Definition IndexedVertexBuffer.cpp:432
IndexedVertexBuffer()
Definition IndexedVertexBuffer.cpp:38
void allocate(std::size_t numVertices)
Definition IndexedVertexBuffer.cpp:135
math::Vector3R getAttribute(EVertexAttribute attribute, std::size_t index) const
Definition IndexedVertexBuffer.cpp:210
void setAttribute(EVertexAttribute attribute, std::size_t index, const math::Vector3R &value)
Definition IndexedVertexBuffer.cpp:313
bool hasAttribute(EVertexAttribute attribute) const
Definition IndexedVertexBuffer.h:220
void setVertices(const std::byte *srcBytes, std::size_t numBytes, std::size_t dstOffset=0)
Definition IndexedVertexBuffer.cpp:417
std::size_t numVertices() const
Definition IndexedVertexBuffer.h:205
bool isAllocated() const
Definition IndexedVertexBuffer.h:200
The root for all renderer implementations.
Definition EEngineProject.h:6
constexpr auto enum_size()
Definition utility.h:179
EVertexAttribute
Definition IndexedVertexBuffer.h:21
EVertexElement
Definition IndexedVertexBuffer.h:34
constexpr auto enum_to_value(const EnumType enumValue)
Definition utility.h:166
Info for a declared vertex attribute.
Definition IndexedVertexBuffer.h:102
std::size_t strideOffset
Definition IndexedVertexBuffer.h:103
uint8 numElements
Definition IndexedVertexBuffer.h:106
uint8 shouldNormalize
Definition IndexedVertexBuffer.h:107
AttributeDeclaration()
Definition IndexedVertexBuffer.cpp:28
std::size_t strideSize
Definition IndexedVertexBuffer.h:104
EVertexElement element
Definition IndexedVertexBuffer.h:105
bool isEmpty() const
Definition IndexedVertexBuffer.h:250