Factorise transparent state changes.

This commit is contained in:
Vincent Lejeune 2014-01-28 22:39:17 +01:00
parent 57808f0815
commit c6e466fdcc
4 changed files with 30 additions and 39 deletions

View File

@ -288,6 +288,13 @@ void IrrDriver::renderGLSL(float dt)
PROFILER_PUSH_CPU_MARKER("- Transparent Pass", 0xFF, 0x00, 0x00);
irr_driver->setPhase(TRANSPARENT_PASS);
m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT;
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
m_scene_manager->drawAll(m_renderpass);
PROFILER_POP_CPU_MARKER();

View File

@ -27,20 +27,11 @@ void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
void STKAnimatedMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
assert(irr_driver->getPhase() == TRANSPARENT_PASS);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
computeMVP(ModelViewProjectionMatrix);
drawTransparentObject(mesh, ModelViewProjectionMatrix);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
return;
}
@ -173,16 +164,18 @@ void STKAnimatedMesh::render()
if (isTransparentPass)
drawTransparent(GLmeshes[i], material.MaterialType);
else
{
drawSolid(GLmeshes[i], material.MaterialType);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
video::SMaterial material;
material.MaterialType = irr_driver->getShader(ES_RAIN);
material.BlendOperation = video::EBO_NONE;
material.ZWriteEnable = true;
material.Lighting = false;
irr_driver->getVideoDriver()->setMaterial(material);
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
video::SMaterial material;
material.MaterialType = irr_driver->getShader(ES_RAIN);
material.BlendOperation = video::EBO_NONE;
material.ZWriteEnable = true;
material.Lighting = false;
irr_driver->getVideoDriver()->setMaterial(material);
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
}
}
else
{

View File

@ -40,10 +40,6 @@ STKBillboard::STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneMan
void STKBillboard::render()
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glDepthMask(GL_FALSE);
core::vector3df pos = getAbsolutePosition();
glBindVertexArray(billboardvao);
GLuint texid = static_cast<irr::video::COpenGLTexture*>(Material.getTexture(0))->getOpenGLTextureName();

View File

@ -686,16 +686,9 @@ void STKMesh::drawDisplace(const GLMesh &mesh)
void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
assert(irr_driver->getPhase() == TRANSPARENT_PASS);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
computeMVP(ModelViewProjectionMatrix);
if (type == irr_driver->getShader(ES_BUBBLES))
drawBubble(mesh, ModelViewProjectionMatrix);
else
@ -957,16 +950,18 @@ void STKMesh::render()
if (transparent)
drawTransparent(GLmeshes[i], material.MaterialType);
else
{
drawSolid(GLmeshes[i], material.MaterialType);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
video::SMaterial material;
material.MaterialType = irr_driver->getShader(ES_RAIN);
material.BlendOperation = video::EBO_NONE;
material.ZWriteEnable = true;
material.Lighting = false;
irr_driver->getVideoDriver()->setMaterial(material);
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
video::SMaterial material;
material.MaterialType = irr_driver->getShader(ES_RAIN);
material.BlendOperation = video::EBO_NONE;
material.ZWriteEnable = true;
material.Lighting = false;
irr_driver->getVideoDriver()->setMaterial(material);
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
}
}
}
}