13SCompositor::SCompositor(
SViewPort* scolViewPort,
const std::string& compositorName,
const std::string& schemeName) :
SData(compositorName)
15 CommonConstructor(scolViewPort, schemeName,
false,
false);
18SCompositor::SCompositor(
SViewPort* scolViewPort,
const std::string& compositorName,
const bool& isActivated) :
SData(compositorName)
20 CommonConstructor(scolViewPort,
"",
true, isActivated);
23SCompositor::SCompositor(
const std::string& compositorName,
const std::string& schemeName) :
SData(compositorName)
25 CommonConstructor(NULL, schemeName,
false,
false);
28void SCompositor::CommonConstructor(
SViewPort* scolViewPort,
const std::string& schemeName,
bool internalCompo,
bool activateCompo)
31 isInternal = internalCompo;
32 isEnable = activateCompo;
33 parent = scolViewPort;
36 if (scolViewPort != 0)
40 ogreCompositor = Ogre::CompositorManager::getSingleton().getByName(
name);
43 if (schemeName.empty() || schemeName ==
"Default" || schemeName ==
"DefaultScheme" || schemeName == Ogre::Root::getSingleton().getRenderSystem()->_getDefaultViewportMaterialScheme())
44 scheme = Ogre::MSN_SHADERGEN;
48 if ((scheme != Ogre::MSN_SHADERGEN) && (scheme !=
"SO3_LEGACY"))
53 Ogre::Compositor::TechniqueIterator iCompositorTechnique = ogreCompositor->getTechniqueIterator();
54 while (iCompositorTechnique.hasMoreElements())
57 Ogre::CompositionTechnique* ogreCompositionTechnique = iCompositorTechnique.getNext();
59 Ogre::CompositionTechnique::TargetPasses passList = ogreCompositionTechnique->getTargetPasses();
60 for (
unsigned int p = 0; p < passList.size(); p++)
63 Ogre::CompositionTargetPass* ogreCompositionTargetPass = passList[p];
65 ogreCompositionTargetPass->setMaterialScheme(scheme);
70 Ogre::MaterialPtr colorMat = Ogre::MaterialManager::getSingleton().getByName(
"SO3/Internal/DefaultColor");
73 mBlackMat = colorMat->clone(
"SO3/Internal/mSchemeBlack/" +
name +
"/" + scheme, Ogre::String(
"SO3/Internal"));
74 mBlackMat->getTechnique(0)->getPass(0)->setAmbient(0,0,0);
75 mBlackMat->getTechnique(0)->setFog(
true, Ogre::FOG_NONE, Ogre::ColourValue::Black);
76 mBlackMat->getTechnique(0)->setSchemeName(scheme);
78 mBlackMatTrans = colorMat->clone(
"SO3/Internal/mSchemeBlackTrans/" +
name +
"/" + scheme, Ogre::String(
"SO3/Internal"));
79 mBlackMatTrans->getTechnique(0)->getPass(0)->setAmbient(0,0,0);
80 mBlackMatTrans->getTechnique(0)->getPass(0)->setDepthWriteEnabled(
false);
81 mBlackMatTrans->getTechnique(0)->setFog(
true, Ogre::FOG_NONE, Ogre::ColourValue::Black);
82 mBlackMatTrans->getTechnique(0)->setSchemeName(scheme);
87 if(!isInternal && ogreCompositor)
93 Ogre::Compositor::TechniqueIterator iCompositorTechnique = ogreCompositor->getTechniqueIterator();
94 while(iCompositorTechnique.hasMoreElements())
97 Ogre::CompositionTechnique* ogreCompositionTechnique = iCompositorTechnique.getNext();
98 SCompositorTechnique* newCompositorTechnique =
new SCompositorTechnique(
this, ogreCompositionTechnique, compositorTechniquesByIndex.size());
101 compositorTechniquesIndexByName.insert(CompositorTechniquesIndexByName::value_type(newCompositorTechnique->GetName(), compositorTechniquesByIndex.size()));
102 compositorTechniquesByIndex.push_back(newCompositorTechnique);
107SCompositor::SCompositor() : SData(
"")
124 if (caps && caps->hasCapability(Ogre::RSC_FIXED_FUNCTION) ==
false)
125 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(mBlackMat->getName(), mBlackMat->getGroup());
127 Ogre::MaterialManager::getSingleton().remove(mBlackMat->getHandle());
132 if (caps && caps->hasCapability(Ogre::RSC_FIXED_FUNCTION) ==
false)
133 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(mBlackMatTrans->getName(), mBlackMatTrans->getGroup());
135 Ogre::MaterialManager::getSingleton().remove(mBlackMatTrans->getHandle());
136 mBlackMatTrans.reset();
140 CompositorTechniquesByIndex::iterator iCompositorTechnique = compositorTechniquesByIndex.begin();
141 while(iCompositorTechnique != compositorTechniquesByIndex.end())
143 delete(*iCompositorTechnique);
144 iCompositorTechnique++;
146 compositorTechniquesByIndex.clear();
147 compositorTechniquesIndexByName.clear();
152 ogreCompositor->unload();
155 ogreCompositor.reset();
162 bool state = isEnable;
178void SCompositor::_AttachToParent()
183 if(!ogreCompositor->isLoaded())
184 ogreCompositor->load();
187 bool hasStereo =
false;
204 Ogre::CompositorManager::getSingleton().addCompositor(mViewport,
name, pos);
206 catch (Ogre::Exception &e)
208 Ogre::LogManager::getSingletonPtr()->logMessage(e.getFullDescription(), Ogre::LML_WARNING,
false);
215 if ((parent != 0) && hasStereo)
219void SCompositor::_DetachFromParent()
227 bool hasStereo =
false;
237#if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
239 Ogre::CompositorManager::getSingleton().removeCompositor(mViewport,
name);
242 Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(mViewport);
245 Ogre::CompositorInstance* compinst = chain->getCompositor(
name);
248 chain->_removeInstance(compinst);
253 if(chain->getCompositorInstances().empty())
254 Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
259 if ((parent != 0) && hasStereo)
275 if (enable != isEnable)
280 Ogre::MaterialManager::getSingleton().addListener(
this, scheme);
284 Ogre::MaterialManager::getSingleton().removeListener(
this, scheme);
291 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport,
name, enable);
293 catch (Ogre::Exception &e)
295 Ogre::LogManager::getSingletonPtr()->logMessage(e.getFullDescription(), Ogre::LML_WARNING,
false);
304 return ogreCompositor->getNumTechniques();
309 if((technique >= 0) && (technique < compositorTechniquesByIndex.size()))
310 return compositorTechniquesByIndex.at(technique);
317 CompositorTechniquesIndexByName::iterator iSearchedCompositorTechniqueIndex = compositorTechniquesIndexByName.find(techname);
318 if(iSearchedCompositorTechniqueIndex!= compositorTechniquesIndexByName.end())
319 return iSearchedCompositorTechniqueIndex->second;
324Ogre::Technique*
SCompositor::handleSchemeNotFound(
unsigned short schemeIndex,
const Ogre::String& schemeName, Ogre::Material* originalMaterial,
unsigned short lodIndex,
const Ogre::Renderable* rend)
326 if (!mBlackMatTrans || !mBlackMat)
329 if ((originalMaterial->getNumSupportedTechniques() > 0) && (originalMaterial->getSupportedTechnique(0)->getNumPasses() > 0) && (!originalMaterial->getSupportedTechnique(0)->getPass(0)->getDepthWriteEnabled()))
330 return mBlackMatTrans->getTechnique(0);
332 return mBlackMat->getTechnique(0);
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
void SetEnable(const bool &enable)
void SetViewport(Ogre::Viewport *vp)
SViewPort * GetParentViewPort()
int GetCompositorTechniqueIndexByName(const std::string &techname)
int GetNumCompositorTechniques()
SCompositorTechnique * GetCompositorTechnique(const unsigned int &technique)
Ogre::RenderSystem * GetOgreRenderSystem()
static SRoot * getSingletonPtr()
void RegisterStereoViewport()
void UnregisterStereoViewport()
bool IsStereoViewportRegistered()
Ogre::Viewport * GetOgreViewPortPointer()
bool UpdateStereoCompositorState(const Ogre::String compname, bool state)