123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "client/engine/shader/WorldPostShader.h"
- #include "client/engine/Wrapper.h"
- WorldPostShader::WorldPostShader()
- {
- }
- WorldPostShader::~WorldPostShader()
- {
- glDeleteFramebuffers(1, &framebuffer);
- glDeleteTextures(1, &texture);
- }
- bool WorldPostShader::init()
- {
- program.compile("resources/shader/worldPostVertex.vs", "resources/shader/worldPostFragment.fs");
- if(!program.isValid())
- {
- return false;
- }
-
- // generate framebuffer
- glGenFramebuffers(1, &framebuffer);
- glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-
- // color texture
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- // attache color texture to framebuffer
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
-
- // check if framebuffer is okay
- if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
- {
- cout << "world post frame buffer is not complete!" << endl;
- return false;
- }
- // unbind framebuffer
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- return true;
- }
- void WorldPostShader::resize()
- {
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- void WorldPostShader::preRender()
- {
- // bind ssao shader program
- glUseProgram(program.getProgram());
-
- // bind ssao framebuffer
- glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-
- // clear color buffer
- glClear(GL_COLOR_BUFFER_BIT);
-
- // depth testing is not needed
- glDisable(GL_DEPTH_TEST);
- }
- void WorldPostShader::bindTexture(unsigned int textureUnit)
- {
- glActiveTexture(GL_TEXTURE0 + textureUnit);
- glBindTexture(GL_TEXTURE_2D, texture);
- }
|