-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuffer.cpp
50 lines (40 loc) · 932 Bytes
/
buffer.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
#include "buffer.hpp"
namespace rematrix {
buffer::buffer(GLenum target, const void* data, GLsizeiptr size, GLenum usage)
{
glGenBuffers(1, &id_);
if (id_ == 0) {
throw runtime_error("couldn't generate buffer");
}
bind(target);
glBufferData(target, size, data, usage);
}
buffer::buffer(buffer&& other) noexcept
: id_ { other.id_ }
{
other.id_ = 0;
}
buffer::~buffer()
{
glDeleteBuffers(1, &id_);
}
buffer& buffer::operator=(buffer&& other) noexcept
{
id_ = other.id_;
other.id_ = 0;
return *this;
}
void buffer::bind(GLenum target)
{
glBindBuffer(target, id_);
}
//----------------------------------------------------------------------------
vertex_buffer::vertex_buffer(const void* data, GLsizeiptr size, GLenum usage)
: buffer { GL_ARRAY_BUFFER, data, size, usage }
{
}
void vertex_buffer::bind()
{
buffer::bind(GL_ARRAY_BUFFER);
}
} // namespace rematrix