From ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Thu, 30 Apr 2009 13:04:20 -0500
Subject: Second Life viewer sources 1.23.0-RC

---
 linden/indra/newview/llface.cpp | 191 +++++++++++++++++++++++-----------------
 1 file changed, 111 insertions(+), 80 deletions(-)

(limited to 'linden/indra/newview/llface.cpp')

diff --git a/linden/indra/newview/llface.cpp b/linden/indra/newview/llface.cpp
index 5095f38..3dfe6a2 100644
--- a/linden/indra/newview/llface.cpp
+++ b/linden/indra/newview/llface.cpp
@@ -17,7 +17,8 @@
  * There are special exceptions to the terms and conditions of the GPL as
  * it is applied to this Source Code. View the full text of the exception
  * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  * 
  * By copying, modifying or distributing this software, you acknowledge
  * that you have read and understood your obligations described above,
@@ -164,6 +165,7 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
 	mReferenceIndex = -1;
 
 	mTextureMatrix = NULL;
+	mDrawInfo = NULL;
 
 	mFaceColor = LLColor4(1,0,0,1);
 
@@ -177,9 +179,6 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
 
 void LLFace::destroy()
 {
-	mDrawablep = NULL;
-	mVObjp = NULL;
-
 	if (mDrawPoolp)
 	{
 		mDrawPoolp->removeFace(this);
@@ -190,7 +189,21 @@ void LLFace::destroy()
 	{
 		delete mTextureMatrix;
 		mTextureMatrix = NULL;
+
+		if (mDrawablep.notNull())
+		{
+			LLSpatialGroup* group = mDrawablep->getSpatialGroup();
+			if (group)
+			{
+				group->dirtyGeom();
+			}
+		}
 	}
+
+	setDrawInfo(NULL);
+	
+	mDrawablep = NULL;
+	mVObjp = NULL;
 }
 
 
@@ -288,7 +301,7 @@ U16 LLFace::getGeometryAvatar(
 	{
 		mVertexBuffer->getVertexStrider      (vertices, mGeomIndex);
 		mVertexBuffer->getNormalStrider      (normals, mGeomIndex);
-		mVertexBuffer->getTexCoordStrider    (tex_coords, mGeomIndex);
+		mVertexBuffer->getTexCoord0Strider    (tex_coords, mGeomIndex);
 		mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex);
 		mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex);
 	}
@@ -308,9 +321,9 @@ U16 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &no
 		{
 			mVertexBuffer->getNormalStrider(normals,    mGeomIndex);
 		}
-		if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD))
+		if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD0))
 		{
-			mVertexBuffer->getTexCoordStrider(tex_coords, mGeomIndex);
+			mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex);
 		}
 
 		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
@@ -434,12 +447,13 @@ void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color)
 		setFaceColor(color);
 		renderSetColor();
 
-		mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD);
+		mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0);
 #if !LL_RELEASE_FOR_DOWNLOAD
-		LLGLState::checkClientArrays("", LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD);
+		LLGLState::checkClientArrays("", LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0);
 #endif
 		mVertexBuffer->draw(LLRender::TRIANGLES, mIndicesCount, mIndicesIndex);
-				
+
+		unsetFaceColor();
 		unsetFaceColor();
 		gGL.popMatrix();
 	}
@@ -476,9 +490,27 @@ void LLFace::renderSelectedUV()
 	glMatrixMode(GL_MODELVIEW);
 	gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
 }
-
 */
 
