-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferObject.h
More file actions
55 lines (42 loc) · 1.08 KB
/
BufferObject.h
File metadata and controls
55 lines (42 loc) · 1.08 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
#ifndef _BUFFER_OBJECT_H
#define _BUFFER_OBJECT_H
#include <vector>
#include <glm/glm.hpp>
#include <GL/glew.h>
#include <GL/glut.h>
template<GLuint T>
class BufferObject {
private:
static GLuint BINDING_COUNTER;
GLuint _id;
GLuint binding_index;
public:
static const GLuint TYPE = T;
BufferObject();
template <typename U> void transfer(const std::vector<U>& v, GLuint mode);
void allocate(GLuint size, GLuint mode);
GLuint id() {
return _id;
}
};
template <GLuint T> GLuint BufferObject<T>::BINDING_COUNTER = 0;
template <GLuint T>
BufferObject<T>::BufferObject() {
glGenBuffers(1, &_id);
binding_index = BINDING_COUNTER;
BINDING_COUNTER++;
}
template <GLuint T>
template <typename U>
void BufferObject<T>::transfer(const std::vector<U>& v, GLuint mode) {
glBindBuffer(T, _id);
glBufferData(T, sizeof(U)*v.size(), v.data(), mode);
glBindBufferBase( T, binding_index, _id );
}
template <GLuint T>
void BufferObject<T>::allocate(GLuint size, GLuint mode) {
glBindBuffer(T, _id);
glBufferData(T, size, NULL, mode);
glBindBufferBase( T, binding_index, _id );
}
#endif