-
Notifications
You must be signed in to change notification settings - Fork 0
/
RFTextureFramebuffer.mm
33 lines (28 loc) · 1.04 KB
/
RFTextureFramebuffer.mm
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
#import "RFTextureFramebuffer.h"
void RFTextureFramebuffer::use()
{
glActiveTexture(GL_TEXTURE1);
RFFramebuffer::use();
}
RFTextureFramebuffer::RFTextureFramebuffer(GLsizei _width, GLsizei _height, bool has_depth_attachement)
{
width = _width;
height = _height;
glActiveTexture(GL_TEXTURE1);
texture = new RFTexture(width, height);
glGenFramebuffers(1, &_id);
glBindFramebuffer(GL_FRAMEBUFFER, _id);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->get_id(), 0);
if (has_depth_attachement) {
GLuint depth_render_buffer;
glGenRenderbuffers(1, &depth_render_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, depth_render_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, width);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_render_buffer);
glEnable(GL_DEPTH_TEST);
}
this->test_for_completeness();
}
RFTextureFramebuffer::~RFTextureFramebuffer() {
delete texture;
}