56 return sizeof(
T) /
sizeof(
float);
66 return std::equal(floatPtr, floatPtr +
numFloatsInVert(),
reinterpret_cast<const float*
>(&vert));
82 for (
const T& vert : verts) {
85 bool existingVertFound =
false;
86 size_t existingVertIndex;
89 for (
int i =
static_cast<int>(
elements.
data.size()) - 1; i >= 0; i--) {
93 existingVertIndex =
static_cast<size_t>(
elements.
data[i]);
94 existingVertFound =
true;
100 if (existingVertFound) {
101 elements.
data.push_back(
static_cast<unsigned int>(existingVertIndex));
106 elements.
data.push_back(
static_cast<unsigned int>(vertIndex));
109 const float* vertLoc =
reinterpret_cast<const float*
>(&vert);
126 template <
typename Verts,
typename Func>
131 reinterpret_cast<const float*
>(verts.data() + verts.size()));
174 reinterpret_cast<const float*
>(verts.data() + verts.size()));
193 reinterpret_cast<const float*
>(verts.data() + verts.size()));
207 template <
size_t N1,
size_t N2,
typename index_type =
unsigned int>
213 for (
const index_type& i : indices)
elements.
data.push_back(
static_cast<unsigned int>(i));
224 template <
typename index_type =
unsigned int>
230 for (
const index_type& i : indices)
elements.
data.push_back(
static_cast<unsigned int>(i));
262 const std::array<size_t,
sizeof...(NFloats)> nFloatsArr = {NFloats...};
263 const float* offset =
nullptr;
264 for (
size_t i = 0; i < attributes.size(); i++) {
265 glVertexAttribPointer(attributes[i],
static_cast<GLint
>(nFloatsArr[i]), GL_FLOAT, GL_FALSE,
266 sizeof(
T),
static_cast<const void*
>(offset));
267 glEnableVertexAttribArray(attributes[i]);
268 offset += nFloatsArr[i];
310 glDrawElements(GL_TRIANGLES,
static_cast<GLsizei
>(
elements.
data.size()), GL_UNSIGNED_INT,
nullptr);
318 glDrawArrays(GL_TRIANGLES, 0,
static_cast<GLsizei
>(
vertices.
data.size()));
void allocBuffer(BufferUsage usage)
bool vertFloatPtrEqual(const float *floatPtr, const T &vert)
void updateVerticesCondense(const std::vector< T > &verts, BufferUsage usage)
void drawNoElements() const
Buffer< unsigned int > elements
void condenseVertices(const Container &verts, BufferUsage usage)
VertexArray(const std::vector< T > &verts, const std::vector< index_type > &indices, BufferUsage usage)
VertexArray(const std::array< T, N1 > &verts, const std::array< index_type, N2 > &indices, BufferUsage usage)
void enableAttributePointer(const std::array< unsigned int, sizeof...(NFloats)> &attributes) const
void drawNoElements(DrawType type) const
void createVerticesAndElements(const Verts &verts, const Func &func, BufferUsage usage)
VertexArray(const std::vector< T > &verts, BufferUsage usage, bool condense=true)
VertexArray(const std::vector< T > &verts, std::vector< unsigned int > &&indices, BufferUsage usage)
VertexArray(const std::array< T, N > &verts, BufferUsage usage, bool condense=true)
void updateVerticesCondense(const std::array< T, N > &verts, BufferUsage usage)
void draw(DrawType type) const
constexpr size_t numFloatsInVert()
GLenum getEnumValue(T value)