68 lines
No EOL
2 KiB
C++
68 lines
No EOL
2 KiB
C++
#include "multipass.hpp"
|
|
#include <iostream>
|
|
|
|
bool Gbuffer::init(GLuint width, GLuint height) {
|
|
// frame buffer object
|
|
glGenFramebuffers(1, &fbo);
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
|
|
|
// gen texturen
|
|
glGenTextures(GBUFER_NUM_TEXTURES, textus);
|
|
glGenTextures(1, &depthtext);
|
|
|
|
for (GLuint i=0; i < GBUFER_NUM_TEXTURES; i++) {
|
|
glBindTexture(GL_TEXTURE_2D, textus[i]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textus[i], 0);
|
|
}
|
|
|
|
// tiefe (hehe tiefenschärfe = schärfentiefe)
|
|
glBindTexture(GL_TEXTURE_2D, depthtext);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
|
|
NULL);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthtext, 0);
|
|
|
|
GLenum malbuffer[]= { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4 };
|
|
glDrawBuffers(sizeof(malbuffer)/sizeof(malbuffer[0]), malbuffer);
|
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if(status!=GL_FRAMEBUFFER_COMPLETE){
|
|
std::cout<<"the framebuffer is incomplete.";
|
|
return false;
|
|
}
|
|
|
|
//den ursprünglichen framebuffer wiederherstellen
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
void Gbuffer::bind(){
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
}
|
|
|
|
void Gbuffer::bindR(){
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
|
}
|
|
void Gbuffer::bindW(){
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
|
}
|
|
|
|
void Gbuffer::clear(){
|
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
}
|
|
|
|
void Gbuffer::clearw(){
|
|
glClearColor(1.0, 1.0, 1.0, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
}
|
|
|
|
Gbuffer::Gbuffer(){}
|
|
Gbuffer::~Gbuffer(){} |