-
Notifications
You must be signed in to change notification settings - Fork 0
/
UBO.tpp
53 lines (42 loc) · 1.53 KB
/
UBO.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
#ifndef UBO_TEMPLATE
#define UBO_TEMPLATE
#ifdef GL_API_GLAD_OPENGL_3
template <typename type>
UBO::UBO(type* data, GLsizeiptr size, GLenum howUse, const GLchar* name, GLuint shader, GLuint index) {
Init<type>(data, size, howUse, name, shader, index);
}
template <typename type>
void UBO::Init(type* data, GLsizeiptr size, GLenum howUse, const GLchar* name, GLuint shader, GLuint index) {
Init<type>(&ID, data, size, howUse, name, shader, index);
}
template <typename type>
void UBO::Init(GLuint* ID, type* data, GLsizeiptr size, GLenum howUse, const GLchar* name, GLuint shader, GLuint index) {
glUniformBlockBinding(shader, glGetUniformBlockIndex(shader, name), index);
glGenBuffers(1, ID);
Bind(*ID);
Data<type>(data, size, howUse);
}
template <typename type>
void UBO::Data(type* data, GLsizeiptr size, GLenum howUse) {
glBufferData(bufferType, size, data, howUse);
}
template <typename type>
void UBO::SubData(type* data, GLintptr offset, GLsizeiptr size) {
glBufferSubData(bufferType, offset, size, data);
}
template <typename type>
type* UBO::GetSubData(GLintptr offset, GLsizeiptr size) {
void* data = new char[size];
glGetBufferSubData(bufferType, offset, size, data);
return static_cast<type*>(data);
}
template <typename type>
type* UBO::Map(GLenum accessType) {
return static_cast<type*>(glMapBuffer(bufferType, accessType));
}
template <typename type>
type* UBO::MapRange(GLintptr offset, GLsizeiptr size, GLbitfield accessType) {
return static_cast<type*>(glMapBufferRange(bufferType, offset, size, accessType));
}
#endif
#endif