From 912c8faf55a4d391f69eb18d4fda5a85a70de6ca Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Sat, 29 Jul 2017 14:48:43 +0100
Subject: [PATCH] SL-731 - diagnostic displays for LOD, tri count

---
 indra/newview/app_settings/settings.xml | 11 ++++++++
 indra/newview/llappviewer.cpp           |  1 +
 indra/newview/llcontrolavatar.cpp       | 17 ++++++++----
 indra/newview/llviewercontrol.cpp       |  7 +++++
 indra/newview/llvovolume.cpp            | 35 ++++++++++++++++---------
 indra/newview/llvovolume.h              |  1 +
 6 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index c8797f3f995..3e06e7094d6 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -10393,6 +10393,17 @@
 		<key>Value</key>
 		<integer>0</integer>
 	</map>
+	<key>RenderForceVolumeLOD</key>
+    <map>
+      <key>Comment</key>
+      <string>Override for all volume LODs</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>S32</string>
+      <key>Value</key>
+      <integer>-1</integer>
+    </map>
 	<key>RenderVolumeLODFactor</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index cfdc752db41..c52ef8a4708 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -594,6 +594,7 @@ static void settings_to_globals()
 	LLVertexBuffer::sUseVAO = gSavedSettings.getBOOL("RenderUseVAO");
 	LLImageGL::sGlobalUseAnisotropic	= gSavedSettings.getBOOL("RenderAnisotropic");
 	LLImageGL::sCompressTextures		= gSavedSettings.getBOOL("RenderCompressTextures");
+	LLVOVolume::sForceLOD				= gSavedSettings.getS32("RenderForceVolumeLOD");
 	LLVOVolume::sLODFactor				= gSavedSettings.getF32("RenderVolumeLODFactor");
 	LLVOVolume::sDistanceFactor			= 1.f-LLVOVolume::sLODFactor * 0.1f;
 	LLVolumeImplFlexible::sUpdateFactor = gSavedSettings.getF32("RenderFlexTimeFactor");
diff --git a/indra/newview/llcontrolavatar.cpp b/indra/newview/llcontrolavatar.cpp
index 9ed3020b66d..fb61328a1bf 100644
--- a/indra/newview/llcontrolavatar.cpp
+++ b/indra/newview/llcontrolavatar.cpp
@@ -212,11 +212,15 @@ void LLControlAvatar::updateDebugText()
         getAnimatedVolumes(volumes);
         S32 animated_volume_count = volumes.size();
         std::string active_string;
+        std::string lod_string;
+        S32 total_tris = 0;
         for (std::vector<LLVOVolume*>::iterator it = volumes.begin();
              it != volumes.end(); ++it)
         {
             LLVOVolume *volp = *it;
-            if (volp && volp->mDrawable)
+            total_tris += volp->getTriangleCount();
+            lod_string += llformat("%d",volp->getLOD());
+                        if (volp && volp->mDrawable)
             {
                 if (volp->mDrawable->isActive())
                 {
@@ -248,10 +252,13 @@ void LLControlAvatar::updateDebugText()
         }
 #endif
 
-        addDebugText(llformat("anim time %.1f (step %f factor %f)", 
-                              mMotionController.getAnimTime(),
-                              mMotionController.getTimeStep(), 
-                              mMotionController.getTimeFactor()));
+        addDebugText(llformat("lod %s",lod_string.c_str()));
+        addDebugText(llformat("tris %d", total_tris));
+        //addDebugText(llformat("anim time %.1f (step %f factor %f)", 
+        //                      mMotionController.getAnimTime(),
+        //                      mMotionController.getTimeStep(), 
+        //                      mMotionController.getTimeFactor()));
+        
     }
 
     LLVOAvatar::updateDebugText();
diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp
index 7c1921b1436..66f5bf3c379 100644
--- a/indra/newview/llviewercontrol.cpp
+++ b/indra/newview/llviewercontrol.cpp
@@ -208,6 +208,12 @@ static bool handleAnisotropicChanged(const LLSD& newvalue)
 	return true;
 }
 
