From a29f7c3b4ac50951aa86a71cb6ba20b712533c70 Mon Sep 17 00:00:00 2001
From: RunitaiLinden <davep@lindenlab.com>
Date: Mon, 23 Oct 2023 13:54:00 -0500
Subject: [PATCH] SL-20498 Preserve default probe when resetting reflection
 probes.

---
 indra/llrender/llcubemaparray.cpp        |  2 ++
 indra/llrender/llcubemaparray.h          |  8 ++++++++
 indra/newview/llreflectionmapmanager.cpp | 20 +++++++++++++++-----
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/indra/llrender/llcubemaparray.cpp b/indra/llrender/llcubemaparray.cpp
index 7d3a92237b4..1debd33953a 100644
--- a/indra/llrender/llcubemaparray.cpp
+++ b/indra/llrender/llcubemaparray.cpp
@@ -110,6 +110,8 @@ LLCubeMapArray::~LLCubeMapArray()
 void LLCubeMapArray::allocate(U32 resolution, U32 components, U32 count, BOOL use_mips)
 {
     U32 texname = 0;
+    mWidth = resolution;
+    mCount = count;
 
     LLImageGL::generateTextures(1, &texname);
 
diff --git a/indra/llrender/llcubemaparray.h b/indra/llrender/llcubemaparray.h
index 19c86278a13..6c3f7dc8907 100644
--- a/indra/llrender/llcubemaparray.h
+++ b/indra/llrender/llcubemaparray.h
@@ -60,9 +60,17 @@ class LLCubeMapArray : public LLRefCount
 
 	void destroyGL();
 
+    // get width of cubemaps in array (they're cubes, so this is also the height)
+    U32 getWidth() const { return mWidth; }
+
+    // get number of cubemaps in the array
+    U32 getCount() const { return mCount; }
+
 protected:
 	friend class LLTexUnit;
 	~LLCubeMapArray();
 	LLPointer<LLImageGL> mImage;
+    U32 mWidth = 0;
+    U32 mCount = 0;
 	S32 mTextureStage;
 };
diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp
index 283c97ff0a1..72f7e23b0cd 100644
--- a/indra/newview/llreflectionmapmanager.cpp
+++ b/indra/newview/llreflectionmapmanager.cpp
@@ -1258,13 +1258,18 @@ void LLReflectionMapManager::initReflectionMaps()
         mProbeResolution = nhpo2(llclamp(gSavedSettings.getU32("RenderReflectionProbeResolution"), (U32)64, (U32)512));
         mMaxProbeLOD = log2f(mProbeResolution) - 1.f; // number of mips - 1
 
-        mTexture = new LLCubeMapArray();
+        if (mTexture.isNull() ||
+            mTexture->getWidth() != mProbeResolution ||
+            mReflectionProbeCount + 2 != mTexture->getCount())
+        {
+            mTexture = new LLCubeMapArray();
 
-        // store mReflectionProbeCount+2 cube maps, final two cube maps are used for render target and radiance map generation source)
-        mTexture->allocate(mProbeResolution, 3, mReflectionProbeCount + 2);
+            // store mReflectionProbeCount+2 cube maps, final two cube maps are used for render target and radiance map generation source)
+            mTexture->allocate(mProbeResolution, 3, mReflectionProbeCount + 2);
 
-        mIrradianceMaps = new LLCubeMapArray();
-        mIrradianceMaps->allocate(LL_IRRADIANCE_MAP_RESOLUTION, 3, mReflectionProbeCount, FALSE);
+            mIrradianceMaps = new LLCubeMapArray();
+            mIrradianceMaps->allocate(LL_IRRADIANCE_MAP_RESOLUTION, 3, mReflectionProbeCount, FALSE);
+        }
 
         // reset probe state
         mUpdatingFace = 0;
@@ -1272,6 +1277,9 @@ void LLReflectionMapManager::initReflectionMaps()
         mRadiancePass = false;
         mRealtimeRadiancePass = false;
 
+        // if default probe already exists, remember whether or not it's complete (SL-20498)
+        bool default_complete = mDefaultProbe.isNull() ? false : mDefaultProbe->mComplete;
+
         for (auto& probe : mProbes)
         {
             probe->mLastUpdateTime = 0.f;
@@ -1299,6 +1307,8 @@ void LLReflectionMapManager::initReflectionMaps()
         mDefaultProbe->mDistance = 64.f;
         mDefaultProbe->mRadius = 4096.f;
         mDefaultProbe->mProbeIndex = 0;
+        mDefaultProbe->mComplete = default_complete;
+
         touch_default_probe(mDefaultProbe);
 
     }
-- 
GitLab