-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawable.cpp
More file actions
48 lines (39 loc) · 1023 Bytes
/
drawable.cpp
File metadata and controls
48 lines (39 loc) · 1023 Bytes
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
39
40
41
42
43
44
45
46
47
48
#include "drawable.h"
Drawable::Drawable() : indexCount() {}
Drawable::~Drawable() {
destroyVBOData();
}
static dict<BufferType, bool> useElemArray = {
{INDEX, true},
{POSITION, false}
};
void Drawable::destroyVBOData() {
for (auto kvp : buffers) {
glDeleteBuffers(1, &kvp.second);
}
buffers.clear();
}
GLenum Drawable::drawMode() {
return GL_TRIANGLES;
}
void Drawable::generateBuffer(BufferType type) {
glGenBuffers(1, &buffers[type]);
}
bool Drawable::hasBuffer(BufferType type) {
return buffers.count(type) != 0;
}
void Drawable::bindBuffer(BufferType type) {
if (useElemArray.at(type)) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[type]);
}
else {
glBindBuffer(GL_ARRAY_BUFFER, buffers[type]);
}
}
void Drawable::bufferData(BufferType type, void* data, GLuint size) {
glBufferData(useElemArray.at(type) ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
}
void Drawable::deleteBuffer(BufferType type) {
glDeleteBuffers(1, &buffers[type]);
buffers.erase(type);
}