-
Notifications
You must be signed in to change notification settings - Fork 2
/
VertexBufferLayout.hpp
38 lines (32 loc) · 1.15 KB
/
VertexBufferLayout.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include <glbinding/gl/gl.h>
#include <vector>
using namespace gl;
struct VertexBufferElement {
GLuint type;
GLint count;
static inline GLsizei sizeOfGlType(const GLuint type) {
switch (type) {
case static_cast<GLuint>(GL_FLOAT): return 4;
case static_cast<GLuint>(GL_UNSIGNED_INT): return 4;
case static_cast<GLuint>(GL_UNSIGNED_BYTE): return 1;
case static_cast<GLuint>(GL_INT): return 4;
case static_cast<GLuint>(GL_BYTE): return 1;
case static_cast<GLuint>(GL_SHORT): return 2;
case static_cast<GLuint>(GL_UNSIGNED_SHORT): return 2;
}
return 0;
}
};
class VertexBufferLayout {
private:
std::vector<VertexBufferElement> elements;
GLsizei stride = 0;
public:
void add(const GLint count, const GLuint glType) {
elements.push_back({glType, count});
stride += count * VertexBufferElement::sizeOfGlType(glType);
}
inline const std::vector<VertexBufferElement>& getElements() const { return elements; }
inline GLsizei getStride() const { return stride; }
};