From b450c18aa6d02f53966cb62862066893829c581d Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 29 Apr 2023 15:42:29 -0400
Subject: [PATCH] Fix RLV effects again

---
 indra/newview/pipeline.cpp   | 17 +++++++++++++++--
 indra/newview/rlvhandler.cpp |  7 +++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 71d3eb6f2cf..78e68df9c9d 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -857,7 +857,10 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
 
 		if (!mPostMap.allocate(resX, resY, GL_RGBA)) return false;
 		if (!mPostFXMap.allocate(resX, resY, GL_RGBA)) return false;
-		if (RenderDepthOfField || samples > 0)
+//		if (RenderDepthOfField || samples > 0)
+// [RLVa:KB] - @setsphere
+		if (RenderDepthOfField || samples > 0 || RlvActions::hasPostProcess())
+// [/RLVa:KB]
 		{ //only need mPostHelperMap for dof OR fxaa
 			if (!mPostHelperMap.allocate(resX, resY, GL_RGBA)) return false;
 		}
@@ -7650,7 +7653,17 @@ void LLPipeline::renderFinalize()
 
     combineGlow(&mPostMap, &mPostFXMap);
 
-	renderDoF(&mPostFXMap, &mPostMap);
+	// [RLVa:KB] - @setsphere
+	LLRenderTarget* pRenderBuffer = &mPostFXMap;
+	if (RlvActions::hasBehaviour(RLV_BHVR_SETSPHERE))
+	{
+		LLShaderEffectParams params(pRenderBuffer, &mPostHelperMap, false);
+		LLVfxManager::instance().runEffect(EVisualEffect::RlvSphere, &params);
+		pRenderBuffer = params.m_pDstBuffer;
+	}
+// [/RLVa:KB]
+
+	renderDoF(pRenderBuffer, &mPostMap);
 
 	gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft;
 	gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom;
diff --git a/indra/newview/rlvhandler.cpp b/indra/newview/rlvhandler.cpp
index 3358c68b22b..1c6b6eff329 100644
--- a/indra/newview/rlvhandler.cpp
+++ b/indra/newview/rlvhandler.cpp
@@ -2139,6 +2139,13 @@ ERlvCmdRet RlvBehaviourHandler<RLV_BHVR_SETSPHERE>::onCommand(const RlvCommand&
 		if (gRlvHandler.hasBehaviour(rlvCmd.getObjectID(), rlvCmd.getBehaviourType()))
 		{
 			LLVfxManager::instance().addEffect(new RlvSphereEffect(rlvCmd.getObjectID()));
+			if (!gPipeline.mPostHelperMap.isComplete())
+			{
+				// In case of deferred with no shadows, no ambient occlusion, no depth of field, and no antialiasing
+				gPipeline.releaseGLBuffers();
+				gPipeline.createGLBuffers();
+				RLV_ASSERT(gPipeline.mPostHelperMap.isComplete());
+			}
 		}
 		else
 		{
-- 
GitLab