Skip to content

Commit

Permalink
GRAPHICS: Add MaterialManager::resetTransparent()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 20, 2014
1 parent 1aeabd0 commit 12c0d21
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/graphics/materialman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ void MaterialManager::create(const MaterialDeclaration &decl, Ogre::MaterialPtr
}

void MaterialManager::setTransparent(Ogre::MaterialPtr material, bool transparent) {
bool depthWrite = material->getTechnique(0)->getPass(0)->getDepthWriteEnabled();
Ogre::SceneBlendFactor sceneBlendSrc = material->getTechnique(0)->getPass(0)->getSourceBlendFactor();
Ogre::SceneBlendFactor sceneBlendDst = material->getTechnique(0)->getPass(0)->getDestBlendFactor();

Ogre::UserObjectBindings &user = material->getTechnique(0)->getPass(0)->getUserObjectBindings();

user.setUserAny("depthwrite", Ogre::Any(depthWrite));
user.setUserAny("sceneblendsource", Ogre::Any(sceneBlendSrc));
user.setUserAny("sceneblenddest", Ogre::Any(sceneBlendDst));

if (transparent) {
material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
Expand All @@ -233,6 +243,20 @@ void MaterialManager::setTransparent(Ogre::MaterialPtr material, bool transparen
}
}

void MaterialManager::resetTransparent(Ogre::MaterialPtr material) {
Ogre::UserObjectBindings &user = material->getTechnique(0)->getPass(0)->getUserObjectBindings();

const Ogre::Any &depthWrite = user.getUserAny("depthwrite");
const Ogre::Any &sceneBlendSrc = user.getUserAny("sceneblendsrc");
const Ogre::Any &sceneBlendDst = user.getUserAny("sceneblenddst");

if (!depthWrite.isEmpty())
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(Ogre::any_cast<bool>(depthWrite));
if (!sceneBlendSrc.isEmpty() && !sceneBlendDst.isEmpty())
material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::any_cast<Ogre::SceneBlendFactor>(sceneBlendSrc),
Ogre::any_cast<Ogre::SceneBlendFactor>(sceneBlendDst));
}

void MaterialManager::setColorModifier(const Ogre::MaterialPtr &material, float r, float g, float b, float a) {
Ogre::TextureUnitState *texState = getColorModifier(material);
if (!texState)
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/materialman.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class MaterialManager : public Common::Singleton<MaterialManager> {

/** Force the material to blend like a transparent or solid material. */
void setTransparent(Ogre::MaterialPtr material, bool transparent);
/** Reset the transparency settings to what it was before the call to setTransparent(). */
void resetTransparent(Ogre::MaterialPtr material);

private:
void create(const MaterialDeclaration &decl, Ogre::MaterialPtr material);
Expand Down

0 comments on commit 12c0d21

Please sign in to comment.