From ae099c639fe45a13454d50526b1c8610ee98ea83 Mon Sep 17 00:00:00 2001
From: Graham Linden <graham@lindenlab.com>
Date: Mon, 1 Oct 2018 17:16:58 +0100
Subject: SL-1655

Make water horizon consistent between ALM and non-ALM rendering again.

Fix using deferred sky rendering in reflections.

Make matrix mode explicit around push/pop for safety.
---
 indra/newview/lldrawpoolwater.cpp | 40 ++++++++-------------------------------
 indra/newview/lldrawpoolwlsky.cpp | 30 ++++++++++++++---------------
 2 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index 7a25e62651..9eb61a1a1f 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -695,43 +695,19 @@ void LLDrawPoolWater::shade()
 		water_color.mV[3] = 0.9f;
 	}
 
-	{
-		LLGLEnable depth_clamp(gGLManager.mHasDepthClamp ? GL_DEPTH_CLAMP : 0);
+	{		
 		LLGLDisable cullface(GL_CULL_FACE);
-		for (std::vector<LLFace*>::iterator iter = mDrawFace.begin();
-			iter != mDrawFace.end(); iter++)
-		{
-			LLFace *face = *iter;
 
-			if (voskyp->isReflFace(face))
-			{
-				continue;
-			}
+        sNeedsReflectionUpdate = TRUE;			
+        sNeedsDistortionUpdate = TRUE;
 
-			LLVOWater* water = (LLVOWater*) face->getViewerObject();
+        for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); iter != mDrawFace.end(); iter++)
+		{
+			LLFace *face = *iter;
 			gGL.getTexUnit(diffTex)->bind(face->getTexture());
-
-			sNeedsReflectionUpdate = TRUE;
-			
-			if (water->getUseTexture() || !water->getIsEdgePatch())
-			{
-				sNeedsDistortionUpdate = TRUE;
-				face->renderIndexed();
-			}
-            // using squash clip for deferred rendering makes the horizon lines match
-            // between ALM and non-ALM rendering (SL-1655), but introduces an ugly seem between
-            // near and far water(SL-9696)...we're going to live with the former and not cause the latter 
-            else if (gGLManager.mHasDepthClamp || deferred_render)
-            {
-				face->renderIndexed();
-			}
-			else
-			{
-				LLGLSquashToFarClip far_clip(get_current_projection());
-				face->renderIndexed();
-			}
+            face->renderIndexed();
 		}
-	}
+    }
 	
 	shader->disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
 	shader->disableTexture(LLShaderMgr::WATER_SCREENTEX);	
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 455df837a9..a796052635 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -132,6 +132,7 @@ void LLDrawPoolWLSky::renderDome(const LLVector3& camPosLocal, F32 camHeightLoca
 {
     llassert_always(NULL != shader);
 
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 	gGL.pushMatrix();
 
 	//chop off translation
@@ -158,6 +159,7 @@ void LLDrawPoolWLSky::renderDome(const LLVector3& camPosLocal, F32 camHeightLoca
 
     gSky.mVOWLSkyp->drawDome();
 
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 	gGL.popMatrix();
 }
 
@@ -191,6 +193,7 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
 
         sky_shader->uniform3f(sCamPosLocal, camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
 
+        LLGLDisable cull(GL_CULL_FACE);
         renderFsSky(camPosLocal, camHeightLocal, sky_shader);
         
 		sky_shader->unbind();
@@ -565,28 +568,23 @@ void LLDrawPoolWLSky::render(S32 pass)
     LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
 
 	renderSkyHaze(origin, camHeightLocal);
-
-    bool use_advanced = gPipeline.useAdvancedAtmospherics();
     
-    if (!use_advanced)
-    {
-	    gGL.pushMatrix();
+	gGL.pushMatrix();
 
-        // MAINT-9006 keep sun position consistent between ALM and non-ALM rendering
-		//gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
+    // MAINT-9006 keep sun position consistent between ALM and non-ALM rendering
+	//gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
 
-		// *NOTE: have to bind a texture here since register combiners blending in
-		// renderStars() requires something to be bound and we might as well only
-		// bind the moon's texture once.		
-		gGL.getTexUnit(0)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture());
-        gGL.getTexUnit(1)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP));
+	// *NOTE: have to bind a texture here since register combiners blending in
+	// renderStars() requires something to be bound and we might as well only
+	// bind the moon's texture once.		
+	gGL.getTexUnit(0)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture());
+    gGL.getTexUnit(1)->bind(gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP));
 
-		renderHeavenlyBodies();
+    renderHeavenlyBodies();
 
-		renderStars();
+	renderStars();
 
-	    gGL.popMatrix();
-    }
+	gGL.popMatrix();
 
 	renderSkyClouds(origin, camHeightLocal);
 
-- 
cgit v1.2.3