//------------------------------------------------------------------------------------- void OgreManager::initialize(void) { // Create dummy CompositorPassProvider (see http://www.ogre3d.org/forums/viewtopic.php?f=11&t=84816&p=525752&hilit=CompositorPassProvider#p525752) // If one of the resource locations contains a compositor with a custom pass, the editor doesn't work anymore. This is to prevent it Ogre::MyCompositorPassProvider* mCompositorPassProvider = OGRE_NEW Ogre::MyCompositorPassProvider; Ogre::CompositorManager2* compositorManager = mRoot->getCompositorManager2(); compositorManager->setCompositorPassProvider(mCompositorPassProvider); // After resources have been setup and renderwindows created (in ogre widget), the Hlms managers are registered registerHlms(); // Initialise, parse scripts etc try { Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(false); } catch (Ogre::Exception e){} mPause = false; try { mRoot->renderOneFrame(); // Render first } catch (Ogre::Exception e) {} }
/**************************************************************************** ** ** Copyright (C) 2016 - 2017 ** ** This file is generated by the Magus toolkit ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE go (ODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ #include "ogre3_renderman.h" #include "OgreConfigFile.h" #include "OgreArchiveManager.h" #include "OgreHlms.h" #include "OgreHlmsUnlit.h" #include "OgreHlmsPbs.h" #include "OgreHlmsManager.h" #include "OgreHlmsCommon.h" #include "OgreLogManager.h" #include "OgreFrameStats.h" namespace Magus { //****************************************************************************/ OgreManager::OgreManager(void) { mGlContext = 0; mCompositorPassProvider = 0; mPause = true; #if _DEBUG || DEBUG mResourcesCfg = "resources_d.cfg"; mPluginsCfg = "plugins_d.cfg"; #else mResourcesCfg = "resources.cfg"; mPluginsCfg = "plugins.cfg"; #endif // Create Ogre tt and initialize mRoot = new Ogre::Root(mPluginsCfg); // Setup renderer mCurrentRenderSystem = 0; const Ogre::RenderSystemList& rsList = mRoot->getAvailableRenderers(); Ogre::RenderSystem* renderSystem = rsList[0]; std::vector<Ogre::String> renderOrder; #if defined(Q_OS_WIN) renderOrder.push_back("Direct3D11"); #endif renderOrder.push_back("OpenGL 3+"); for (std::vector<Ogre::String>::iterator iter = renderOrder.begin(); iter != renderOrder.end(); iter++) { for (Ogre::RenderSystemList::const_iterator it = rsList.begin(); it != rsList.end(); it++) { if ((*it)->getName().find(*iter) != Ogre::String::npos) { renderSystem = *it; break; } } if (renderSystem != 0) break; } if (renderSystem == 0) { if (!mRoot->restoreConfig()) { if (!mRoot->showConfigDialog()) OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Abort render system configuration", "OgreManager::OgreManager"); } } renderSystem->setConfigOption("Full Screen", "No"); renderSystem->setConfigOption("VSync", "Yes"); mRoot->setRenderSystem(renderSystem); mCurrentRenderSystem = renderSystem; // Uncomment next line to show dialog //if(mRoot->restoreConfig() || mRoot->showConfigDialog()) //{ mRoot->initialise(false); //} // Initialize resources setupResources(); // Start timer mTimer = new Ogre::Timer(); mTimer->reset(); } //****************************************************************************/ OgreManager::~OgreManager(void) { // Added removeAllWorkspaces after Ogre 2.1 upgrade (commit 2783a361c0b8) // In debug mode, the application crashed in deleting mRoot Ogre::CompositorManager2* compositorManager = mRoot->getCompositorManager2(); compositorManager->removeAllWorkspaces(); // Delete the dummy CompositorPassProvider compositorManager->setCompositorPassProvider(0); OGRE_DELETE mCompositorPassProvider; // Destroy render textures // This is a piece of custom code specific for the HLMS Editor (assume that the OgreWidget is still available) QMap<int, QOgreWidget*>::iterator i; QOgreWidget* item = 0; for (i = mQOgreWidgetMap.begin(); i != mQOgreWidgetMap.end(); ++i) { item = i.value(); item->cleanup(); } // Delete Ogre root delete mRoot; }