From 0782839a4286723ba08181632e89342fd9e33a10 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 12 Mar 2017 23:04:08 +0100 Subject: [PATCH] Avoid redundant culling tests on the transform/drawable --- components/terrain/chunkmanager.cpp | 12 ++++++++++++ components/terrain/chunkmanager.hpp | 4 ++++ components/terrain/quadtreeworld.cpp | 2 ++ components/terrain/terraindrawable.cpp | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 3eb48d88f..b0860ecf2 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -27,6 +27,7 @@ ChunkManager::ChunkManager(Storage *storage, Resource::SceneManager *sceneMgr, T , mTextureManager(textureManager) , mCompositeMapRenderer(renderer) , mCompositeMapSize(512) + , mCullingActive(true) { } @@ -53,6 +54,11 @@ void ChunkManager::reportStats(unsigned int frameNumber, osg::Stats *stats) cons stats->setAttribute(frameNumber, "Terrain Chunk", mCache->getCacheSize()); } +void ChunkManager::setCullingActive(bool active) +{ + mCullingActive = active; +} + osg::ref_ptr ChunkManager::createCompositeMapRTT() { osg::ref_ptr texture = new osg::Texture2D; @@ -207,6 +213,12 @@ osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Ve transform->addChild(geometry); + if (!mCullingActive) + { + transform->setCullingActive(false); + geometry->setCullingActive(false); + } + if (mSceneManager->getIncrementalCompileOperation()) { mSceneManager->getIncrementalCompileOperation()->add(geometry); diff --git a/components/terrain/chunkmanager.hpp b/components/terrain/chunkmanager.hpp index 08cf2d70c..58db98dc9 100644 --- a/components/terrain/chunkmanager.hpp +++ b/components/terrain/chunkmanager.hpp @@ -39,6 +39,8 @@ namespace Terrain virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) const; + void setCullingActive(bool active); + private: osg::ref_ptr createChunk(float size, const osg::Vec2f& center, int lod, unsigned int lodFlags); @@ -55,6 +57,8 @@ namespace Terrain BufferCache mBufferCache; unsigned int mCompositeMapSize; + + bool mCullingActive; }; } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 649496e8d..d65b1d5ed 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -240,6 +240,8 @@ QuadTreeWorld::QuadTreeWorld(osg::Group *parent, osg::Group *compileRoot, Resour , mViewDataMap(new ViewDataMap) , mQuadTreeBuilt(false) { + // No need for culling on the Drawable / Transform level as the quad tree performs the culling already. + mChunkManager->setCullingActive(false); } QuadTreeWorld::~QuadTreeWorld() diff --git a/components/terrain/terraindrawable.cpp b/components/terrain/terraindrawable.cpp index b5934eb12..8557233ed 100644 --- a/components/terrain/terraindrawable.cpp +++ b/components/terrain/terraindrawable.cpp @@ -43,7 +43,7 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv) { const osg::BoundingBox& bb = getBoundingBox(); - if (cv->isCulled(getBoundingBox())) + if (_cullingActive && cv->isCulled(getBoundingBox())) return; osg::RefMatrix& matrix = *cv->getModelViewMatrix();