void AbstractGameCore::handleDebugInput(OIS::KeyEvent evt) { if(LuaConsole::getSingleton().isVisible()) LuaConsole::getSingleton().injectKeyPress(evt); /*OIS::Keyboard* pKeyboard=InputSystem::GetSingleton()->getKeyboardDevice(); //F1 to turn off any post-process effects if(pKeyboard->isKeyDown(OIS::KC_F1)) { m_bCompositorsEnabled=!m_bCompositorsEnabled; Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(m_pRenderWindow->getViewport(0)); int n = chain->getNumCompositors(); //loop through and disable all for(int i=0;i<n;i++) { if(m_bCompositorsEnabled) chain->setCompositorEnabled(i,false); else chain->setCompositorEnabled(i,true); } }*/ switch(evt.key) { //press "`" to turn on console case OIS::KC_GRAVE: //this is the "`" or "~" key case OIS::KC_KANJI: //in some machines (like mine >_<) it thinks its KANJI LuaConsole::getSingleton().setVisible( ! LuaConsole::getSingleton().isVisible() ); pause(); SoundSystem::GetSingleton()->togglePauseAll(); break; //F1 to toggle post processing case OIS::KC_F1: { m_bCompositorsEnabled=!m_bCompositorsEnabled; Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(m_pRenderWindow->getViewport(0)); int n = chain->getNumCompositors(); //loop through and disable all for(int i=0;i<n;i++) { if(m_bCompositorsEnabled) chain->setCompositorEnabled(i,false); else chain->setCompositorEnabled(i,true); } } break; //F2 to toggle debug shadows case OIS::KC_F2: m_pSceneMgr->setShowDebugShadows(m_bDebugShadowsOn); m_bDebugShadowsOn=!m_bDebugShadowsOn; break; } }
void LoadingScreen::draw() { const float loadingScreenFps = 20.f; if (mTimer.getMilliseconds () > mLastRenderTime + (1.f/loadingScreenFps) * 1000.f) { mLastRenderTime = mTimer.getMilliseconds (); if (mFirstLoad && mTimer.getMilliseconds () > mLastWallpaperChangeTime + 5000*1) { mLastWallpaperChangeTime = mTimer.getMilliseconds (); changeWallpaper(); } // Turn off rendering except the GUI mSceneMgr->clearSpecialCaseRenderQueues(); // SCRQM_INCLUDE with RENDER_QUEUE_OVERLAY does not work. for (int i = 0; i < Ogre::RENDER_QUEUE_MAX; ++i) { if (i > 0 && i < 96) mSceneMgr->addSpecialCaseRenderQueue(i); } mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); MWBase::Environment::get().getInputManager()->update(0, true); Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(mWindow->getViewport(0)); bool hasCompositor = chain->getCompositor ("gbufferFinalizer"); if (!hasCompositor) { mWindow->getViewport(0)->setClearEveryFrame(false); } else { if (!mFirstLoad) { mBackgroundMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(chain->getCompositor ("gbufferFinalizer")->getTextureInstance ("no_mrt_output", 0)->getName()); mRectangle->setVisible(true); } for (unsigned int i = 0; i<chain->getNumCompositors(); ++i) { Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), chain->getCompositor(i)->getCompositor()->getName(), false); } } // First, swap buffers from last draw, then, queue an update of the // window contents, but don't swap buffers (which would have // caused a sync / flush and would be expensive). // We're doing this so we can do some actual loading while the GPU is busy with the render. // This means the render is lagging a frame behind, but this is hardly noticable. mWindow->swapBuffers(); mWindow->update(false); if (!hasCompositor) mWindow->getViewport(0)->setClearEveryFrame(true); else { for (unsigned int i = 0; i<chain->getNumCompositors(); ++i) { Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), chain->getCompositor(i)->getCompositor()->getName(), true); } } mRectangle->setVisible(false); // resume 3d rendering mSceneMgr->clearSpecialCaseRenderQueues(); mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); } }
void LoadingScreen::setLoadingProgress (const std::string& stage, int depth, int current, int total) { if (!mLoadingOn) loadingOn(); const int numRefLists = 20; if (depth == 0) { mCurrentCellLoading = current; mTotalCellsLoading = total; mCurrentRefLoading = 0; mCurrentRefList = 0; } else if (depth == 1) { mCurrentRefLoading = current; mTotalRefsLoading = total; } assert (mTotalCellsLoading != 0); float refProgress; if (mTotalRefsLoading <= 1) refProgress = 1; else refProgress = float(mCurrentRefLoading) / float(mTotalRefsLoading-1); refProgress += mCurrentRefList; refProgress /= numRefLists; assert(refProgress <= 1 && refProgress >= 0); if (depth == 1 && mCurrentRefLoading == mTotalRefsLoading-1) ++mCurrentRefList; float progress = (float(mCurrentCellLoading)+refProgress) / float(mTotalCellsLoading); assert(progress <= 1 && progress >= 0); mLoadingText->setCaption(stage + "... "); mProgressBar->setProgressPosition (static_cast<size_t>(progress * 1000)); static float loadingScreenFps = 30.f; if (mTimer.getMilliseconds () > mLastRenderTime + (1.f/loadingScreenFps) * 1000.f) { mLastRenderTime = mTimer.getMilliseconds (); if (mFirstLoad && mTimer.getMilliseconds () > mLastWallpaperChangeTime + 3000*1) { mLastWallpaperChangeTime = mTimer.getMilliseconds (); changeWallpaper(); } // Turn off rendering except the GUI mSceneMgr->clearSpecialCaseRenderQueues(); // SCRQM_INCLUDE with RENDER_QUEUE_OVERLAY does not work. for (int i = 0; i < Ogre::RENDER_QUEUE_MAX; ++i) { if (i > 0 && i < 96) mSceneMgr->addSpecialCaseRenderQueue(i); } mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); // always update input before rendering something, otherwise mygui goes crazy when something was entered in the frame before // (e.g. when using "coc" console command, it would enter an infinite loop and crash due to overflow) //MWBase::Environment::get().getInputManager()->update(0, true); Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(mWindow->getViewport(0)); bool hasCompositor = chain->getCompositor ("gbufferFinalizer"); if (!hasCompositor) { mWindow->getViewport(0)->setClearEveryFrame(false); } else { if (!mFirstLoad) { mBackgroundMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(chain->getCompositor ("gbufferFinalizer")->getTextureInstance ("no_mrt_output", 0)->getName()); mRectangle->setVisible(true); } for (unsigned int i = 0; i<chain->getNumCompositors(); ++i) { Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), chain->getCompositor(i)->getCompositor()->getName(), false); } } mWindow->update(); if (!hasCompositor) mWindow->getViewport(0)->setClearEveryFrame(true); else { for (unsigned int i = 0; i<chain->getNumCompositors(); ++i) { Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), chain->getCompositor(i)->getCompositor()->getName(), true); } } mRectangle->setVisible(false); // resume 3d rendering mSceneMgr->clearSpecialCaseRenderQueues(); mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); } }
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; }