From b89af09f598af21b67b14e5ff940461d9c89afb8 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 4 Mar 2011 14:25:46 -0600
Subject: [PATCH] SH-998 Fix for improper LoD when an object is first rezzed.

---
 indra/newview/lldrawable.cpp                       |  9 ++++++++-
 indra/newview/llviewermenu.cpp                     |  4 ++++
 indra/newview/llvovolume.cpp                       | 11 ++++++++++-
 indra/newview/pipeline.cpp                         |  2 +-
 indra/newview/pipeline.h                           |  1 +
 indra/newview/skins/default/xui/en/menu_viewer.xml | 10 ++++++++++
 6 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp
index fe743e74516..bdc12ec0e3c 100644
--- a/indra/newview/lldrawable.cpp
+++ b/indra/newview/lldrawable.cpp
@@ -708,7 +708,14 @@ void LLDrawable::updateDistance(LLCamera& camera, bool force_update)
 		LLVOVolume* volume = getVOVolume();
 		if (volume)
 		{
-			pos.set(getPositionGroup().getF32ptr());
+			if (getSpatialGroup())
+			{
+				pos.set(getPositionGroup().getF32ptr());
+			}
+			else
+			{
+				pos = getPositionAgent();
+			}
 			
 			if (isState(LLDrawable::HAS_ALPHA))
 			{
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 37aa0802288..99c7d4b8c93 100755
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -937,6 +937,10 @@ U32 info_display_from_string(std::string info_display)
 	{
 		return LLPipeline::RENDER_DEBUG_FACE_AREA;
 	}
+	else if ("lod info" == info_display)
+	{
+		return LLPipeline::RENDER_DEBUG_LOD_INFO;
+	}
 	else if ("build queue" == info_display)
 	{
 		return LLPipeline::RENDER_DEBUG_BUILD_QUEUE;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 66263412ec5..7601b68c5f9 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -1218,7 +1218,10 @@ BOOL LLVOVolume::calcLOD()
 		distance = mDrawable->mDistanceWRTCamera;
 		radius = getVolume()->mLODScaleBias.scaledVec(getScale()).length();
 	}
-			
+	
+	//hold onto unmodified distance for debugging
+	F32 debug_distance = distance;
+	
 	distance *= sDistanceFactor;
 
 	F32 rampDist = LLVOVolume::sLODFactor * 2;
@@ -1237,6 +1240,12 @@ BOOL LLVOVolume::calcLOD()
 	cur_detail = computeLODDetail(llround(distance, 0.01f), 
 									llround(radius, 0.01f));
 
+
+	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LOD_INFO))
+	{
+		setDebugText(llformat("%.2f:%.2f, %d", debug_distance, radius, cur_detail));
+	}
+
 	if (cur_detail != mLOD)
 	{
 		mAppAngle = llround((F32) atan2( mDrawable->getRadius(), mDrawable->mDistanceWRTCamera) * RAD_TO_DEG, 0.01f);
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 9eaf515c653..ba597d62bf1 100755
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -2742,7 +2742,7 @@ void LLPipeline::stateSort(LLDrawable* drawablep, LLCamera& camera)
 
 	if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD)
 	{
-		if (drawablep->isVisible())
+		//if (drawablep->isVisible()) isVisible() check here is redundant, if it wasn't visible, it wouldn't be here
 		{
 			if (!drawablep->isActive())
 			{
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 32ac93388d9..be58af947c4 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -447,6 +447,7 @@ class LLPipeline
 		RENDER_DEBUG_UPDATE_TYPE		= 0x0800000,
 		RENDER_DEBUG_PHYSICS_SHAPES     = 0x1000000,
 		RENDER_DEBUG_NORMALS	        = 0x2000000,
+		RENDER_DEBUG_LOD_INFO	        = 0x4000000,
 	};
 
 public:
diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml
index 0a6be2899ba..38e91656136 100644
--- a/indra/newview/skins/default/xui/en/menu_viewer.xml
+++ b/indra/newview/skins/default/xui/en/menu_viewer.xml
@@ -2277,6 +2277,16 @@
            function="Advanced.ToggleInfoDisplay"
            parameter="face area" />
         </menu_item_check>
+        <menu_item_check
+         label="LOD Info"
+         name="LOD Info">
+          <menu_item_check.on_check
+           function="Advanced.CheckInfoDisplay"
+           parameter="lod info" />
+          <menu_item_check.on_click
+           function="Advanced.ToggleInfoDisplay"
+           parameter="lod info" />
+        </menu_item_check>
         <menu_item_check
          label="Build Queue"
          name="Build Queue">
-- 
GitLab