Use singletonshader template for colorize

This commit is contained in:
Vincent Lejeune 2014-08-07 02:29:13 +02:00
parent 87bf242164
commit 926fc3ac7c
3 changed files with 6 additions and 24 deletions

View File

@ -404,7 +404,6 @@ void Shaders::loadShaders()
FullScreenShader::MLAAColorEdgeDetectionSHader::init();
FullScreenShader::MLAABlendWeightSHader::init();
FullScreenShader::MLAAGatherSHader::init();
MeshShader::ColorizeShader::init();
MeshShader::BubbleShader::init();
LightShader::PointLightShader::init();
MeshShader::RSMShader::init();
@ -974,30 +973,17 @@ namespace MeshShader
AssignTextureUnit(Program, TexUnit(TU_tex, "tex"));
}
GLuint ColorizeShader::Program;
GLuint ColorizeShader::uniform_MM;
GLuint ColorizeShader::uniform_col;
void ColorizeShader::init()
ColorizeShader::ColorizeShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str());
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
uniform_col = glGetUniformLocation(Program, "col");
AssignUniforms("ModelMatrix", "col");
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void ColorizeShader::setUniforms(const core::matrix4 &ModelMatrix, float r, float g, float b)
{
if (irr_driver->needUBOWorkaround())
bypassUBO(Program);
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
glUniform3f(uniform_col, r, g, b);
}
ShadowShader::ShadowShader()
{
// Geometry shader needed

View File

@ -313,14 +313,10 @@ public:
};
class ColorizeShader
class ColorizeShader : public ShaderHelperSingleton<ColorizeShader, core::matrix4, video::SColorf>
{
public:
static GLuint Program;
static GLuint uniform_MM, uniform_col;
static void init();
static void setUniforms(const core::matrix4 &ModelMatrix, float r, float g, float b);
ColorizeShader();
};
class ShadowShader : public ShaderHelperSingleton<ShadowShader, core::matrix4>

View File

@ -142,7 +142,7 @@ void STKMeshSceneNode::drawGlow(const GLMesh &mesh)
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
MeshShader::ColorizeShader::setUniforms(AbsoluteTransformation, cb->getRed(), cb->getGreen(), cb->getBlue());
MeshShader::ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue()));
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
}
@ -312,7 +312,7 @@ void STKMeshSceneNode::render()
if (irr_driver->getPhase() == GLOW_PASS)
{
glUseProgram(MeshShader::ColorizeShader::Program);
glUseProgram(MeshShader::ColorizeShader::getInstance()->Program);
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);