diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 08b7c1300d..42a44ceff1 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -201,12 +201,14 @@ osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Ve compositeMapNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - mCompositeMapRenderer->addCompositeMap(compositeMapNode, true); + mCompositeMapRenderer->addCompositeMap(compositeMapNode, false); std::vector > passes2; passes2.push_back(new osg::StateSet); passes2[0]->setTextureAttributeAndModes(0, compositeMap, osg::StateAttribute::ON); geometry->setPasses(passes2); + + transform->getOrCreateUserDataContainer()->addUserObject(compositeMapNode); } else { diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 54c6c1470c..15835b0040 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -8,6 +8,7 @@ #include "storage.hpp" #include "viewdata.hpp" #include "chunkmanager.hpp" +#include "compositemaprenderer.hpp" namespace { @@ -314,7 +315,19 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) } if (entry.mVisible) + { + osg::UserDataContainer* udc = entry.mRenderingNode->getUserDataContainer(); + if (udc && udc->getNumUserObjects() > 0) + { + osg::Node* compositeMapNode = udc->getUserObject(0)->asNode(); + if (compositeMapNode) + { + mCompositeMapRenderer->setImmediate(compositeMapNode); + udc->removeUserObject(0); + } + } entry.mRenderingNode->accept(nv); + } } vd->reset(nv.getTraversalNumber()); diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index b662cd314e..4012523344 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -27,15 +27,14 @@ World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSyst mTerrainRoot->setName("Terrain Root"); - osg::ref_ptr renderer (new CompositeMapRenderer); - renderer->setNodeMask(preCompileMask); - compileRoot->addChild(renderer); - mCompositeMapRenderer = renderer; + mCompositeMapRenderer = new CompositeMapRenderer; + mCompositeMapRenderer->setNodeMask(preCompileMask); + compileRoot->addChild(mCompositeMapRenderer); mParent->addChild(mTerrainRoot); mTextureManager.reset(new TextureManager(mResourceSystem->getSceneManager())); - mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), renderer)); + mChunkManager.reset(new ChunkManager(mStorage, mResourceSystem->getSceneManager(), mTextureManager.get(), mCompositeMapRenderer)); mResourceSystem->addResourceManager(mChunkManager.get()); mResourceSystem->addResourceManager(mTextureManager.get()); diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index d4867d2ba5..091ddadd25 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -26,6 +26,7 @@ namespace Terrain class TextureManager; class ChunkManager; + class CompositeMapRenderer; /** * @brief The basic interface for a terrain world. How the terrain chunks are paged and displayed @@ -70,7 +71,7 @@ namespace Terrain osg::ref_ptr mParent; osg::ref_ptr mTerrainRoot; - osg::ref_ptr mCompositeMapRenderer; + osg::ref_ptr mCompositeMapRenderer; Resource::ResourceSystem* mResourceSystem;