bool OgreRenderQueueClearer::frameStarted (const Ogre::FrameEvent &evt)
{
    // Workaround taken from http://www.ogre3d.org/mantis/view.php?id=130
    // in case a plugin creates its own scene manager.
    //
    // Has the following modifications:
    // 1. Need to pass 'true' to RenderQueue::clear( bool destroyPassMaps ).
    // 2. Don't need to call Ogre::Pass::processPendingPassUpdates(),
    //    since this is done within RenderQueue::clear().

    // This workaround is only necessary if there is more than one
    // scene manager present, so check for that
    Ogre::SceneManagerEnumerator::SceneManagerIterator it = Ogre::Root::getSingletonPtr()->getSceneManagerIterator();
    it.getNext();
    if ( !it.hasMoreElements() )
    {
        return true;
    }

    it = Ogre::Root::getSingletonPtr()->getSceneManagerIterator();
    while ( it.hasMoreElements() )
    {
        it.getNext()->getRenderQueue()->clear( true );
    }
    return true;
}
	void LayerManager::initialise()
	{
		MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
		MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);

		WidgetManager::getInstance().registerUnlinker(this);
		Gui::getInstance().registerLoadXmlDelegate(XML_TYPE) = newDelegate(this, &LayerManager::_load);

		Ogre::SceneManagerEnumerator::SceneManagerIterator iter = Ogre::Root::getSingleton().getSceneManagerIterator();
		if (iter.hasMoreElements()) {
			mSceneManager = iter.getNext();
			mSceneManager->addRenderQueueListener(this);
		}
		else {
			mSceneManager = null;
		}

		// инициализация
		mPixScaleX = mPixScaleY = 1;
        mHOffset = mVOffset = 0;
		mAspectCoef = 1;
		mUpdate = false;

		MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
		mIsInitialise = true;

		// не забывай, о великий построитель гуёв
		// Кто здесь?
		mMaximumDepth = Ogre::Root::getSingleton().getRenderSystem()->getMaximumDepthInputValue();
	}
Example #3
0
	void COgreManager::updateSceneManagersAfterMaterialsChange()
	{
		if(Root::getSingletonPtr() && (Ogre::Pass::getDirtyHashList().size()!=0 || Ogre::Pass::getPassGraveyard().size()!=0))
		{
			Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Root::getSingletonPtr()->getSceneManagerIterator();

			while(scenesIter.hasMoreElements())
			{
				Ogre::SceneManager* pScene = scenesIter.getNext();
				if(pScene)
				{
					Ogre::RenderQueue* pQueue = pScene->getRenderQueue();
					if(pQueue)
					{
						Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator();
						while(groupIter.hasMoreElements())
						{
							Ogre::RenderQueueGroup* pGroup = groupIter.getNext();
							if(pGroup)
								pGroup->clear(false);
						}//end_while(groupIter.hasMoreElements())
					}//end_if(pScene)
				}//end_if(pScene)
			}//end_while(scenesIter.hasMoreElements())      

			// Now trigger the pending pass updates
			Ogre::Pass::processPendingPassUpdates();

		}//end_if(m_Root..
	}
