STKMesh, GPUParticles: Some factorization.
This commit is contained in:
parent
1f4e697e48
commit
9da56ddefc
@ -296,6 +296,16 @@ void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUni
|
||||
glUniform1i(location, textureUnit);
|
||||
}
|
||||
|
||||
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + TextureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MagFilter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
static GLuint TexturedQuadShader;
|
||||
static GLuint TexturedQuadAttribPosition;
|
||||
static GLuint TexturedQuadAttribTexCoord;
|
||||
|
@ -22,7 +22,7 @@ void initGL();
|
||||
GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_path);
|
||||
GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount);
|
||||
void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit);
|
||||
|
||||
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter);
|
||||
|
||||
// already includes glext.h, which defines useful GL constants.
|
||||
// COpenGLDriver has already loaded the extension GL functions we use (e.g glBeginQuery)
|
||||
|
@ -522,13 +522,10 @@ void ParticleSystemProxy::drawFlip()
|
||||
(float)UserConfigParams::m_height
|
||||
};
|
||||
|
||||
bindUniformToTextureUnit(ParticleShader::FlipParticleRender::uniform_tex, texture, 0);
|
||||
bindUniformToTextureUnit(ParticleShader::FlipParticleRender::uniform_normal_and_depths, normal_and_depth, 1);
|
||||
setTexture(0, texture, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(1, normal_and_depth, GL_NEAREST, GL_NEAREST);
|
||||
|
||||
glUniformMatrix4fv(ParticleShader::FlipParticleRender::uniform_invproj, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
|
||||
glUniform2f(ParticleShader::FlipParticleRender::uniform_screen, screen[0], screen[1]);
|
||||
glUniformMatrix4fv(ParticleShader::FlipParticleRender::uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
|
||||
glUniformMatrix4fv(ParticleShader::FlipParticleRender::uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
|
||||
ParticleShader::FlipParticleRender::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), irr_driver->getInvProjMatrix(), screen[0], screen[1], 0, 1);
|
||||
|
||||
glBindVertexArray(current_rendering_flip_vao);
|
||||
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
|
||||
@ -557,13 +554,10 @@ void ParticleSystemProxy::drawNotFlip()
|
||||
(float)UserConfigParams::m_height
|
||||
};
|
||||
|
||||
bindUniformToTextureUnit(ParticleShader::SimpleParticleRender::uniform_tex, texture, 0);
|
||||
bindUniformToTextureUnit(ParticleShader::SimpleParticleRender::uniform_normal_and_depths, normal_and_depth, 1);
|
||||
setTexture(0, texture, GL_LINEAR, GL_LINEAR);
|
||||
setTexture(1, normal_and_depth, GL_NEAREST, GL_NEAREST);
|
||||
|
||||
glUniformMatrix4fv(ParticleShader::SimpleParticleRender::uniform_invproj, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
|
||||
glUniform2f(ParticleShader::SimpleParticleRender::uniform_screen, screen[0], screen[1]);
|
||||
glUniformMatrix4fv(ParticleShader::SimpleParticleRender::uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
|
||||
glUniformMatrix4fv(ParticleShader::SimpleParticleRender::uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
|
||||
ParticleShader::SimpleParticleRender::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), irr_driver->getInvProjMatrix(), screen[0], screen[1], 0, 1);
|
||||
|
||||
glBindVertexArray(current_rendering_vao);
|
||||
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
|
||||
|
@ -803,6 +803,16 @@ namespace ParticleShader
|
||||
uniform_normal_and_depths = glGetUniformLocation(Program, "normals_and_depth");
|
||||
}
|
||||
|
||||
void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
|
||||
glUniform2f(uniform_screen, width, height);
|
||||
glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
|
||||
glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
|
||||
glUniform1i(uniform_tex, TU_tex);
|
||||
glUniform1i(uniform_normal_and_depths, TU_normal_and_depth);
|
||||
}
|
||||
|
||||
GLuint FlipParticleRender::Program;
|
||||
GLuint FlipParticleRender::attrib_pos;
|
||||
GLuint FlipParticleRender::attrib_lf;
|
||||
@ -836,6 +846,16 @@ namespace ParticleShader
|
||||
uniform_screen = glGetUniformLocation(Program, "screen");
|
||||
uniform_normal_and_depths = glGetUniformLocation(Program, "normals_and_depth");
|
||||
}
|
||||
|
||||
void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
|
||||
glUniform2f(uniform_screen, width, height);
|
||||
glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
|
||||
glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
|
||||
glUniform1i(uniform_tex, TU_tex);
|
||||
glUniform1i(uniform_normal_and_depths, TU_normal_and_depth);
|
||||
}
|
||||
}
|
||||
|
||||
static GLuint createVAO(GLuint Program)
|
||||
|
@ -206,6 +206,7 @@ public:
|
||||
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_normal_and_depths, uniform_screen, uniform_invproj;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
|
||||
};
|
||||
|
||||
class FlipParticleRender
|
||||
@ -216,6 +217,7 @@ public:
|
||||
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_normal_and_depths, uniform_screen, uniform_invproj;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -204,17 +204,6 @@ void STKMesh::drawObjectPass1(const GLMesh &mesh)
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + TextureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MagFilter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
void STKMesh::drawObjectRefPass1(const GLMesh &mesh)
|
||||
{
|
||||
GLenum ptype = mesh.PrimitiveType;
|
||||
|
Loading…
Reference in New Issue
Block a user