void MainCamera::enableCompositor(const std::string& compositorName, bool enable) { if (enable) { S_LOG_INFO("Enabling compositor '" << compositorName<< "'."); } else { S_LOG_INFO("Disabling compositor '" << compositorName<< "'."); } if (std::find(mLoadedCompositors.begin(), mLoadedCompositors.end(), compositorName) == mLoadedCompositors.end()) { Ogre::CompositorInstance* compositor = Ogre::CompositorManager::getSingleton().addCompositor(mWindow.getViewport(0), compositorName); if (compositor) { bool hasErrors = false; //There's a bug in Ogre which will causes a segfault during rendering if a compositor has an invalid shader. //We therefore need to check for this here, and disable the shader if so is the case. compositor->getCompositor()->load(); hasErrors = !validateCompositionTargetPass(*compositor->getTechnique()->getOutputTargetPass()); if (!hasErrors) { Ogre::CompositionTechnique::TargetPassIterator targetPassIter = compositor->getTechnique()->getTargetPassIterator(); while (targetPassIter.hasMoreElements() && !hasErrors) { hasErrors = !validateCompositionTargetPass(*targetPassIter.getNext()); } } if (hasErrors) { S_LOG_FAILURE("Compositor "<< compositorName <<" has errors and will be disabled."); Ogre::CompositorManager::getSingleton().removeCompositor(mWindow.getViewport(0), compositorName); } else { compositor->setEnabled(true); mLoadedCompositors.push_back(compositorName); } } } else { Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow.getViewport(0), compositorName, enable); } }
void DeferredShadingSystem::logCurrentMode(void) { if (mActive==false) { Ogre::LogManager::getSingleton().logMessage("No Compositor Enabled!"); return; } Ogre::CompositorInstance* ci = mInstance[mCurrentMode]; assert(ci->getEnabled()==true); Ogre::LogManager::getSingleton().logMessage("Current Mode: "); Ogre::LogManager::getSingleton().logMessage(ci->getCompositor()->getName()); }
bool gkCompositorManager::setCompositorChain(gkCompositorOp op, const gkString& compositorName, gkViewport *viewport) { GK_ASSERT(viewport && viewport->getViewport()); bool found = false; Ogre::Viewport *vp = viewport->getViewport(); int width = vp->getActualWidth(), height = vp->getActualHeight(); Ogre::CompositorChain *chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp); assert(chain); for (size_t i = 0; i < chain->getNumCompositors(); i++) { Ogre::CompositorInstance *ci = chain->getCompositor(i); assert(ci); bool match = (compositorName == ci->getCompositor()->getName()); if (op == GK_COMPOSITOR_OP_REPLACE) ci->setEnabled(match); else if (op == GK_COMPOSITOR_OP_RESET) ci->setEnabled(false); else if (match) ci->setEnabled(op == GK_COMPOSITOR_OP_ADD); if (!found && match) found = true; } if (op == GK_COMPOSITOR_OP_DEL || op == GK_COMPOSITOR_OP_RESET) return true; if (!compositorName.empty() && !found) //create new compositor { if (compositorName == GK_COMPOSITOR_HEAT_VISION && !m_heatVisionInited) m_heatVisionInited = gkOgreCompositorHelper::createHeatVisionCompositor(); else if (compositorName == GK_COMPOSITOR_MOTION_BLUR && !m_motionBlurInited) m_motionBlurInited = gkOgreCompositorHelper::createMotionBlurCompositor(); Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton(); Ogre::CompositorInstance* instance = compMgr.addCompositor(vp, compositorName, 0); if (instance) { if (compositorName == GK_COMPOSITOR_HALFTONE && !m_halftonInited) m_halftonInited = gkOgreCompositorHelper::createHalftoneTexture(); else if (compositorName == GK_COMPOSITOR_DITHER && !m_ditherInited) m_ditherInited = gkOgreCompositorHelper::createDitherTexture(width, height); instance->setEnabled(true); gkPrintf("[COMP] add new compositor: %s", compositorName.c_str()); return true; } else { gkPrintf("[COMP] %s - FAILED. check compositor name.", compositorName.c_str()); return false; } } return false; }