diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 36aca0d58..7121e52ef 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -446,15 +446,11 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &a void PostProcessing::renderPassThrough(GLuint tex) { + glUseProgram(FullScreenShader::PassThroughShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::PassThroughShader::getInstance()->vao); - glUseProgram(FullScreenShader::PassThroughShader::Program); - glBindVertexArray(FullScreenShader::PassThroughShader::vao); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glUniform1i(FullScreenShader::PassThroughShader::uniform_texture, 0); + setTexture(FullScreenShader::PassThroughShader::getInstance()->TU_tex, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::PassThroughShader::getInstance()->setUniforms(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } @@ -476,18 +472,15 @@ void PostProcessing::renderTextureLayer(unsigned tex, unsigned layer) void PostProcessing::renderGlow(unsigned tex) { + glUseProgram(FullScreenShader::GlowShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::GlowShader::getInstance()->vao); - glUseProgram(FullScreenShader::GlowShader::Program); - glBindVertexArray(FullScreenShader::GlowShader::vao); - - setTexture(0, tex, GL_LINEAR, GL_LINEAR); - glUniform1i(FullScreenShader::GlowShader::uniform_tex, 0); + setTexture(FullScreenShader::GlowShader::getInstance()->TU_tex, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::GlowShader::getInstance()->setUniforms(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } -ITexture *noise_tex = 0; - void PostProcessing::renderSSAO() { glDisable(GL_DEPTH_TEST); @@ -503,9 +496,6 @@ void PostProcessing::renderSSAO() glDrawArrays(GL_TRIANGLES, 0, 3); irr_driver->getFBO(FBO_SSAO).Bind(); - if (!noise_tex) - noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str()); - glUseProgram(FullScreenShader::SSAOShader::getInstance()->Program); glBindVertexArray(FullScreenShader::SSAOShader::getInstance()->vao); @@ -634,13 +624,6 @@ static void renderDoF(FrameBuffer &fbo, GLuint rtt) glDrawArrays(GL_TRIANGLES, 0, 3); } -static void averageTexture(GLuint tex) -{ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, tex); - glGenerateMipmap(GL_TEXTURE_2D); -} - void PostProcessing::applyMLAA() { const core::vector2df &PIXEL_SIZE = core::vector2df(1.0f / UserConfigParams::m_width, 1.0f / UserConfigParams::m_height); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index cc3089c7a..45b2fc97c 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -373,8 +373,6 @@ void Shaders::loadShaders() initCubeVBO(); initFrustrumVBO(); initShadowVPMUBO(); - FullScreenShader::GlowShader::init(); - FullScreenShader::PassThroughShader::init(); FullScreenShader::LayerPassThroughShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); FullScreenShader::RHDebug::init(); @@ -1840,15 +1838,14 @@ namespace FullScreenShader vao = createFullScreenVAO(Program); } - GLuint PassThroughShader::Program; - GLuint PassThroughShader::uniform_texture; - GLuint PassThroughShader::vao; - void PassThroughShader::init() + PassThroughShader::PassThroughShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/texturedquad.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "texture"); + TU_tex = 0; + AssignUniforms(); + AssignTextureUnit(Program, TexUnit(TU_tex, "texture")); vao = createVAO(Program); } @@ -1877,15 +1874,14 @@ namespace FullScreenShader vao = createFullScreenVAO(Program); } - GLuint GlowShader::Program; - GLuint GlowShader::uniform_tex; - GLuint GlowShader::vao; - void GlowShader::init() + GlowShader::GlowShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/glow.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); + AssignUniforms(); + TU_tex = 0; + AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); vao = createVAO(Program); } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index b823887f9..81545f3fb 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -682,14 +682,13 @@ public: Gaussian3VBlurShader(); }; -class PassThroughShader +class PassThroughShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_texture; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); + PassThroughShader(); }; class LayerPassThroughShader @@ -711,14 +710,13 @@ public: LinearizeDepthShader(); }; -class GlowShader +class GlowShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); + GlowShader(); }; class SSAOShader : public ShaderHelperSingleton