From e11c724b20b6405b39ffe34dbf2beb38b5fc1ac5 Mon Sep 17 00:00:00 2001
From: Drake Arconis <drake@alchemyviewer.org>
Date: Tue, 3 Jan 2017 19:26:02 -0500
Subject: [PATCH] Tweak stencil and tree masking

---
 indra/newview/lldrawpool.h           | 2 +-
 indra/newview/lldrawpoolwater.cpp    | 1 +
 indra/newview/lldrawpoolwlsky.cpp    | 1 +
 indra/newview/llmaniptranslate.cpp   | 1 +
 indra/newview/llspatialpartition.cpp | 2 ++
 indra/newview/llvieweroctree.cpp     | 2 ++
 indra/newview/pipeline.cpp           | 4 +++-
 7 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/indra/newview/lldrawpool.h b/indra/newview/lldrawpool.h
index 20e5c91296..7d76e1cf26 100644
--- a/indra/newview/lldrawpool.h
+++ b/indra/newview/lldrawpool.h
@@ -52,9 +52,9 @@ public:
 		POOL_BUMP,
 		POOL_MATERIALS,
 		POOL_TERRAIN,	
+		POOL_TREE,
 		POOL_SKY,
 		POOL_WL_SKY,
-		POOL_TREE,
 		POOL_ALPHA_MASK,
 		POOL_FULLBRIGHT_ALPHA_MASK,
 		POOL_GRASS,
diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index 457184e94a..297bc4e37c 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -248,6 +248,7 @@ void LLDrawPoolWater::render(S32 pass)
 	
 	glClearStencil(1);
 	glClear(GL_STENCIL_BUFFER_BIT);
+	glClearStencil(0);
 	LLGLEnable gls_stencil(GL_STENCIL_TEST);
 	glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP);
 	glStencilFunc(GL_ALWAYS, 0, 0xFFFFFFFF);
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index d041204b12..19b2230ef6 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -323,6 +323,7 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
 
 	const F32 camHeightLocal = LLWLParamManager::getInstance()->getDomeOffset() * LLWLParamManager::getInstance()->getDomeRadius();
 
+	LLGLDisable stencil(GL_STENCIL_TEST);
 	LLGLSNoFog disableFog;
 	LLGLDepthTest depth(GL_TRUE, GL_FALSE);
 	LLGLDisable clip(GL_CLIP_PLANE0);
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp
index 2c4e4ca83d..b441c4d51b 100644
--- a/indra/newview/llmaniptranslate.cpp
+++ b/indra/newview/llmaniptranslate.cpp
@@ -1661,6 +1661,7 @@ void LLManipTranslate::highlightIntersection(LLVector3 normal,
 		glStencilMask(stencil_mask);
 		glClearStencil(1);
 		glClear(GL_STENCIL_BUFFER_BIT);
+		glClearStencil(0);
 		LLGLEnable cull_face(GL_CULL_FACE);
 		LLGLEnable stencil(GL_STENCIL_TEST);
 		LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS);
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 3a3949334d..a85212c511 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -3175,6 +3175,8 @@ public:
 			return;
 		}
 
+		LLGLDisable stencil(GL_STENCIL_TEST);
+
 		group->rebuildGeom();
 		group->rebuildMesh();
 
diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp
index 7c5a8b8631..00ddee5f38 100644
--- a/indra/newview/llvieweroctree.cpp
+++ b/indra/newview/llvieweroctree.cpp
@@ -1194,6 +1194,8 @@ void LLOcclusionCullingGroup::doOcclusion(LLCamera* camera, const LLVector4a* sh
 {
 	if (mSpatialPartition->isOcclusionEnabled() && LLPipeline::sUseOcclusion > 1)
 	{
+		LLGLDisable stencil(GL_STENCIL_TEST);
+
 		//move mBounds to the agent space if necessary
 		LLVector4a bounds[2];
 		bounds[0] = mBounds[0];
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 2ab8dd275b..7fb389ac60 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -287,9 +287,9 @@ std::string gPoolNames[] =
 	"POOL_BUMP",
 	"POOL_MATERIALS",
 	"POOL_TERRAIN,"	
+	"POOL_TREE",
 	"POOL_SKY",
 	"POOL_WL_SKY",
-	"POOL_TREE",
 	"POOL_ALPHA_MASK",
 	"POOL_FULLBRIGHT_ALPHA_MASK",
 	"POOL_GRASS",
@@ -2400,6 +2400,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl
 
 	LLGLDisable blend(GL_BLEND);
 	LLGLDisable test(GL_ALPHA_TEST);
+	LLGLDisable stencil(GL_STENCIL_TEST);
 	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
 
@@ -3967,6 +3968,7 @@ void LLPipeline::renderHighlights()
 		glStencilMask(0xFFFFFFFF);
 		glClearStencil(1);
 		glClear(GL_STENCIL_BUFFER_BIT);
+		glClearStencil(0);
 
 		glStencilFunc(GL_ALWAYS, 0, 0xFFFFFFFF);
 		glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
-- 
GitLab