-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVBO.cpp
42 lines (31 loc) · 820 Bytes
/
VBO.cpp
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
#include "VBO.h"
VBO::VBO(std::vector <Vertex>& vertices, bool isStatic)
{
glGenBuffers(1, &ID);
this->Bind();
isStatic
? glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STATIC_DRAW)
: glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STREAM_DRAW);
}
void VBO::SetVertices(std::vector<Vertex>& vertices)
{
this->Bind();
glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(Vertex), vertices.data());
}
void VBO::SetVertex(int index, Vertex& newVertex)
{
this->Bind();
glBufferSubData(GL_ARRAY_BUFFER, index * sizeof(Vertex), sizeof(Vertex), &newVertex);
}
void VBO::Bind()
{
glBindBuffer(GL_ARRAY_BUFFER, ID);
}
void VBO::Unbind()
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VBO::Delete()
{
glDeleteBuffers(1, &ID);
}