+static bool handleForceLODChanged(const LLSD& newvalue)
+{
+	LLVOVolume::sForceLOD = (F32) newvalue.asReal();
+	return true;
+}
+
 static bool handleVolumeLODChanged(const LLSD& newvalue)
 {
 	LLVOVolume::sLODFactor = (F32) newvalue.asReal();
@@ -626,6 +632,7 @@ void settings_setup_listeners()
 	gSavedSettings.getControl("RenderAvatarCloth")->getSignal()->connect(boost::bind(&handleSetShaderChanged, _2));
 	gSavedSettings.getControl("WindLightUseAtmosShaders")->getSignal()->connect(boost::bind(&handleSetShaderChanged, _2));
 	gSavedSettings.getControl("RenderGammaFull")->getSignal()->connect(boost::bind(&handleSetShaderChanged, _2));
+	gSavedSettings.getControl("RenderForceVolumeLOD")->getSignal()->connect(boost::bind(&handleForceLODChanged, _2));
 	gSavedSettings.getControl("RenderVolumeLODFactor")->getSignal()->connect(boost::bind(&handleVolumeLODChanged, _2));
 	gSavedSettings.getControl("RenderAvatarLODFactor")->getSignal()->connect(boost::bind(&handleAvatarLODChanged, _2));
 	gSavedSettings.getControl("RenderAvatarPhysicsLODFactor")->getSignal()->connect(boost::bind(&handleAvatarPhysicsLODChanged, _2));
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index bdd0cb09848..c0814c56953 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -91,6 +91,8 @@ U32 JOINT_COUNT_REQUIRED_FOR_FULLRIG = 1;
 BOOL gAnimateTextures = TRUE;
 //extern BOOL gHideSelectedObjects;
 
+// AXON TEMP
+S32 LLVOVolume::sForceLOD = -1;
 F32 LLVOVolume::sLODFactor = 1.f;
 F32	LLVOVolume::sLODSlopDistanceFactor = 0.5f; //Changing this to zero, effectively disables the LOD transition slop 
 F32 LLVOVolume::sDistanceFactor = 1.0f;
@@ -1222,16 +1224,24 @@ void LLVOVolume::sculpt()
 S32	LLVOVolume::computeLODDetail(F32 distance, F32 radius)
 {
 	S32	cur_detail;
-	if (LLPipeline::sDynamicLOD)
-	{
-		// We've got LOD in the profile, and in the twist.  Use radius.
-		F32 tan_angle = (LLVOVolume::sLODFactor*radius)/distance;
-		cur_detail = LLVolumeLODGroup::getDetailFromTan(ll_round(tan_angle, 0.01f));
-	}
-	else
-	{
-		cur_detail = llclamp((S32) (sqrtf(radius)*LLVOVolume::sLODFactor*4.f), 0, 3);		
-	}
+    // AXON TEMP
+    if (LLVOVolume::sForceLOD>=0 && LLVOVolume::sForceLOD<=3)
+    {
+        cur_detail = LLVOVolume::sForceLOD;
+    }
+    else
+    {
+        if (LLPipeline::sDynamicLOD)
+        {
+            // We've got LOD in the profile, and in the twist.  Use radius.
+            F32 tan_angle = (LLVOVolume::sLODFactor*radius)/distance;
+            cur_detail = LLVolumeLODGroup::getDetailFromTan(ll_round(tan_angle, 0.01f));
+        }
+        else
+        {
+            cur_detail = llclamp((S32) (sqrtf(radius)*LLVOVolume::sLODFactor*4.f), 0, 3);		
+        }
+    }
 	return cur_detail;
 }
 
@@ -1291,9 +1301,8 @@ BOOL LLVOVolume::calcLOD()
 	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LOD_INFO) &&
 		mDrawable->getFace(0))
 	{
-		//setDebugText(llformat("%.2f:%.2f, %d", mDrawable->mDistanceWRTCamera, radius, cur_detail));
-
-		setDebugText(llformat("%d", mDrawable->getFace(0)->getTextureIndex()));
+        // This is a display for LODs. If you need the texture index, put it somewhere else!
+		setDebugText(llformat("lod %d", cur_detail));
 	}
 
 	if (cur_detail != mLOD)
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index 44d9c65b4bf..c972d7770e1 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -395,6 +395,7 @@ class LLVOVolume : public LLViewerObject
 public:
 	static F32 sLODSlopDistanceFactor;// Changing this to zero, effectively disables the LOD transition slop
 	static F32 sLODFactor;				// LOD scale factor
+	static S32 sForceLOD;				// LOD override
 	static F32 sDistanceFactor;			// LOD distance factor
 
 	static LLPointer<LLObjectMediaDataClient> sObjectMediaClient;
-- 
GitLab