diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index f7293f406..2809dd445 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -612,20 +612,20 @@ void PostProcessing::renderMotionBlur(unsigned cam, FrameBuffer &in_fbo, FrameBu static void renderGodFade(GLuint tex, const SColor &col) { - glUseProgram(FullScreenShader::GodFadeShader::Program); - glBindVertexArray(FullScreenShader::GodFadeShader::vao); - setTexture(0, tex, GL_LINEAR, GL_LINEAR); - FullScreenShader::GodFadeShader::setUniforms(col, 0); + glUseProgram(FullScreenShader::GodFadeShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::GodFadeShader::getInstance()->vao); + setTexture(FullScreenShader::GodFadeShader::getInstance()->TU_tex, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::GodFadeShader::getInstance()->setUniforms(col); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } static void renderGodRay(GLuint tex, const core::vector2df &sunpos) { - glUseProgram(FullScreenShader::GodRayShader::Program); - glBindVertexArray(FullScreenShader::GodRayShader::vao); - setTexture(0, tex, GL_LINEAR, GL_LINEAR); - FullScreenShader::GodRayShader::setUniforms(sunpos, 0); + glUseProgram(FullScreenShader::GodRayShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::GodRayShader::getInstance()->vao); + setTexture(FullScreenShader::GodRayShader::getInstance()->TU_tex, tex, GL_LINEAR, GL_LINEAR); + FullScreenShader::GodRayShader::getInstance()->setUniforms(sunpos); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 142b8ca01..326e5ea68 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -389,8 +389,6 @@ void Shaders::loadShaders() FullScreenShader::DiffuseEnvMapShader::init(); FullScreenShader::RHDebug::init(); FullScreenShader::MotionBlurShader::init(); - FullScreenShader::GodFadeShader::init(); - FullScreenShader::GodRayShader::init(); FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); @@ -2009,48 +2007,28 @@ namespace FullScreenShader glUniform1i(uniform_dtex, TU_dtex); } - GLuint GodFadeShader::Program; - GLuint GodFadeShader::uniform_tex; - GLuint GodFadeShader::uniform_col; - GLuint GodFadeShader::vao; - - void GodFadeShader::init() + GodFadeShader::GodFadeShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/godfade.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_col = glGetUniformLocation(Program, "col"); + AssignUniforms("col"); + TU_tex = 0; + AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); vao = createVAO(Program); } - void GodFadeShader::setUniforms(const SColor &col, unsigned TU_tex) - { - glUniform3f(uniform_col, col.getRed() / 255.f, col.getGreen() / 255.f, col.getBlue() / 255.f); - glUniform1i(uniform_tex, TU_tex); - } - - GLuint GodRayShader::Program; - GLuint GodRayShader::uniform_tex; - GLuint GodRayShader::uniform_sunpos; - GLuint GodRayShader::vao; - - void GodRayShader::init() + GodRayShader::GodRayShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/godray.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_sunpos = glGetUniformLocation(Program, "sunpos"); + TU_tex = 0; + AssignUniforms("sunpos"); + AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); vao = createVAO(Program); } - void GodRayShader::setUniforms(const core::vector2df &sunpos, unsigned TU_tex) - { - glUniform2f(uniform_sunpos, sunpos.X, sunpos.Y); - glUniform1i(uniform_tex, TU_tex); - } - GLuint MLAAColorEdgeDetectionSHader::Program; GLuint MLAAColorEdgeDetectionSHader::uniform_colorMapG; GLuint MLAAColorEdgeDetectionSHader::uniform_PIXEL_SIZE; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index fc55d35b6..1920fb90d 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -146,7 +146,6 @@ protected: } public: - friend class Singleton; GLuint Program; void setUniforms(const Args & ... args) const @@ -764,26 +763,22 @@ public: static void setUniforms(float boost_amount, const core::matrix4 &previousVP, const core::vector2df ¢er, float mask_radius, unsigned TU_cb, unsigned TU_dtex); }; -class GodFadeShader +class GodFadeShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex, uniform_col; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); - static void setUniforms(const video::SColor &col, unsigned TU_tex); + GodFadeShader(); }; -class GodRayShader +class GodRayShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex, uniform_sunpos; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); - static void setUniforms(const core::vector2df &sunpos, unsigned TU_tex); + GodRayShader(); }; class MLAAColorEdgeDetectionSHader