diff options
Diffstat (limited to 'indra/newview/llvocache.cpp')
-rwxr-xr-x | indra/newview/llvocache.cpp | 132 |
1 files changed, 107 insertions, 25 deletions
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index 98a924b3be..2576a69f26 100755 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -34,6 +34,7 @@ #include "llviewerregion.h" #include "pipeline.h" +BOOL LLVOCachePartition::sNeedsOcclusionCheck = FALSE; LLTrace::MemStatHandle LLVOCachePartition::sMemStat("LLVOCachePartition"); BOOL check_read(LLAPRFile* apr_file, void* src, S32 n_bytes) @@ -263,6 +264,28 @@ void LLVOCacheEntry::addChild(LLVOCacheEntry* entry) } } +void LLVOCacheEntry::removeChild(LLVOCacheEntry* entry) +{ + for(S32 i = 0; i < mChildrenList.size(); i++) + { + if(mChildrenList[i] == entry) + { + entry->setParentID(0); + mChildrenList[i] = mChildrenList[mChildrenList.size() - 1]; + mChildrenList.pop_back(); + } + } +} + +void LLVOCacheEntry::removeAllChildren() +{ + for(S32 i = 0; i < mChildrenList.size(); i++) + { + mChildrenList[i]->setParentID(0); + } + mChildrenList.clear(); +} + LLDataPackerBinaryBuffer *LLVOCacheEntry::getDP(U32 crc) { if ( (mCRC != crc) @@ -445,8 +468,14 @@ LLVOCachePartition::LLVOCachePartition(LLViewerRegion* regionp) { mLODPeriod = 16; mRegionp = regionp; - mPartitionType = LLViewerRegion::PARTITION_VO_CACHE; - + mPartitionType = LLViewerRegion::PARTITION_VO_CACHE; + mDirty = FALSE; + + for(S32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++) + { + mCulledTime[i] = 0; + mCullHistory[i] = -1; + } new LLOcclusionCullingGroup(mOctree, this); } @@ -455,6 +484,7 @@ void LLVOCachePartition::addEntry(LLViewerOctreeEntry* entry) llassert(entry->hasVOCacheEntry()); mOctree->insert(entry); + mDirty = TRUE; } void LLVOCachePartition::removeEntry(LLViewerOctreeEntry* entry) @@ -473,7 +503,7 @@ public: mPartition(part) { mLocalShift = shift; - mUseObjectCacheOcclusion = (use_object_cache_occlusion && LLPipeline::sUseOcclusion); + mUseObjectCacheOcclusion = use_object_cache_occlusion; } virtual bool earlyFail(LLviewerOctreeGroup* base_group) @@ -490,9 +520,8 @@ public: group->checkOcclusion(); - if (group->isOcclusionState(LLSpatialGroup::OCCLUDED)) + if (group->isOcclusionState(LLOcclusionCullingGroup::OCCLUDED)) { - mPartition->addOccluders(group); return true; } } @@ -530,7 +559,32 @@ public: virtual void processGroup(LLviewerOctreeGroup* base_group) { - mRegionp->addVisibleGroup(base_group); + if( !mUseObjectCacheOcclusion || + !base_group->getOctreeNode()->getParent()) + { + //no occlusion check + mRegionp->addVisibleGroup(base_group); + return; + } + + LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)base_group; + if(!group->isRecentlyVisible())//needs to issue new occlusion culling check. + { + mPartition->addOccluders(group); + group->setVisible(); + return ; //wait for occlusion culling result + } + + if(group->isOcclusionState(LLOcclusionCullingGroup::QUERY_PENDING) || + group->isOcclusionState(LLOcclusionCullingGroup::ACTIVE_OCCLUSION)) + { + //keep waiting + group->setVisible(); + } + else + { + mRegionp->addVisibleGroup(base_group); + } } private: @@ -540,46 +594,52 @@ private: bool mUseObjectCacheOcclusion; }; -S32 LLVOCachePartition::cull(LLCamera &camera) +S32 LLVOCachePartition::cull(LLCamera &camera, bool do_occlusion) { static LLCachedControl<bool> use_object_cache_occlusion(gSavedSettings,"UseObjectCacheOcclusion"); - + if(!LLViewerRegion::sVOCacheCullingEnabled) { return 0; } + if(mCulledTime[LLViewerCamera::sCurCameraID] == LLViewerOctreeEntryData::getCurrentFrame()) + { + return 0; //already culled + } + mCulledTime[LLViewerCamera::sCurCameraID] = LLViewerOctreeEntryData::getCurrentFrame(); + + if(!mDirty && !mCullHistory[LLViewerCamera::sCurCameraID] && LLViewerRegion::isViewerCameraStatic()) + { + return 0; //nothing changed, skip culling + } + ((LLviewerOctreeGroup*)mOctree->getListener(0))->rebound(); + mCullHistory[LLViewerCamera::sCurCameraID] <<= 2; //localize the camera LLVector3 region_agent = mRegionp->getOriginAgent(); camera.calcRegionFrustumPlanes(region_agent); - mOccludedGroups.clear(); - - LLVOCacheOctreeCull culler(&camera, mRegionp, region_agent, use_object_cache_occlusion, this); + LLVOCacheOctreeCull culler(&camera, mRegionp, region_agent, do_occlusion && use_object_cache_occlusion, this); culler.traverse(mOctree); - if(!mOccludedGroups.empty()) + if(mRegionp->getNumOfVisibleGroups() > 0) { - processOccluders(&camera, ®ion_agent); - mOccludedGroups.clear(); + mCullHistory[LLViewerCamera::sCurCameraID] |= 1; } - return 0; + if(!sNeedsOcclusionCheck) + { + sNeedsOcclusionCheck = !mOccludedGroups.empty(); + } + return 1; } void LLVOCachePartition::addOccluders(LLviewerOctreeGroup* gp) { LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)gp; - const U32 MIN_WAIT_TIME = 19; //wait 19 frames to issue a new occlusion request - U32 last_issued_time = group->getLastOcclusionIssuedTime(); - if(!group->needsUpdate() && gFrameCount > last_issued_time && gFrameCount < last_issued_time + MIN_WAIT_TIME) - { - return; - } - if(!group->isOcclusionState(LLOcclusionCullingGroup::ACTIVE_OCCLUSION)) { group->setOcclusionState(LLOcclusionCullingGroup::ACTIVE_OCCLUSION); @@ -587,14 +647,36 @@ void LLVOCachePartition::addOccluders(LLviewerOctreeGroup* gp) } } -void LLVOCachePartition::processOccluders(LLCamera* camera, const LLVector3* region_agent) +void LLVOCachePartition::processOccluders(LLCamera* camera) +{ + if(mOccludedGroups.empty()) + { + return; + } + + LLVector3 region_agent = mRegionp->getOriginAgent(); + for(std::set<LLOcclusionCullingGroup*>::iterator iter = mOccludedGroups.begin(); iter != mOccludedGroups.end(); ++iter) + { + LLOcclusionCullingGroup* group = *iter; + group->doOcclusion(camera, ®ion_agent); + } +} + +void LLVOCachePartition::resetOccluders() { + if(mOccludedGroups.empty()) + { + return; + } + for(std::set<LLOcclusionCullingGroup*>::iterator iter = mOccludedGroups.begin(); iter != mOccludedGroups.end(); ++iter) { LLOcclusionCullingGroup* group = *iter; - group->doOcclusion(camera, region_agent); group->clearOcclusionState(LLOcclusionCullingGroup::ACTIVE_OCCLUSION); - } + } + mOccludedGroups.clear(); + mDirty = FALSE; + sNeedsOcclusionCheck = FALSE; } //------------------------------------------------------------------- |