-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBO.tpp
87 lines (69 loc) · 1.89 KB
/
VBO.tpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef VBO_TEMPLATE
#define VBO_TEMPLATE
#ifdef GL_API_GLAD_OPENGL_3
template <typename type>
VBO<type>::VBO(type* vertices, GLsizeiptr size, GLenum howUse) {
Init(vertices, size, howUse);
}
template <typename type>
VBO<type>::~VBO() {
Delete();
}
template <typename type>
void VBO<type>::Init(type* vertices, GLsizeiptr size, GLenum howUse) {
Init(&ID, vertices, size, howUse);
}
template <typename type>
void VBO<type>::Init(GLuint* ID, type* vertices, GLsizeiptr size, GLenum howUse) {
glGenBuffers(1, ID);
Bind(*ID);
Data(vertices, size, howUse);
}
template <typename type>
void VBO<type>::Data(type* vertices, GLsizeiptr size, GLenum howUse) {
glBufferData(bufferType, size, vertices, howUse);
}
template <typename type>
void VBO<type>::SubData(type* vertices, GLintptr offset, GLsizeiptr size) {
glBufferSubData(bufferType, offset, size, vertices);
}
template <typename type>
type* VBO<type>::GetSubData(GLintptr offset, GLsizeiptr size) {
void* vertices = new char[size];
glGetBufferSubData(GL_UNIFORM_BUFFER, offset, size, vertices);
return static_cast<type*>(vertices);
}
template <typename type>
type* VBO<type>::Map(GLenum accessType) {
return static_cast<type*>(glMapBuffer(bufferType, accessType));
}
template <typename type>
type* VBO<type>::MapRange(GLintptr offset, GLsizeiptr size, GLbitfield accessType) {
return static_cast<type*>(glMapBufferRange(bufferType, offset, size, accessType));
}
template <typename type>
void VBO<type>::Unmap() {
glUnmapBuffer(bufferType);
}
template <typename type>
void VBO<type>::Bind() {
Bind(ID);
}
template <typename type>
void VBO<type>::Bind(GLuint ID) {
glBindBuffer(bufferType, ID);
}
template <typename type>
void VBO<type>::Unbind() {
glBindBuffer(bufferType, 0);
}
template <typename type>
void VBO<type>::Delete() {
Delete(&ID);
}
template <typename type>
void VBO<type>::Delete(GLuint* ID) {
glDeleteBuffers(1, ID);
}
#endif
#endif