+void LLFace::setDrawInfo(LLDrawInfo* draw_info)
+{
+	if (draw_info)
+	{
+		if (draw_info->mFace)
+		{
+			draw_info->mFace->setDrawInfo(NULL);
+		}
+		draw_info->mFace = this;
+	}
+	
+	if (mDrawInfo)
+	{
+		mDrawInfo->mFace = NULL;
+	}
+
+	mDrawInfo = draw_info;
+}
+
 void LLFace::printDebugInfo() const
 {
 	LLFacePool *poolp = getPool();
@@ -586,11 +618,11 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
 	//get bounding box
 	if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION))
 	{
-		if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
-		{ //vertex buffer no longer valid
-			mVertexBuffer = NULL;
-			mLastVertexBuffer = NULL;
-		}
+		//if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
+		//{ //vertex buffer no longer valid
+		//	mVertexBuffer = NULL;
+		//	mLastVertexBuffer = NULL;
+		//}
 
 		LLVector3 min,max;
 	
@@ -738,6 +770,34 @@ LLVector2 LLFace::surfaceToTexture(LLVector2 surface_coord, LLVector3 position,
 	return tc;
 }
 
+void LLFace::updateRebuildFlags()
+{
+	if (!mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
+	{
+		BOOL moved = TRUE;
+		if (mLastVertexBuffer == mVertexBuffer && 
+			!mVertexBuffer->isEmpty())
+		{	//this face really doesn't need to be regenerated, try real hard not to do so
+			if (mLastGeomCount == mGeomCount &&
+				mLastGeomIndex == mGeomIndex &&
+				mLastIndicesCount == mIndicesCount &&
+				mLastIndicesIndex == mIndicesIndex)
+			{ //data is in same location in vertex buffer
+				moved = FALSE;
+			}
+		}
+		mLastMoveTime = gFrameTimeSeconds;
+		
+		if (moved)
+		{
+			mDrawablep->setState(LLDrawable::REBUILD_VOLUME);
+		}
+	}
+	else
+	{
+		mLastUpdateTime = gFrameTimeSeconds;
+	}
+}
 
 BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 							   const S32 &f,
@@ -763,16 +823,16 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 		}
 	}
 
-	LLStrider<LLVector3> old_verts,vertices;
-	LLStrider<LLVector2> old_texcoords,tex_coords;
-	LLStrider<LLVector2> old_texcoords2,tex_coords2;
-	LLStrider<LLVector3> old_normals,normals;
-	LLStrider<LLColor4U> old_colors,colors;
+	LLStrider<LLVector3> vertices;
+	LLStrider<LLVector2> tex_coords;
+	LLStrider<LLVector2> tex_coords2;
+	LLStrider<LLVector3> normals;
+	LLStrider<LLColor4U> colors;
+	LLStrider<LLVector3> binormals;
 	LLStrider<U16> indicesp;
 
 	BOOL full_rebuild = mDrawablep->isState(LLDrawable::REBUILD_VOLUME);
-	BOOL moved = TRUE;
-
+	
 	BOOL global_volume = mDrawablep->getVOVolume()->isVolumeGlobal();
 	LLVector3 scale;
 	if (global_volume)
@@ -783,35 +843,12 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 	{
 		scale = mVObjp->getScale();
 	}
-
-	if (!full_rebuild)
-	{   
-		if (mLastVertexBuffer == mVertexBuffer && 
-			!mVertexBuffer->isEmpty())
-		{	//this face really doesn't need to be regenerated, try real hard not to do so
-			if (mLastGeomCount == mGeomCount &&
-				mLastGeomIndex == mGeomIndex &&
-				mLastIndicesCount == mIndicesCount &&
-				mLastIndicesIndex == mIndicesIndex)
-			{ //data is in same location in vertex buffer
-				moved = FALSE;
-			}
-			
-			if (!moved && !mDrawablep->isState(LLDrawable::REBUILD_ALL))
-			{ //nothing needs to be done
-				return FALSE;
-			}
-		}
-		mLastMoveTime = gFrameTimeSeconds;
-	}
-	else
-	{
-		mLastUpdateTime = gFrameTimeSeconds;
-	}
 	
