From b0aa408a665ce61ff374f99e421812482fe53848 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Fri, 4 Oct 2013 11:09:29 -0600
Subject: [PATCH] fix for SH-4544: Interesting: Shadows from platforms above
 the camera flicker

---
 indra/newview/llspatialpartition.cpp | 2 +-
 indra/newview/llvieweroctree.cpp     | 8 ++++++++
 indra/newview/llvieweroctree.h       | 4 +++-
 indra/newview/llvocache.cpp          | 6 ++++++
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 0fbe1578cf5..50576b7a2ca 100755
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -1105,7 +1105,7 @@ class LLOctreeCull : public LLViewerOctreeCull
 	{
 		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
 		if (group->needsUpdate() ||
-			group->mVisible[LLViewerCamera::sCurCameraID] < LLDrawable::getCurrentFrame() - 1)
+			group->getVisible(LLViewerCamera::sCurCameraID) < LLDrawable::getCurrentFrame() - 1)
 		{
 			group->doOcclusion(mCamera);
 		}
diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp
index e8eba432428..56f10aba715 100644
--- a/indra/newview/llvieweroctree.cpp
+++ b/indra/newview/llvieweroctree.cpp
@@ -435,6 +435,7 @@ LLviewerOctreeGroup::~LLviewerOctreeGroup()
 
 LLviewerOctreeGroup::LLviewerOctreeGroup(OctreeNode* node) :
 	mOctreeNode(node),
+	mAnyVisible(0),
 	mState(CLEAN)
 {
 	LLVector4a tmp;
@@ -735,6 +736,7 @@ BOOL LLviewerOctreeGroup::isRecentlyVisible() const
 void LLviewerOctreeGroup::setVisible()
 {
 	mVisible[LLViewerCamera::sCurCameraID] = LLViewerOctreeEntryData::getCurrentFrame();
+	mAnyVisible = LLViewerOctreeEntryData::getCurrentFrame();
 }
 
 void LLviewerOctreeGroup::checkStates()
@@ -871,6 +873,12 @@ BOOL LLOcclusionCullingGroup::isRecentlyVisible() const
 	return (LLDrawable::getCurrentFrame() - mVisible[LLViewerCamera::sCurCameraID]) < MIN_VIS_FRAME_RANGE ;
 }
 
+BOOL LLOcclusionCullingGroup::isAnyRecentlyVisible() const
+{
+	const S32 MIN_VIS_FRAME_RANGE = 2;
+	return (LLDrawable::getCurrentFrame() - mAnyVisible) < MIN_VIS_FRAME_RANGE ;
+}
+
 //virtual 
 void LLOcclusionCullingGroup::handleChildAddition(const OctreeNode* parent, OctreeNode* child)
 {
diff --git a/indra/newview/llvieweroctree.h b/indra/newview/llvieweroctree.h
index 174af5e22f5..90870baaeae 100644
--- a/indra/newview/llvieweroctree.h
+++ b/indra/newview/llvieweroctree.h
@@ -233,6 +233,7 @@ class LLviewerOctreeGroup : public LLOctreeListener<LLViewerOctreeEntry>
 	void setVisible();
 	BOOL isVisible() const;
 	virtual BOOL isRecentlyVisible() const;
+	S32  getVisible(LLViewerCamera::eCameraID id) const {return mVisible[id];}
 	bool isEmpty() const { return mOctreeNode->isEmpty(); }
 
 	U32  getState()				   {return mState; }
@@ -278,7 +279,7 @@ class LLviewerOctreeGroup : public LLOctreeListener<LLViewerOctreeEntry>
 	LL_ALIGN_16(LLVector4a mExtents[2]);       // extents (min, max) of this node and all its children
 	LL_ALIGN_16(LLVector4a mObjectExtents[2]); // extents (min, max) of objects in this node	
 
-public:
+	S32         mAnyVisible; //latest visible to any camera
 	S32         mVisible[LLViewerCamera::NUM_CAMERAS];	
 
 };//LL_ALIGN_POSTFIX(16);
@@ -330,6 +331,7 @@ class LLOcclusionCullingGroup : public LLviewerOctreeGroup
 	//virtual
 	BOOL isRecentlyVisible() const;
 	LLViewerOctreePartition* getSpatialPartition()const {return mSpatialPartition;}
+	BOOL isAnyRecentlyVisible() const;
 
 	static U32 getNewOcclusionQueryObjectName();
 	static void releaseOcclusionQueryObjectName(U32 name);
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index ada412be8cb..71d5a92df30 100755
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -361,6 +361,12 @@ bool LLVOCacheEntry::isRecentlyVisible() const
 {
 	bool vis = LLViewerOctreeEntryData::isRecentlyVisible();
 
+	if(!vis && getGroup())
+	{
+		//recently visible to any camera?
+		vis = ((LLOcclusionCullingGroup*)getGroup())->isAnyRecentlyVisible();
+	}
+
 	//combination of projected area and squared distance
 	if(!vis && !mParentID && mSceneContrib > sBackAngleTanSquared) 
 	{
-- 
GitLab