Example #4
0
void TerrainMaterialCompilationTask::updateSceneManagersAfterMaterialsChange()
{
    //We need to do this to prevent stale hashes in Ogre, which will lead to crashes during rendering.
    if (Ogre::Pass::getDirtyHashList().size() != 0 || Ogre::Pass::getPassGraveyard().size() != 0) {
        Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Ogre::Root::getSingleton().getSceneManagerIterator();

        while (scenesIter.hasMoreElements()) {
            Ogre::SceneManager* pScene = scenesIter.getNext();
            if (pScene) {
                Ogre::RenderQueue* pQueue = pScene->getRenderQueue();
                if (pQueue) {
                    Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator();
                    while (groupIter.hasMoreElements()) {
                        Ogre::RenderQueueGroup* pGroup = groupIter.getNext();
                        if (pGroup)
                            pGroup->clear(false);
                    }//end_while(groupIter.hasMoreElements())
                }//end_if(pScene)
            }//end_if(pScene)
        }//end_while(scenesIter.hasMoreElements())

        // Now trigger the pending pass updates
        Ogre::Pass::processPendingPassUpdates();

    }//end_if(m_Root..
}
void updateSceneManagersAfterMaterialsChange()
{
    Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Ogre::Root::getSingletonPtr()->getSceneManagerIterator();

    while(scenesIter.hasMoreElements())
    {
        Ogre::SceneManager* pScene = scenesIter.getNext();
        if(pScene)
        {
            Ogre::RenderQueue* pQueue = pScene->getRenderQueue();
            if(pQueue)
            {
                Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator();
                while(groupIter.hasMoreElements())
                {
                    Ogre::RenderQueueGroup* pGroup = groupIter.getNext();
                    if(pGroup)
                    {
                        pGroup->clear(true);
                    }
                }
            }
        }
    }

    // Now trigger the pending pass updates
    Ogre::Pass::processPendingPassUpdates();


}
void ResourceGroupReloader::updateOnEveryRenderable()
{

	//1/ get all the available object type (entity, light, user defined types ...)
	std::vector<std::string> allAvailableTypes; 
	Ogre::Root::MovableObjectFactoryIterator iterFactory = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
	for(;iterFactory.hasMoreElements();)
	{
		Ogre::MovableObjectFactory* factory = iterFactory.getNext();
		allAvailableTypes.push_back(factory->getType());
	}

	UpdateMaterialRenderableVisitor lRenderableVisitor;

	//2/ for each scene manager, lets visit renderables!
	// unfortunately that does not cover all renderables type... (overlays...)
	Ogre::SceneManagerEnumerator::SceneManagerIterator iterSceneManager = Ogre::Root::getSingleton().getSceneManagerIterator();
	for(;iterSceneManager.hasMoreElements();)
	{
		Ogre::SceneManager * scMgr = iterSceneManager.getNext();

		std::vector<std::string>::iterator iterMovableType = allAvailableTypes.begin();
		std::vector<std::string>::iterator iterMovableTypeEnd = allAvailableTypes.end();
		for(;iterMovableType!=iterMovableTypeEnd;iterMovableType++)
		{
			Ogre::SceneManager::MovableObjectIterator iterMovable = scMgr->getMovableObjectIterator(*iterMovableType);
			for(;iterMovable.hasMoreElements();)
			{
				Ogre::MovableObject * movable = iterMovable.getNext();
				movable->visitRenderables(&lRenderableVisitor,false);
			}
		}
	}

	// 3 / visit overlays!
	{
		Ogre::OverlayManager::OverlayMapIterator iterOverlay = Ogre::OverlayManager::getSingleton().getOverlayIterator();
		for(;iterOverlay.hasMoreElements();)
		{
			Ogre::Overlay* lOverlay = iterOverlay.getNext();
			// get the first level of OverlayContainer in the Overlay
			Ogre::Overlay::Overlay2DElementsIterator iterOverlayElem = lOverlay->get2DElementsIterator();
			for(;iterOverlayElem.hasMoreElements();)
			{
				Ogre::OverlayContainer * lOverlayCont = iterOverlayElem.getNext();
				visitRecursivelyRenderablesFrom(lOverlayCont,lRenderableVisitor, false);
			}
		}
	}
}
Example #7
0
void ResourceLoader::resetRenderQueues() {
    Ogre::Root& root = Ogre::Root::getSingleton();
    Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = root.getSceneManagerIterator();
    while (scenesIter.hasMoreElements()) {
        Ogre::SceneManager* pScene = scenesIter.getNext();
        if (pScene) {
            Ogre::RenderQueue* pQueue = pScene->getRenderQueue();
            if (pQueue) {
                pQueue->clear(true);
            }
        }
    }
    Ogre::Pass::processPendingPassUpdates();
    mNeedRenderQueuesReset = false;
}
ModelDefinitionManager::~ModelDefinitionManager()
{
	Ogre::ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
	Ogre::ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
	//we need to make sure that all Models are destroyed before Ogre begins destroying other movable objects (such as Entities)
	//this is because Model internally uses Entities, so if those Entities are destroyed by Ogre before the Models are destroyed, the Models will try to delete them again, causing segfaults and other wickedness
	Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerIterator =  Ogre::SceneManagerEnumerator::getSingleton().getSceneManagerIterator();
	while (sceneManagerIterator.hasMoreElements()) {
		sceneManagerIterator.getNext()->destroyAllMovableObjectsByType(Model::sMovableType);
	}

	if (mModelFactory) {
		Ogre::Root::getSingleton().removeMovableObjectFactory(mModelFactory);
		delete mModelFactory;
	}

}
Example #9
0
void OgreInfo::diagnose(std::ostream& outputStream)
{
	Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerI = Ogre::Root::getSingleton().getSceneManagerIterator();
	while (sceneManagerI.hasMoreElements()) {
		Ogre::SceneManager* sceneManager = sceneManagerI.getNext();
		outputStream << "Scenemanager(" << sceneManager->getTypeName() << ") " << sceneManager->getName() << std::endl;
		outputStream << " Number of scene nodes: " << countNodes(sceneManager->getRootSceneNode()) << std::endl;
		outputStream << " Movable objects:" << std::endl;
		unsigned int movableObjectCounter = 0;
		Ogre::Root::MovableObjectFactoryIterator movableObjectFactoryI = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
		while (movableObjectFactoryI.hasMoreElements()) {
			Ogre::MovableObjectFactory* factory = movableObjectFactoryI.getNext();
			std::string type(factory->getType());
			{
				Ogre::SceneManager::MovableObjectIterator I = sceneManager->getMovableObjectIterator(type);
				while (I.hasMoreElements()) {
					movableObjectCounter++;
					Ogre::MovableObject* movable = I.getNext();
					if (movable->getMovableType() == "Light") {
						Ogre::Light* light = static_cast<Ogre::Light*> (movable);
						outputStream << "  * Light " << light->getName() << "(" << (light->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
						outputStream << "   Pos: " << light->getDerivedPosition() << std::endl;
						outputStream << "   Direction: " << light->getDerivedDirection() << std::endl;

					} else {
						std::stringstream ssPosAndOrientation;
						if (movable->getParentSceneNode() && movable->isInScene()) {
							ssPosAndOrientation << " pos: " << movable->getParentSceneNode()->getPosition() << " orientation: " << movable->getParentSceneNode()->getOrientation();
						}
						outputStream << "  * " << type << " " << movable->getName() << "(" << (movable->isInScene() ? "in scene" : "not in scene") << ")" << ssPosAndOrientation.str() << std::endl;
						//					outputStream << "  Pos: " << light->getDerivedPosition() << std::endl;
						//					outputStream << "  Direction: " << light->getDerivedDirection() << std::endl;
					}
				}
			}
		}

		outputStream << " Number of movable objects: " << movableObjectCounter << std::endl;

		outputStream << " Cameras:" << std::endl;
		{
			Ogre::SceneManager::CameraIterator I = sceneManager->getCameraIterator();
			while (I.hasMoreElements()) {
				Ogre::Camera* camera = I.getNext();
				outputStream << "  Camera " << camera->getName() << "(" << (camera->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
				outputStream << "  Pos: " << camera->getDerivedPosition() << std::endl;
				outputStream << "  Direction: " << camera->getDerivedDirection() << std::endl;
				outputStream << "  Clip distances: " << camera->getNearClipDistance() << " - " << camera->getFarClipDistance() << std::endl;
			}
		}

	}

	size_t resourceMemoryUsage = 0;
	outputStream << "Resource Managers:" << std::endl;
	Ogre::ResourceGroupManager::ResourceManagerIterator I = Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
	while (I.hasMoreElements()) {
		std::string name = I.peekNextKey();
		Ogre::ResourceManager* manager = I.getNext();
		outputStream << " Resource Manager: " << name << std::endl;
		if (manager->getMemoryBudget() == std::numeric_limits<size_t>::max()) {
			outputStream << "  Memory budget: not set" << std::endl;
		} else {
			outputStream << "  Memory budget: " << manager->getMemoryBudget() << " bytes" << std::endl;
		}
		outputStream << "  Memory usage:  " << manager->getMemoryUsage() << " bytes" << std::endl;
		resourceMemoryUsage += manager->getMemoryUsage();

		Ogre::ResourceManager::ResourceMapIterator resourceI = manager->getResourceIterator();
		if (resourceI.hasMoreElements()) {
			outputStream << "  Resources: " << std::endl;
			int resourceCount = 0;
			int loadedResourceCount = 0;
			while (resourceI.hasMoreElements()) {
				Ogre::ResourcePtr resource = resourceI.getNext();
				if (resource->isLoaded()) {
					std::string reloadable = resource->isReloadable() ? " reloadable" : "";
					outputStream << "   " << resource->getName() << " ( " << resource->getSize() << " bytes)" << reloadable;
					Ogre::Texture* texture = dynamic_cast<Ogre::Texture*>(resource.get());
					if (texture) {
						outputStream << texture->getWidth() << "x" << texture->getHeight() << " ";
					}
					outputStream << std::endl;
					loadedResourceCount++;
				}
				resourceCount++;
			}
			outputStream << "  Total number of resources: " << resourceCount << std::endl;
			outputStream << "  Number of loaded resources: " << loadedResourceCount << std::endl;
		}
	}

	outputStream << "Total memory usage for all resource manager: " << resourceMemoryUsage << " bytes" << std::endl;

	outputStream << std::flush;
}