From 512c9615e513a6e4eda6dff7162b8e30619aac3e Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Wed, 14 Jul 2010 13:27:58 -0600
Subject: [PATCH] EXT-8386: FIXED: link grass rendering to the Trees Mesh
 detail slider

---
 indra/newview/llvograss.cpp | 56 +++++++++++++++++++++++++++++++++++--
 indra/newview/llvotree.cpp  |  6 ++++
 indra/newview/llvotree.h    |  1 +
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/indra/newview/llvograss.cpp b/indra/newview/llvograss.cpp
index a82afbeb76d..8a58a9c65b5 100644
--- a/indra/newview/llvograss.cpp
+++ b/indra/newview/llvograss.cpp
@@ -53,6 +53,7 @@
 #include "llworld.h"
 #include "lldir.h"
 #include "llxmltree.h"
+#include "llvotree.h"
 
 const S32 GRASS_MAX_BLADES =	32;
 const F32 GRASS_BLADE_BASE =	0.25f;			//  Width of grass at base
@@ -294,6 +295,23 @@ BOOL LLVOGrass::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 		return TRUE;
 	}
 
+	if(LLVOTree::isTreeRenderingStopped()) //stop rendering grass
+	{
+		if(mNumBlades)
+		{
+			mNumBlades = 0 ;
+			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE);
+		}
+		return TRUE ;
+	}
+	else if(!mNumBlades)//restart grass rendering
+	{
+		mNumBlades = GRASS_MAX_BLADES ;
+		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE);
+		
+		return TRUE ;
+	}
+
 	if (mPatch && (mLastPatchUpdateTime != mPatch->getLastUpdateTime()))
 	{
 		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
@@ -340,7 +358,20 @@ BOOL LLVOGrass::updateLOD()
 	{
 		return FALSE;
 	}
-	
+	if(LLVOTree::isTreeRenderingStopped())
+	{
+		if(mNumBlades)
+		{
+			mNumBlades = 0 ;
+			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE);
+		}
+		return TRUE ;
+	}
+	if(!mNumBlades)
+	{
+		mNumBlades = GRASS_MAX_BLADES;
+	}
+
 	LLFace* face = mDrawable->getFace(0);
 
 	F32 tan_angle = 0.f;
@@ -387,8 +418,24 @@ static LLFastTimer::DeclareTimer FTM_UPDATE_GRASS("Update Grass");
 BOOL LLVOGrass::updateGeometry(LLDrawable *drawable)
 {
 	LLFastTimer ftm(FTM_UPDATE_GRASS);
+
 	dirtySpatialGroup();
-	plantBlades();
+
+	if(!mNumBlades)//stop rendering grass
+	{
+		if (mDrawable->getNumFaces() > 0)
+		{
+			LLFace* facep = mDrawable->getFace(0);
+			if(facep)
+			{
+				facep->setSize(0, 0);			
+			}
+		}
+	}
+	else
+	{		
+		plantBlades();
+	}
 	return TRUE;
 }
 
@@ -429,6 +476,11 @@ void LLVOGrass::getGeometry(S32 idx,
 								LLStrider<LLColor4U>& colorsp, 
 								LLStrider<U16>& indicesp)
 {
+	if(!mNumBlades)//stop rendering grass
+	{
+		return ;
+	}
+
 	mPatch = mRegionp->getLand().resolvePatchRegion(getPositionRegion());
 	if (mPatch)
 		mLastPatchUpdateTime = mPatch->getLastUpdateTime();
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index 5431aec07c2..10537a6eb5c 100644
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -101,6 +101,12 @@ LLVOTree::~LLVOTree()
 	}
 }
 
+//static
+bool LLVOTree::isTreeRenderingStopped()
+{
+	return LLVOTree::sTreeFactor < LLVOTree::sLODAngles[sMAX_NUM_TREE_LOD_LEVELS - 1] ;
+}
+
 // static
 void LLVOTree::initClass()
 {
diff --git a/indra/newview/llvotree.h b/indra/newview/llvotree.h
index 036ad692b17..a6850e4790a 100644
--- a/indra/newview/llvotree.h
+++ b/indra/newview/llvotree.h
@@ -59,6 +59,7 @@ class LLVOTree : public LLViewerObject
 	// Initialize data that's only inited once per class.
 	static void initClass();
 	static void cleanupClass();
+	static bool isTreeRenderingStopped();
 
 	/*virtual*/ U32 processUpdateMessage(LLMessageSystem *mesgsys,
 											void **user_data,
-- 
GitLab