-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexBuffer.hpp
More file actions
66 lines (52 loc) · 1.49 KB
/
Copy pathVertexBuffer.hpp
File metadata and controls
66 lines (52 loc) · 1.49 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
#pragma once
#include <glad/glad.h>
#include <utility>
#include <span>
#include <vector>
class VertexBuffer {
private:
GLuint id;
public:
VertexBuffer(){
glGenBuffers(1, &id);
}
~VertexBuffer(){
if(id!=0){
glDeleteBuffers(1,&id);
}
}
void bind(){
glBindBuffer(GL_ARRAY_BUFFER, id);
}
void unbind(){
glBindBuffer(GL_ARRAY_BUFFER,0);
}
//Case we reserve the space and also add the data
template<typename T, size_t N>
void setData(const T (&data)[N],GLenum usage){
bind();
glBufferData(GL_ARRAY_BUFFER, N * sizeof(T), data, usage);
}
//for vectors
template<typename T>
void setData(const std::vector<T> &data,GLenum usage){
bind();
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(T), data.data(), usage);
}
//Case we only reserve the space
void setData(GLsizeiptr sizeInBytes, GLenum usage) {
bind();
glBufferData(GL_ARRAY_BUFFER, sizeInBytes, nullptr, usage);
}
//Maybe I need the offset for threading in the future
template<typename T, size_t N>
void updateSubData(GLintptr offset, const T (&data)[N]){
bind();
glBufferSubData(GL_ARRAY_BUFFER, offset, N * sizeof(T), data);
}
template<typename T>
void updateSubData(GLintptr offset, const std::vector<T> &data){
bind();
glBufferSubData(GL_ARRAY_BUFFER, offset, data.size() * sizeof(T), data.data());
}
};