-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertexBuffer.cpp
More file actions
66 lines (54 loc) · 1.23 KB
/
Copy pathvertexBuffer.cpp
File metadata and controls
66 lines (54 loc) · 1.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "vertexBuffer.h"
vertexBuffer::vertexBuffer()
{
glGenBuffers(1, &id);
if (!id) { throw std::exception(); }
dirty = true;
components = -1;
}
vertexBuffer::~vertexBuffer()
{
glDeleteBuffers(1, &id);
}
void vertexBuffer::addData(glm::vec2 _value)
{
if (components == -1) { components = 2; }
else if (components != 2) { throw std::exception(); }
data.push_back(_value.x);
data.push_back(_value.y);
dirty = true;
}
void vertexBuffer::addData(glm::vec3 _value)
{
if (components == -1) { components = 3; }
else if (components != 3) { throw std::exception(); }
data.push_back(_value.x);
data.push_back(_value.y);
data.push_back(_value.z);
dirty = true;
}
void vertexBuffer::addData(glm::vec4 _value)
{
if (components == -1) { components = 4; }
else if (components != 4) { throw std::exception(); }
data.push_back(_value.x);
data.push_back(_value.y);
data.push_back(_value.z);
data.push_back(_value.w);
dirty = true;
}
int vertexBuffer::getComponents()
{
return components;
}
GLuint vertexBuffer::getId()
{
if (dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, id);
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(data.at(0)), &data.at(0), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
dirty = false;
}
return id;
}