Use singleton template again.
This commit is contained in:
parent
3684d22ef8
commit
b79cebba40
@ -117,10 +117,10 @@ void IrrDriver::renderSolidFirstPass()
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, enum E_VERTEX_TYPE VertexType, typename... TupleType>
|
||||
void renderMeshes2ndPass(const T *Shader, const std::vector<GLuint> &TexUnits, std::vector<std::tuple<TupleType...> > &meshes)
|
||||
template<typename Shader, enum E_VERTEX_TYPE VertexType, typename... TupleType>
|
||||
void renderMeshes2ndPass(const std::vector<GLuint> &TexUnits, std::vector<std::tuple<TupleType...> > &meshes)
|
||||
{
|
||||
glUseProgram(Shader->Program);
|
||||
glUseProgram(Shader::getInstance<Shader>()->Program);
|
||||
glBindVertexArray(getVAO(VertexType));
|
||||
for (unsigned i = 0; i < meshes.size(); i++)
|
||||
{
|
||||
@ -150,7 +150,7 @@ void renderMeshes2ndPass(const T *Shader, const std::vector<GLuint> &TexUnits, s
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
apply_instance<T>(Shader, meshes[i]);
|
||||
apply_instance(Shader::getInstance<Shader>(), meshes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,14 +193,14 @@ void IrrDriver::renderSolidSecondPass()
|
||||
|
||||
m_scene_manager->drawAll(scene::ESNRP_SOLID);
|
||||
|
||||
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD>(MeshShader::ObjectPass2ShaderInstance, { MeshShader::ObjectPass2ShaderInstance->TU_Albedo }, ListDefaultStandardSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS>(MeshShader::ObjectPass2ShaderInstance, { MeshShader::ObjectPass2ShaderInstance->TU_Albedo }, ListDefaultTangentSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD>(MeshShader::ObjectRefPass2ShaderInstance, { MeshShader::ObjectRefPass2ShaderInstance->TU_Albedo }, ListAlphaRefSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::SphereMapShader, video::EVT_STANDARD>(MeshShader::SphereMapShaderInstance, { MeshShader::SphereMapShaderInstance->TU_tex }, ListSphereMapSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectUnlitShader, video::EVT_STANDARD>(MeshShader::ObjectUnlitShaderInstance, { MeshShader::ObjectUnlitShaderInstance->TU_tex }, ListUnlitSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::DetailledObjectPass2Shader, video::EVT_2TCOORDS>(MeshShader::DetailledObjectPass2ShaderInstance, { MeshShader::DetailledObjectPass2ShaderInstance->TU_Albedo, MeshShader::DetailledObjectPass2ShaderInstance->TU_detail }, ListDetailSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::SplattingShader, video::EVT_2TCOORDS>(MeshShader::SplattingShaderInstance, { 8, MeshShader::SplattingShaderInstance->TU_tex_layout, MeshShader::SplattingShaderInstance->TU_tex_detail0, MeshShader::SplattingShaderInstance->TU_tex_detail1, MeshShader::SplattingShaderInstance->TU_tex_detail2, MeshShader::SplattingShaderInstance->TU_tex_detail3 }, ListSplattingSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::GrassPass2Shader, video::EVT_STANDARD>(MeshShader::GrassPass2ShaderInstance, { MeshShader::GrassPass2ShaderInstance->TU_Albedo }, ListGrassSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_STANDARD>({ MeshShader::ObjectPass2Shader::getInstance<MeshShader::ObjectPass2Shader>()->TU_Albedo }, ListDefaultStandardSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectPass2Shader, video::EVT_TANGENTS>({ MeshShader::ObjectPass2Shader::getInstance<MeshShader::ObjectPass2Shader>()->TU_Albedo }, ListDefaultTangentSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectRefPass2Shader, video::EVT_STANDARD>({ MeshShader::ObjectRefPass2Shader::getInstance<MeshShader::ObjectRefPass2Shader>()->TU_Albedo }, ListAlphaRefSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::SphereMapShader, video::EVT_STANDARD>({ MeshShader::SphereMapShader::getInstance<MeshShader::SphereMapShader>()->TU_tex }, ListSphereMapSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::ObjectUnlitShader, video::EVT_STANDARD>({ MeshShader::ObjectUnlitShader::getInstance<MeshShader::ObjectUnlitShader>()->TU_tex }, ListUnlitSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::DetailledObjectPass2Shader, video::EVT_2TCOORDS>({ MeshShader::DetailledObjectPass2Shader::getInstance<MeshShader::DetailledObjectPass2Shader>()->TU_Albedo, MeshShader::DetailledObjectPass2Shader::getInstance<MeshShader::DetailledObjectPass2Shader>()->TU_detail }, ListDetailSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::SplattingShader, video::EVT_2TCOORDS>({ 8, MeshShader::SplattingShader::getInstance<MeshShader::SplattingShader>()->TU_tex_layout, MeshShader::SplattingShader::getInstance<MeshShader::SplattingShader>()->TU_tex_detail0, MeshShader::SplattingShader::getInstance<MeshShader::SplattingShader>()->TU_tex_detail1, MeshShader::SplattingShader::getInstance<MeshShader::SplattingShader>()->TU_tex_detail2, MeshShader::SplattingShader::getInstance<MeshShader::SplattingShader>()->TU_tex_detail3 }, ListSplattingSM::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::GrassPass2Shader, video::EVT_STANDARD>({ MeshShader::GrassPass2Shader::getInstance<MeshShader::GrassPass2Shader>()->TU_Albedo }, ListGrassSM::Arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,16 +227,16 @@ void IrrDriver::renderTransparent()
|
||||
if (World::getWorld() && World::getWorld()->isFogEnabled())
|
||||
{
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, { MeshShader::TransparentFogShaderInstance->TU_tex }, ListBlendTransparentFog::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::getInstance<MeshShader::TransparentFogShader>()->TU_tex }, ListBlendTransparentFog::Arguments);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>(MeshShader::TransparentFogShaderInstance, { MeshShader::TransparentFogShaderInstance->TU_tex }, ListAdditiveTransparentFog::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentFogShader, video::EVT_STANDARD>({ MeshShader::TransparentFogShader::getInstance<MeshShader::TransparentFogShader>()->TU_tex }, ListAdditiveTransparentFog::Arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, { MeshShader::TransparentShaderInstance->TU_tex }, ListBlendTransparent::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::getInstance<MeshShader::TransparentShader>()->TU_tex }, ListBlendTransparent::Arguments);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>(MeshShader::TransparentShaderInstance, { MeshShader::TransparentShaderInstance->TU_tex }, ListAdditiveTransparent::Arguments);
|
||||
renderMeshes2ndPass<MeshShader::TransparentShader, video::EVT_STANDARD>({ MeshShader::TransparentShader::getInstance<MeshShader::TransparentShader>()->TU_tex }, ListAdditiveTransparent::Arguments);
|
||||
}
|
||||
|
||||
if (!UserConfigParams::m_dynamic_lights)
|
||||
|
@ -328,19 +328,10 @@ void Shaders::loadShaders()
|
||||
MeshShader::InstancedObjectPass1ShaderInstance = new MeshShader::InstancedObjectPass1Shader();
|
||||
MeshShader::InstancedObjectRefPass1ShaderInstance = new MeshShader::InstancedObjectRefPass1Shader();
|
||||
MeshShader::InstancedGrassPass1ShaderInstance = new MeshShader::InstancedGrassPass1Shader();
|
||||
MeshShader::ObjectPass2ShaderInstance = new MeshShader::ObjectPass2Shader();
|
||||
MeshShader::InstancedObjectPass2ShaderInstance = new MeshShader::InstancedObjectPass2Shader();
|
||||
MeshShader::InstancedObjectRefPass2ShaderInstance = new MeshShader::InstancedObjectRefPass2Shader();
|
||||
MeshShader::InstancedGrassPass2ShaderInstance = new MeshShader::InstancedGrassPass2Shader();
|
||||
MeshShader::DetailledObjectPass2ShaderInstance = new MeshShader::DetailledObjectPass2Shader();
|
||||
MeshShader::ObjectRefPass2ShaderInstance = new MeshShader::ObjectRefPass2Shader();
|
||||
MeshShader::ObjectUnlitShaderInstance = new MeshShader::ObjectUnlitShader();
|
||||
MeshShader::SphereMapShaderInstance = new MeshShader::SphereMapShader();
|
||||
MeshShader::SplattingShaderInstance = new MeshShader::SplattingShader();
|
||||
MeshShader::GrassPass2ShaderInstance = new MeshShader::GrassPass2Shader();
|
||||
MeshShader::BubbleShader::init();
|
||||
MeshShader::TransparentShaderInstance = new MeshShader::TransparentShader();
|
||||
MeshShader::TransparentFogShaderInstance = new MeshShader::TransparentFogShader();
|
||||
MeshShader::BillboardShader::init();
|
||||
LightShader::PointLightShader::init();
|
||||
MeshShader::DisplaceShaderInstance = new MeshShader::DisplaceShader();
|
||||
|
@ -198,7 +198,7 @@ public:
|
||||
|
||||
extern InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
|
||||
|
||||
class ObjectPass2Shader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
|
||||
class ObjectPass2Shader : public ShaderHelperSingleton<ObjectPass2Shader, core::matrix4, core::matrix4, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Albedo;
|
||||
@ -206,8 +206,6 @@ public:
|
||||
ObjectPass2Shader();
|
||||
};
|
||||
|
||||
extern ObjectPass2Shader *ObjectPass2ShaderInstance;
|
||||
|
||||
class InstancedObjectPass2Shader : public ShaderHelper<video::SColorf>
|
||||
{
|
||||
public:
|
||||
@ -228,7 +226,7 @@ public:
|
||||
|
||||
extern InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
|
||||
|
||||
class DetailledObjectPass2Shader : public ShaderHelper<core::matrix4, video::SColorf>
|
||||
class DetailledObjectPass2Shader : public ShaderHelperSingleton<DetailledObjectPass2Shader, core::matrix4, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Albedo, TU_detail;
|
||||
@ -236,9 +234,7 @@ public:
|
||||
DetailledObjectPass2Shader();
|
||||
};
|
||||
|
||||
extern DetailledObjectPass2Shader *DetailledObjectPass2ShaderInstance;
|
||||
|
||||
class ObjectUnlitShader : public ShaderHelper<core::matrix4>
|
||||
class ObjectUnlitShader : public ShaderHelperSingleton<ObjectUnlitShader, core::matrix4>
|
||||
{
|
||||
public:
|
||||
GLuint TU_tex;
|
||||
@ -246,9 +242,7 @@ public:
|
||||
ObjectUnlitShader();
|
||||
};
|
||||
|
||||
extern ObjectUnlitShader *ObjectUnlitShaderInstance;
|
||||
|
||||
class ObjectRefPass2Shader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
|
||||
class ObjectRefPass2Shader : public ShaderHelperSingleton<ObjectRefPass2Shader, core::matrix4, core::matrix4, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Albedo;
|
||||
@ -256,9 +250,7 @@ public:
|
||||
ObjectRefPass2Shader();
|
||||
};
|
||||
|
||||
extern ObjectRefPass2Shader *ObjectRefPass2ShaderInstance;
|
||||
|
||||
class GrassPass2Shader : public ShaderHelper<core::matrix4, core::vector3df, video::SColorf>
|
||||
class GrassPass2Shader : public ShaderHelperSingleton<GrassPass2Shader, core::matrix4, core::vector3df, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Albedo;
|
||||
@ -266,8 +258,6 @@ public:
|
||||
GrassPass2Shader();
|
||||
};
|
||||
|
||||
extern GrassPass2Shader *GrassPass2ShaderInstance;
|
||||
|
||||
class InstancedGrassPass2Shader : public ShaderHelper<core::vector3df, core::vector3df, video::SColorf>
|
||||
{
|
||||
public:
|
||||
@ -278,7 +268,7 @@ public:
|
||||
|
||||
extern InstancedGrassPass2Shader *InstancedGrassPass2ShaderInstance;
|
||||
|
||||
class SphereMapShader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
|
||||
class SphereMapShader : public ShaderHelperSingleton<SphereMapShader, core::matrix4, core::matrix4, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_tex;
|
||||
@ -286,9 +276,7 @@ public:
|
||||
SphereMapShader();
|
||||
};
|
||||
|
||||
extern SphereMapShader *SphereMapShaderInstance;
|
||||
|
||||
class SplattingShader : public ShaderHelper<core::matrix4, video::SColorf>
|
||||
class SplattingShader : public ShaderHelperSingleton<SplattingShader, core::matrix4, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_tex_layout, TU_tex_detail0, TU_tex_detail1, TU_tex_detail2, TU_tex_detail3;
|
||||
@ -296,8 +284,6 @@ public:
|
||||
SplattingShader();
|
||||
};
|
||||
|
||||
extern SplattingShader *SplattingShaderInstance;
|
||||
|
||||
class BubbleShader
|
||||
{
|
||||
public:
|
||||
@ -308,7 +294,7 @@ public:
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency);
|
||||
};
|
||||
|
||||
class TransparentShader : public ShaderHelper<core::matrix4, core::matrix4>
|
||||
class TransparentShader : public ShaderHelperSingleton<TransparentShader, core::matrix4, core::matrix4>
|
||||
{
|
||||
public:
|
||||
GLuint TU_tex;
|
||||
@ -316,9 +302,7 @@ public:
|
||||
TransparentShader();
|
||||
};
|
||||
|
||||
extern TransparentShader *TransparentShaderInstance;
|
||||
|
||||
class TransparentFogShader : public ShaderHelper<core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
|
||||
class TransparentFogShader : public ShaderHelperSingleton<TransparentFogShader, core::matrix4, core::matrix4, float, float, float, float, float, video::SColorf>
|
||||
{
|
||||
public:
|
||||
GLuint TU_tex;
|
||||
@ -326,8 +310,6 @@ public:
|
||||
TransparentFogShader();
|
||||
};
|
||||
|
||||
extern TransparentFogShader *TransparentFogShaderInstance;
|
||||
|
||||
class BillboardShader
|
||||
{
|
||||
public:
|
||||
|
@ -276,7 +276,7 @@ void STKMeshSceneNode::render()
|
||||
glDisable(GL_CULL_FACE);
|
||||
if (!spareWhiteTex)
|
||||
spareWhiteTex = getUnicolorTexture(video::SColor(255, 255, 255, 255));
|
||||
glUseProgram(MeshShader::ObjectPass2ShaderInstance->Program);
|
||||
glUseProgram(MeshShader::ObjectPass2Shader::getInstance<MeshShader::ObjectPass2Shader>()->Program);
|
||||
// Only untextured
|
||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
||||
{
|
||||
@ -286,8 +286,8 @@ void STKMeshSceneNode::render()
|
||||
GLenum itype = mesh.IndexType;
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
setTexture(MeshShader::ObjectPass2ShaderInstance->TU_Albedo, getTextureGLuint(spareWhiteTex), GL_NEAREST, GL_NEAREST, false);
|
||||
MeshShader::ObjectPass2ShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
|
||||
setTexture(MeshShader::ObjectPass2Shader::getInstance<MeshShader::ObjectPass2Shader>()->TU_Albedo, getTextureGLuint(spareWhiteTex), GL_NEAREST, GL_NEAREST, false);
|
||||
MeshShader::ObjectPass2Shader::getInstance<MeshShader::ObjectPass2Shader>()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, irr_driver->getSceneManager()->getAmbientLight());
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
@ -350,7 +350,7 @@ void STKMeshSceneNode::render()
|
||||
|
||||
if (World::getWorld() && World::getWorld()->isFogEnabled())
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentFogShaderInstance->Program);
|
||||
glUseProgram(MeshShader::TransparentFogShader::getInstance<MeshShader::TransparentFogShader>()->Program);
|
||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
||||
{
|
||||
GLMesh &mesh = GLmeshes[i];
|
||||
@ -374,8 +374,8 @@ void STKMeshSceneNode::render()
|
||||
tmpcol.getBlue() / 255.0f);
|
||||
|
||||
compressTexture(mesh.textures[0], true);
|
||||
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
MeshShader::TransparentFogShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col);
|
||||
setTexture(MeshShader::TransparentFogShader::getInstance<MeshShader::TransparentFogShader>()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
MeshShader::TransparentFogShader::getInstance<MeshShader::TransparentFogShader>()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col);
|
||||
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
@ -385,7 +385,7 @@ void STKMeshSceneNode::render()
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(MeshShader::TransparentShaderInstance->Program);
|
||||
glUseProgram(MeshShader::TransparentShader::getInstance<MeshShader::TransparentShader>()->Program);
|
||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
||||
{
|
||||
irr_driver->IncreaseObjectCount();
|
||||
@ -395,9 +395,9 @@ void STKMeshSceneNode::render()
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
compressTexture(mesh.textures[0], true);
|
||||
setTexture(MeshShader::TransparentShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
setTexture(MeshShader::TransparentShader::getInstance<MeshShader::TransparentShader>()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
|
||||
MeshShader::TransparentShaderInstance->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
|
||||
MeshShader::TransparentShader::getInstance<MeshShader::TransparentShader>()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user