-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFramebuffer.cpp
More file actions
50 lines (40 loc) · 1.62 KB
/
Framebuffer.cpp
File metadata and controls
50 lines (40 loc) · 1.62 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
#include "Framebuffer.h"
Framebuffer::Framebuffer(int width, int height, GLenum access) : Framebuffer(width, height, access,
GL_COLOR_ATTACHMENT0) {
}
Framebuffer::Framebuffer(int width, int height, GLenum access, GLuint texture) {
glGenFramebuffers(1, &this->m_fbo);
this->m_colorTexture = new Texture(width, height, access);
this->m_colorTexture->use();
this->bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, texture, GL_TEXTURE_2D, this->m_colorTexture->id, 0);
// glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, this->m_colorTexture->id, 0);
this->checkErrors();
this->unbind();
}
Framebuffer::~Framebuffer() {
glDeleteFramebuffers(1, &this->m_fbo);
delete this->m_colorTexture;
}
void Framebuffer::checkErrors() {
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
std::cout << "ERROR::FRAMEBUFFER - Framebuffer is incomplete!" << std::endl;
}
}
void Framebuffer::bind() {
this->m_colorTexture->use();
GLenum drawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, drawBuffers);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, this->m_fbo);
glViewport(0, 0, this->m_colorTexture->getWidth(), this->m_colorTexture->getHeight());
// glViewport(0, 0, this->m_colorTexture->getWidth() / 2, this->m_colorTexture->getHeight() / 2);
}
void Framebuffer::unbind() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
Texture *Framebuffer::getTextureAttachment() const {
return this->m_colorTexture;
}
GLuint Framebuffer::getId() const {
return this->m_fbo;
}