From fb04904336b77b480f2ebd6bf9219f85c356d36f Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Mon, 12 Apr 2010 11:11:23 -0500
Subject: [PATCH] Fix for avatars not rendering in non-deferred mode.

---
 indra/newview/lldrawpoolavatar.cpp |  5 ++++-
 indra/newview/llvoavatar.cpp       | 22 +++++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp
index 9311a5f60ec..a07be305655 100644
--- a/indra/newview/lldrawpoolavatar.cpp
+++ b/indra/newview/lldrawpoolavatar.cpp
@@ -320,7 +320,7 @@ void LLDrawPoolAvatar::renderShadow(S32 pass)
 
 S32 LLDrawPoolAvatar::getNumPasses()
 {
-	return LLPipeline::sImpostorRender ? 1 : 4;
+	return LLPipeline::sImpostorRender ? 1 : 3;
 }
 
 void LLDrawPoolAvatar::render(S32 pass)
@@ -357,6 +357,7 @@ void LLDrawPoolAvatar::beginRenderPass(S32 pass)
 		break;
 	case 2:
 		beginSkinned();
+		break;
 	case 3:
 		beginRigged();
 		break;
@@ -574,12 +575,14 @@ void LLDrawPoolAvatar::endSkinned()
 
 void LLDrawPoolAvatar::beginRigged()
 {
+	sVertexProgram = NULL;
 	gSkinnedObjectSimpleProgram.bind();
 	LLVertexBuffer::sWeight4Loc = gSkinnedObjectSimpleProgram.getAttribLocation(LLViewerShaderMgr::OBJECT_WEIGHT);
 }
 
 void LLDrawPoolAvatar::endRigged()
 {
+	sVertexProgram = NULL;
 	gSkinnedObjectSimpleProgram.unbind();
 	LLVertexBuffer::sWeight4Loc = -1;
 }
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 6c2eb37971d..201c4ce1d52 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -3645,7 +3645,8 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 	
 	const U32 data_mask =	LLVertexBuffer::MAP_VERTEX | 
 							LLVertexBuffer::MAP_NORMAL | 
-							LLVertexBuffer::MAP_TEXCOORD0 | 
+							LLVertexBuffer::MAP_TEXCOORD0 |
+							LLVertexBuffer::MAP_COLOR |
 							LLVertexBuffer::MAP_WEIGHT4;
 
 	for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(); 
@@ -3669,10 +3670,16 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 						if (face->isState(LLFace::RIGGED))
 						{
 							LLVolume* volume = attached_object->getVolume();
+							if (!volume || volume->getNumVolumeFaces() <= i)
+							{
+								continue;
+							}
+
 							const LLVolumeFace& vol_face = volume->getVolumeFace(i);
 
 							const LLMeshSkinInfo* skin = NULL;
 							LLVertexBuffer* buff = face->mVertexBuffer;
+							LLUUID mesh_id = volume->getParams().getSculptID();;
 
 							if (!buff || 
 								!buff->hasDataType(LLVertexBuffer::TYPE_WEIGHT4) ||
@@ -3682,7 +3689,6 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 								face->mLastVertexBuffer = NULL;
 								buff = NULL;
 
-								LLUUID mesh_id = volume->getParams().getSculptID();
 								if (mesh_id.notNull())
 								{
 									skin = gMeshRepo.getSkinInfo(mesh_id);
@@ -3693,7 +3699,8 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 
 										face->setGeomIndex(0);
 										face->setIndicesIndex(0);
-										
+										face->setSize(vol_face.mVertices.size(), vol_face.mIndices.size());
+
 										U16 offset = 0;
 										
 										LLMatrix4 mat_vert = skin->mBindShapeMatrix;
@@ -3705,8 +3712,13 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 								}
 							}								
 							
-							if (buff)
+							if (buff && mesh_id.notNull())
 							{
+								if (!skin)
+								{
+									skin = gMeshRepo.getSkinInfo(mesh_id);
+								}
+
 								if (skin)
 								{
 									LLMatrix4 mat[64];
@@ -3729,7 +3741,7 @@ U32 LLVOAvatar::renderSkinnedAttachments()
 									buff->setBuffer(data_mask);
 
 									U16 start = face->getGeomStart();
-									U16 end = start + face->getGeomCount();
+									U16 end = start + face->getGeomCount()-1;
 									S32 offset = face->getIndicesStart();
 									U32 count = face->getIndicesCount();
 
-- 
GitLab