-	BOOL rebuild_pos = full_rebuild || moved || mDrawablep->isState(LLDrawable::REBUILD_POSITION);
-	BOOL rebuild_color = full_rebuild || moved || mDrawablep->isState(LLDrawable::REBUILD_COLOR);
-	BOOL rebuild_tcoord = full_rebuild || moved || mDrawablep->isState(LLDrawable::REBUILD_TCOORD);
+	BOOL rebuild_pos = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_POSITION);
+	BOOL rebuild_color = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_COLOR);
+	BOOL rebuild_tcoord = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_TCOORD);
+	BOOL rebuild_normal = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL);
+	BOOL rebuild_binormal = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_BINORMAL);
 
 	const LLTextureEntry *tep = mVObjp->getTE(f);
 	U8  bump_code = tep ? tep->getBumpmap() : 0;
@@ -819,14 +856,21 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 	if (rebuild_pos)
 	{
 		mVertexBuffer->getVertexStrider(vertices, mGeomIndex);
+	}
+	if (rebuild_normal)
+	{
 		mVertexBuffer->getNormalStrider(normals, mGeomIndex);
 	}
+	if (rebuild_binormal)
+	{
+		mVertexBuffer->getBinormalStrider(binormals, mGeomIndex);
+	}
 	if (rebuild_tcoord)
 	{
-		mVertexBuffer->getTexCoordStrider(tex_coords, mGeomIndex);
-		if (bump_code)
+		mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex);
+		if (bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1))
 		{
-			mVertexBuffer->getTexCoord2Strider(tex_coords2, mGeomIndex);
+			mVertexBuffer->getTexCoord1Strider(tex_coords2, mGeomIndex);
 		}
 	}
 	if (rebuild_color)
@@ -888,12 +932,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 		{
 			clearState(TEXTURE_ANIM);
 		}
-		//else if (getVirtualSize() <= 512.f)
-		//{			
-		//	//vobj->mTextureAnimp->animateTextures(os, ot, ms, mt, r);
-		//	//cos_ang = cos(r);
-		//	//sin_ang = sin(r);
-		//}
 		else
 		{
 			os = ot = 0.f;
@@ -921,14 +959,14 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 			0.75f
 		};
 
-		if (getPoolType() != LLDrawPool::POOL_ALPHA && LLPipeline::sRenderBump && tep->getShiny())
+		if (getPoolType() != LLDrawPool::POOL_ALPHA && (LLPipeline::sRenderDeferred || LLPipeline::sRenderBump && tep->getShiny()))
 		{
 			color.mV[3] = U8 (alpha[tep->getShiny()] * 255);
 		}
 	}
 
     // INDICES
-	if (full_rebuild || moved)
+	if (full_rebuild)
 	{
 		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
 		for (U16 i = 0; i < num_indices; i++)
@@ -1045,7 +1083,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 
 			*tex_coords++ = tc;
 		
-			if (bump_code)
+			if (bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1))
 			{
 				LLVector3 tangent = vf.mVertices[i].mBinormal % vf.mVertices[i].mNormal;
 
@@ -1065,38 +1103,31 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 				*tex_coords2++ = tc;
 			}	
 		}
-		else if (moved)
-		{
-			*tex_coords++ = *old_texcoords++;
-			if (bump_code)
-			{
-				*tex_coords2++ = *old_texcoords2++;
-			}
-		}
 			
 		if (rebuild_pos)
 		{
 			*vertices++ = vf.mVertices[i].mPosition * mat_vert;
-
+		}
+		
+		if (rebuild_normal)
+		{
 			LLVector3 normal = vf.mVertices[i].mNormal * mat_normal;
 			normal.normVec();
 			
 			*normals++ = normal;
 		}
-		else if (moved)
+		
+		if (rebuild_binormal)
 		{
-			*normals++ = *old_normals++;
-			*vertices++ = *old_verts++;
+			LLVector3 binormal = vf.mVertices[i].mBinormal * mat_normal;
+			binormal.normVec();
+			*binormals++ = binormal;
 		}
-
+		
 		if (rebuild_color)
 		{
 			*colors++ = color;		
 		}
-		else if (moved)
-		{
-			*colors++ = *old_colors++;
-		}
 	}
 
 	if (rebuild_tcoord)
-- 
cgit v1.1