Port remaining pass 1 Instanced shaders to singleton

This commit is contained in:
vlj 2014-07-14 23:25:52 +02:00
parent 732aefc2dc
commit 098eb7f595
3 changed files with 27 additions and 43 deletions

View File

@ -329,8 +329,8 @@ void Shaders::loadShaders()
MeshShader::ObjectPass1ShaderInstance = new MeshShader::ObjectPass1Shader();
MeshShader::ObjectRefPass1ShaderInstance = new MeshShader::ObjectRefPass1Shader();
MeshShader::InstancedObjectPass1ShaderInstance = new MeshShader::InstancedObjectPass1Shader();
MeshShader::InstancedObjectRefPass1Shader::init();
MeshShader::InstancedGrassPass1Shader::init();
MeshShader::InstancedObjectRefPass1ShaderInstance = new MeshShader::InstancedObjectRefPass1Shader();
MeshShader::InstancedGrassPass1ShaderInstance = new MeshShader::InstancedGrassPass1Shader();
MeshShader::ObjectPass2ShaderInstance = new MeshShader::ObjectPass2Shader();
MeshShader::InstancedObjectPass2Shader::init();
MeshShader::InstancedObjectRefPass2Shader::init();
@ -571,17 +571,15 @@ namespace MeshShader
InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
GLuint InstancedObjectRefPass1Shader::Program;
GLuint InstancedObjectRefPass1Shader::uniform_tex;
void InstancedObjectRefPass1Shader::init()
InstancedObjectRefPass1Shader::InstancedObjectRefPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
TU_tex = 0;
AssignTextureUnit(Program, { { TU_tex, "tex" } });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@ -589,26 +587,18 @@ namespace MeshShader
}
}
void InstancedObjectRefPass1Shader::setUniforms(unsigned TU_tex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform1i(uniform_tex, TU_tex);
}
InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
GLuint InstancedGrassPass1Shader::Program;
GLuint InstancedGrassPass1Shader::uniform_windDir;
GLuint InstancedGrassPass1Shader::uniform_tex;
void InstancedGrassPass1Shader::init()
InstancedGrassPass1Shader::InstancedGrassPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
uniform_windDir = glGetUniformLocation(Program, "windDir");
uniform_tex = glGetUniformLocation(Program, "tex");
AssignUniforms(Program, uniforms, { "windDir" });
TU_tex = 0;
AssignTextureUnit(Program, { { TU_tex, "tex" } });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@ -616,13 +606,7 @@ namespace MeshShader
}
}
void InstancedGrassPass1Shader::setUniforms(const core::vector3df &windDir, unsigned TU_tex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_windDir, windDir.X, windDir.Y, windDir.Z);
glUniform1i(uniform_tex, TU_tex);
}
InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
// Solid Lit pass shaders
ObjectPass2Shader::ObjectPass2Shader()

View File

@ -169,26 +169,26 @@ public:
extern InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
class InstancedObjectRefPass1Shader
class InstancedObjectRefPass1Shader : public ShaderHelper<>
{
public:
static GLuint Program;
static GLuint uniform_tex;
GLuint TU_tex;
static void init();
static void setUniforms(unsigned TU_tex);
InstancedObjectRefPass1Shader();
};
class InstancedGrassPass1Shader
extern InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
class InstancedGrassPass1Shader : public ShaderHelper<core::vector3df>
{
public:
static GLuint Program;
static GLuint uniform_windDir, uniform_tex;
GLuint TU_tex;
static void init();
static void setUniforms(const core::vector3df &windDir, unsigned TU_tex);
InstancedGrassPass1Shader();
};
extern InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
class ObjectPass2Shader : public ShaderHelper<core::matrix4, core::matrix4, video::SColorf>
{
public:

View File

@ -172,8 +172,8 @@ static void drawFSPMAlphaRefTexture(GLMesh &mesh, size_t instance_count)
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1Shader::setUniforms(0);
setTexture(MeshShader::InstancedObjectRefPass1ShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedObjectRefPass1ShaderInstance->setUniforms();
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -202,8 +202,8 @@ static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t i
size_t count = mesh.IndexCount;
compressTexture(mesh.textures[0], true);
setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1Shader::setUniforms(windDir, 0);
setTexture(MeshShader::InstancedGrassPass1ShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
MeshShader::InstancedGrassPass1ShaderInstance->setUniforms(windDir);
glBindVertexArray(mesh.vao);
glDrawElementsInstanced(ptype, count, itype, 0, instance_count);
@ -309,13 +309,13 @@ void STKInstancedSceneNode::render()
drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT_STANDARD][i], instance_pos.size() / 9);
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
glUseProgram(MeshShader::InstancedObjectRefPass1Shader::Program);
glUseProgram(MeshShader::InstancedObjectRefPass1ShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++)
drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9);
windDir = getWind();
if (!GeometricMesh[FPSM_GRASS].empty())
glUseProgram(MeshShader::InstancedGrassPass1Shader::Program);
glUseProgram(MeshShader::InstancedGrassPass1ShaderInstance->Program);
for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++)
drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9);
return;