Port instancing shaders to singleton.

This commit is contained in:
Vincent Lejeune 2014-07-30 00:34:00 +02:00
parent b935e9316a
commit f1c29ad26f
3 changed files with 26 additions and 74 deletions

View File

@ -405,12 +405,6 @@ void Shaders::loadShaders()
FullScreenShader::MLAABlendWeightSHader::init();
FullScreenShader::MLAAGatherSHader::init();
MeshShader::ColorizeShader::init();
MeshShader::InstancedObjectPass1ShaderInstance = new MeshShader::InstancedObjectPass1Shader();
MeshShader::InstancedObjectRefPass1ShaderInstance = new MeshShader::InstancedObjectRefPass1Shader();
MeshShader::InstancedGrassPass1ShaderInstance = new MeshShader::InstancedGrassPass1Shader();
MeshShader::InstancedObjectPass2ShaderInstance = new MeshShader::InstancedObjectPass2Shader();
MeshShader::InstancedObjectRefPass2ShaderInstance = new MeshShader::InstancedObjectRefPass2Shader();
MeshShader::InstancedGrassPass2ShaderInstance = new MeshShader::InstancedGrassPass2Shader();
MeshShader::BubbleShader::init();
MeshShader::BillboardShader::init();
LightShader::PointLightShader::init();
@ -682,8 +676,6 @@ namespace MeshShader
}
}
InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
InstancedObjectRefPass1Shader::InstancedObjectRefPass1Shader()
{
Program = LoadProgram(
@ -700,8 +692,6 @@ namespace MeshShader
}
}
InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
InstancedGrassPass1Shader::InstancedGrassPass1Shader()
{
Program = LoadProgram(
@ -719,8 +709,6 @@ namespace MeshShader
}
}
InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
// Solid Lit pass shaders
ObjectPass2Shader::ObjectPass2Shader()
{
@ -744,8 +732,6 @@ namespace MeshShader
);
}
ObjectPass2Shader *ObjectPass2ShaderInstance;
InstancedObjectPass2Shader::InstancedObjectPass2Shader()
{
Program = LoadProgram(
@ -770,8 +756,6 @@ namespace MeshShader
}
}
InstancedObjectPass2Shader *InstancedObjectPass2ShaderInstance;
InstancedObjectRefPass2Shader::InstancedObjectRefPass2Shader()
{
Program = LoadProgram(
@ -793,8 +777,6 @@ namespace MeshShader
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
DetailledObjectPass2Shader::DetailledObjectPass2Shader()
{
Program = LoadProgram(
@ -816,8 +798,6 @@ namespace MeshShader
);
}
DetailledObjectPass2Shader *DetailledObjectPass2ShaderInstance;
ObjectUnlitShader::ObjectUnlitShader()
{
Program = LoadProgram(
@ -834,8 +814,6 @@ namespace MeshShader
AssignTextureUnit(Program, TexUnit(TU_tex, "tex"));
}
ObjectUnlitShader *ObjectUnlitShaderInstance;
ObjectRefPass2Shader::ObjectRefPass2Shader()
{
Program = LoadProgram(
@ -858,8 +836,6 @@ namespace MeshShader
);
}
ObjectRefPass2Shader *ObjectRefPass2ShaderInstance;
GrassPass2Shader::GrassPass2Shader()
{
Program = LoadProgram(
@ -877,8 +853,6 @@ namespace MeshShader
);
}
GrassPass2Shader *GrassPass2ShaderInstance;
InstancedGrassPass2Shader::InstancedGrassPass2Shader()
{
Program = LoadProgram(
@ -902,8 +876,6 @@ namespace MeshShader
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
InstancedGrassPass2Shader *InstancedGrassPass2ShaderInstance;
SphereMapShader::SphereMapShader()
{
Program = LoadProgram(
@ -927,8 +899,6 @@ namespace MeshShader
);
}
SphereMapShader *SphereMapShaderInstance;
SplattingShader::SplattingShader()
{
Program = LoadProgram(
@ -953,8 +923,6 @@ namespace MeshShader
);
}
SplattingShader *SplattingShaderInstance;
GLuint BubbleShader::Program;
GLuint BubbleShader::uniform_MVP;
GLuint BubbleShader::uniform_tex;
@ -995,8 +963,6 @@ namespace MeshShader
AssignTextureUnit(Program, TexUnit(TU_tex, "tex"));
}
TransparentShader *TransparentShaderInstance;
TransparentFogShader::TransparentFogShader()
{
Program = LoadProgram(
@ -1013,8 +979,6 @@ namespace MeshShader
AssignTextureUnit(Program, TexUnit(TU_tex, "tex"));
}
TransparentFogShader *TransparentFogShaderInstance;
GLuint BillboardShader::Program;
GLuint BillboardShader::attrib_corner;
GLuint BillboardShader::attrib_texcoord;

View File

@ -195,7 +195,7 @@ public:
NormalMapShader();
};
class InstancedObjectPass1Shader : public ShaderHelper<>
class InstancedObjectPass1Shader : public ShaderHelperSingleton<InstancedObjectPass1Shader>
{
public:
GLuint TU_tex;
@ -203,9 +203,7 @@ public:
InstancedObjectPass1Shader();
};
extern InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
class InstancedObjectRefPass1Shader : public ShaderHelper<>
class InstancedObjectRefPass1Shader : public ShaderHelperSingleton<InstancedObjectRefPass1Shader>
{
public:
GLuint TU_tex;
@ -213,9 +211,7 @@ public:
InstancedObjectRefPass1Shader();
};
extern InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
class InstancedGrassPass1Shader : public ShaderHelper<core::vector3df>
class InstancedGrassPass1Shader : public ShaderHelperSingleton<InstancedGrassPass1Shader, core::vector3df>
{
public:
GLuint TU_tex;
@ -223,8 +219,6 @@ public:
InstancedGrassPass1Shader();
};
extern InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
class ObjectPass2Shader : public ShaderHelperSingleton<ObjectPass2Shader, core::matrix4, core::matrix4>
{
public:
@ -233,7 +227,7 @@ public:
ObjectPass2Shader();
};
class InstancedObjectPass2Shader : public ShaderHelper<video::SColorf>
class InstancedObjectPass2Shader : public ShaderHelperSingleton<InstancedObjectPass2Shader>
{
public:
GLuint TU_Albedo;
@ -241,9 +235,7 @@ public:
InstancedObjectPass2Shader();
};
extern InstancedObjectPass2Shader *InstancedObjectPass2ShaderInstance;
class InstancedObjectRefPass2Shader : public ShaderHelper<video::SColorf>
class InstancedObjectRefPass2Shader : public ShaderHelperSingleton<InstancedObjectRefPass2Shader>
{
public:
GLuint TU_Albedo;
@ -251,8 +243,6 @@ public:
InstancedObjectRefPass2Shader();
};
extern InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
class DetailledObjectPass2Shader : public ShaderHelperSingleton<DetailledObjectPass2Shader, core::matrix4>
{
public:
@ -285,7 +275,7 @@ public:
GrassPass2Shader();
};
class InstancedGrassPass2Shader : public ShaderHelper<core::vector3df, core::vector3df>
class InstancedGrassPass2Shader : public ShaderHelperSingleton<InstancedGrassPass2Shader, core::vector3df, core::vector3df>
{
public:
GLuint TU_Albedo, TU_dtex;
@ -293,8 +283,6 @@ public:
InstancedGrassPass2Shader();
};
extern InstancedGrassPass2Shader *InstancedGrassPass2ShaderInstance;
class SphereMapShader : public ShaderHelperSingleton<SphereMapShader, core::matrix4, core::matrix4>
{
public:

View File

@ -129,15 +129,15 @@ static void drawFSPMDefault(GLMesh &mesh, size_t instance_count)
if (mesh.textures[0])
{
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::InstancedObjectPass1ShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::InstancedObjectPass1Shader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
}
else
{
setTexture(MeshShader::InstancedObjectPass1ShaderInstance->TU_tex, 0, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, false);
setTexture(MeshShader::InstancedObjectPass1Shader::getInstance()->TU_tex, 0, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, false);
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
MeshShader::InstancedObjectPass1ShaderInstance->setUniforms();
MeshShader::InstancedObjectPass1Shader::getInstance()->setUniforms();
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -170,8 +170,8 @@ static void drawFSPMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::InstancedObjectRefPass1ShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1ShaderInstance->setUniforms();
setTexture(MeshShader::InstancedObjectRefPass1Shader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1Shader::getInstance()->setUniforms();
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -215,8 +215,8 @@ static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t i
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::InstancedGrassPass1ShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1ShaderInstance->setUniforms(windDir);
setTexture(MeshShader::InstancedGrassPass1Shader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1Shader::getInstance()->setUniforms(windDir);
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -229,7 +229,7 @@ static void drawSMDefault(GLMesh &mesh, size_t instance_count)
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(MeshShader::InstancedObjectPass2ShaderInstance->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::InstancedObjectPass2Shader::getInstance()->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
@ -241,7 +241,7 @@ static void drawSMDefault(GLMesh &mesh, size_t instance_count)
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
MeshShader::InstancedObjectPass2ShaderInstance->setUniforms(irr_driver->getSceneManager()->getAmbientLight());
MeshShader::InstancedObjectPass2Shader::getInstance()->setUniforms();
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -255,7 +255,7 @@ static void drawSMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::InstancedObjectRefPass2ShaderInstance->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::InstancedObjectRefPass2Shader::getInstance()->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
@ -267,7 +267,7 @@ static void drawSMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
MeshShader::InstancedObjectRefPass2ShaderInstance->setUniforms(irr_driver->getSceneManager()->getAmbientLight());
MeshShader::InstancedObjectRefPass2Shader::getInstance()->setUniforms();
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -281,7 +281,7 @@ static void drawSMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t ins
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::InstancedGrassPass2ShaderInstance->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(MeshShader::InstancedGrassPass2Shader::getInstance()->TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
@ -292,10 +292,10 @@ static void drawSMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t ins
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
setTexture(MeshShader::InstancedGrassPass2ShaderInstance->TU_dtex, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
setTexture(MeshShader::InstancedGrassPass2Shader::getInstance()->TU_dtex, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT);
MeshShader::InstancedGrassPass2ShaderInstance->setUniforms(windDir, cb->getPosition());
MeshShader::InstancedGrassPass2Shader::getInstance()->setUniforms(windDir, cb->getPosition());
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -317,18 +317,18 @@ void STKInstancedSceneNode::render()
ModelViewProjectionMatrix *= irr_driver->getViewMatrix();
if (!MeshSolidMaterial[MAT_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass1ShaderInstance->Program);
glUseProgram(MeshShader::InstancedObjectPass1Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
drawFSPMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9);
if (!MeshSolidMaterial[MAT_ALPHA_REF].empty())
glUseProgram(MeshShader::InstancedObjectRefPass1ShaderInstance->Program);
glUseProgram(MeshShader::InstancedObjectRefPass1Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
drawFSPMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9);
windDir = getWind();
if (!MeshSolidMaterial[MAT_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass1ShaderInstance->Program);
glUseProgram(MeshShader::InstancedGrassPass1Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
drawFSPMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9);
return;
@ -337,17 +337,17 @@ void STKInstancedSceneNode::render()
if (irr_driver->getPhase() == SOLID_LIT_PASS)
{
if (!MeshSolidMaterial[MAT_DEFAULT].empty())
glUseProgram(MeshShader::InstancedObjectPass2ShaderInstance->Program);
glUseProgram(MeshShader::InstancedObjectPass2Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
drawSMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9);
if (!MeshSolidMaterial[MAT_ALPHA_REF].empty())
glUseProgram(MeshShader::InstancedObjectRefPass2ShaderInstance->Program);
glUseProgram(MeshShader::InstancedObjectRefPass2Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
drawSMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9);
if (!MeshSolidMaterial[MAT_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass2ShaderInstance->Program);
glUseProgram(MeshShader::InstancedGrassPass2Shader::getInstance()->Program);
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
drawSMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9);
return;