-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathframe_buffer.cpp
64 lines (53 loc) · 1.2 KB
/
frame_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "frame_buffer.hpp"
#include "decl.hpp"
namespace rematrix {
frame_buffer::frame_buffer()
{
glGenFramebuffers(1, &id_);
if (id_ == 0) {
throw runtime_error("couldn't generate frame buffer");
}
}
frame_buffer::frame_buffer(frame_buffer&& other) noexcept
: id_ { other.id_ }
{
other.id_ = 0;
}
frame_buffer::~frame_buffer()
{
glDeleteFramebuffers(1, &id_);
}
frame_buffer& frame_buffer::operator=(frame_buffer&& other) noexcept
{
id_ = other.id_;
other.id_ = 0;
return *this;
}
void frame_buffer::bind()
{
glBindFramebuffer(GL_FRAMEBUFFER, id_);
}
void frame_buffer::unbind()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void frame_buffer::draw_buffers(initializer_list<GLenum> bufs)
{
const vector<GLenum> bufs2 { bufs };
glDrawBuffers(bufs2.size(), bufs2.data());
}
void frame_buffer::attach(GLenum point, GLuint texture_id)
{
glFramebufferTexture2D(GL_FRAMEBUFFER,
point,
GL_TEXTURE_2D,
texture_id,
0);
}
void frame_buffer::check_complete() const
{
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw runtime_error("frame buffer isn't complete");
}
}
} // namespace rematrix