-
Notifications
You must be signed in to change notification settings - Fork 3
/
VBO.cpp
72 lines (49 loc) · 1.33 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "VBO.hpp"
// Constructor that generates a Vertex Buffer Object and links it to vertices
VBO::VBO(GLfloat* vertices, GLsizeiptr size)
{
// Generate a reference ID for the VBO
glGenBuffers(1, &ID);
glBindBuffer(GL_ARRAY_BUFFER, ID);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
}
// Constructor that only generates an ID for the VBO
VBO::VBO()
{
// Generate a reference ID for the VBO
glGenBuffers(1, &ID);
glBindBuffer(GL_ARRAY_BUFFER, ID);
}
// Bind the VBO
void VBO::Bind()
{
glBindBuffer(GL_ARRAY_BUFFER, ID);
}
// Unbind the VBO
void VBO::Unbind()
{
// Putting a 0 in glBindBuffer unbinds the currently
// bound buffer
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
// Deletes the VBO
void VBO::Delete()
{
// Pass in the VBO's reference ID to
// delete
glDeleteBuffers(1, &ID);
}
// Initializes the VBO from blank constructor
void VBO::InitVBO(GLfloat* vertices, GLsizeiptr size)
{
// Generate a reference ID for the VBO
glBindBuffer(GL_ARRAY_BUFFER, ID);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_DYNAMIC_DRAW);
}
// Initializes the VBO from blank constructor
void VBO::InitVBO(GLuint* vertices, GLsizeiptr size)
{
// Generate a reference ID for the VBO
glBindBuffer(GL_ARRAY_BUFFER, ID);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_DYNAMIC_DRAW);
}