aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvoavatar.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-06-08 00:41:31 -0500
committerJacek Antonelli2009-06-08 00:41:31 -0500
commit0e5df9bdf8d6b418bb6e25615e2ffc922d0f02aa (patch)
tree2c93d38e210832e737d09cff7561373d8d5453b2 /linden/indra/newview/llvoavatar.cpp
parentImprudence 1.1.0 released. (diff)
parentUpdated Imprudence to be based on SL 1.22.11. (ChangeLog Entry) (diff)
downloadmeta-impy-0e5df9bdf8d6b418bb6e25615e2ffc922d0f02aa.zip
meta-impy-0e5df9bdf8d6b418bb6e25615e2ffc922d0f02aa.tar.gz
meta-impy-0e5df9bdf8d6b418bb6e25615e2ffc922d0f02aa.tar.bz2
meta-impy-0e5df9bdf8d6b418bb6e25615e2ffc922d0f02aa.tar.xz
Merge branch 'sl-base-1.22' into next
Conflicts: linden/indra/newview/English.lproj/InfoPlist.strings linden/indra/newview/skins/default/xui/en-us/panel_chat_bar.xml
Diffstat (limited to 'linden/indra/newview/llvoavatar.cpp')
-rw-r--r--linden/indra/newview/llvoavatar.cpp284
1 files changed, 213 insertions, 71 deletions
diff --git a/linden/indra/newview/llvoavatar.cpp b/linden/indra/newview/llvoavatar.cpp
index 7d70dd2..3d2523e 100644
--- a/linden/indra/newview/llvoavatar.cpp
+++ b/linden/indra/newview/llvoavatar.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$ 5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2001-2008, Linden Research, Inc. 7 * Copyright (c) 2001-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -244,6 +244,11 @@ static F32 calc_bouncy_animation(F32 x)
244 return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO))*(0.4f + x * -0.1f) + x * 1.3f; 244 return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO))*(0.4f + x * -0.1f) + x * 1.3f;
245} 245}
246 246
247BOOL LLLineSegmentCapsuleIntersect(const LLVector3& start, const LLVector3& end, const LLVector3& p1, const LLVector3& p2, const F32& radius, LLVector3& result)
248{
249 return FALSE;
250}
251
247//----------------------------------------------------------------------------- 252//-----------------------------------------------------------------------------
248// Static Data 253// Static Data
249//----------------------------------------------------------------------------- 254//-----------------------------------------------------------------------------
@@ -267,6 +272,7 @@ LLUUID LLVOAvatar::sStepSounds[LL_MCODE_END] =
267 LLUUID(SND_RUBBER_RUBBER) 272 LLUUID(SND_RUBBER_RUBBER)
268}; 273};
269 274
275// static
270S32 LLVOAvatar::sRenderName = RENDER_NAME_ALWAYS; 276S32 LLVOAvatar::sRenderName = RENDER_NAME_ALWAYS;
271BOOL LLVOAvatar::sRenderGroupTitles = TRUE; 277BOOL LLVOAvatar::sRenderGroupTitles = TRUE;
272S32 LLVOAvatar::sNumVisibleChatBubbles = 0; 278S32 LLVOAvatar::sNumVisibleChatBubbles = 0;
@@ -279,9 +285,12 @@ BOOL LLVOAvatar::sVisibleInFirstPerson = FALSE;
279F32 LLVOAvatar::sLODFactor = 1.f; 285F32 LLVOAvatar::sLODFactor = 1.f;
280BOOL LLVOAvatar::sUseImpostors = FALSE; 286BOOL LLVOAvatar::sUseImpostors = FALSE;
281BOOL LLVOAvatar::sJointDebug = FALSE; 287BOOL LLVOAvatar::sJointDebug = FALSE;
282
283S32 LLVOAvatar::sCurJoint = 0; 288S32 LLVOAvatar::sCurJoint = 0;
284S32 LLVOAvatar::sCurVolume = 0; 289S32 LLVOAvatar::sCurVolume = 0;
290F32 LLVOAvatar::sUnbakedTime = 0.f;
291F32 LLVOAvatar::sUnbakedUpdateTime = 0.f;
292F32 LLVOAvatar::sGreyTime = 0.f;
293F32 LLVOAvatar::sGreyUpdateTime = 0.f;
285 294
286struct LLAvatarTexData 295struct LLAvatarTexData
287{ 296{
@@ -753,7 +762,7 @@ LLVOAvatar::LLVOAvatar(
753 mRippleTimeLast = 0.f; 762 mRippleTimeLast = 0.f;
754 763
755 mShadowImagep = gImageList.getImageFromFile("foot_shadow.j2c"); 764 mShadowImagep = gImageList.getImageFromFile("foot_shadow.j2c");
756 mShadowImagep->bind(); 765 gGL.getTexUnit(0)->bind(mShadowImagep.get());
757 mShadowImagep->setClamp(TRUE, TRUE); 766 mShadowImagep->setClamp(TRUE, TRUE);
758 767
759 mInAir = FALSE; 768 mInAir = FALSE;
@@ -1062,11 +1071,29 @@ void LLVOAvatar::deleteLayerSetCaches()
1062 if( mLowerBodyLayerSet ) mLowerBodyLayerSet->deleteCaches(); 1071 if( mLowerBodyLayerSet ) mLowerBodyLayerSet->deleteCaches();
1063 if( mEyesLayerSet ) mEyesLayerSet->deleteCaches(); 1072 if( mEyesLayerSet ) mEyesLayerSet->deleteCaches();
1064 if( mSkirtLayerSet ) mSkirtLayerSet->deleteCaches(); 1073 if( mSkirtLayerSet ) mSkirtLayerSet->deleteCaches();
1074
1075 if(mUpperMaskTexName)
1076 {
1077 glDeleteTextures(1, (GLuint*)&mUpperMaskTexName);
1078 mUpperMaskTexName = 0 ;
1079 }
1080 if(mHeadMaskTexName)
1081 {
1082 glDeleteTextures(1, (GLuint*)&mHeadMaskTexName);
1083 mHeadMaskTexName = 0 ;
1084 }
1085 if(mLowerMaskTexName)
1086 {
1087 glDeleteTextures(1, (GLuint*)&mLowerMaskTexName);
1088 mLowerMaskTexName = 0 ;
1089 }
1065} 1090}
1066 1091
1067// static 1092// static
1068BOOL LLVOAvatar::areAllNearbyInstancesBaked() 1093BOOL LLVOAvatar::areAllNearbyInstancesBaked(S32& grey_avatars)
1069{ 1094{
1095 BOOL res = TRUE;
1096 grey_avatars = 0;
1070 for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin(); 1097 for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
1071 iter != LLCharacter::sInstances.end(); ++iter) 1098 iter != LLCharacter::sInstances.end(); ++iter)
1072 { 1099 {
@@ -1075,18 +1102,22 @@ BOOL LLVOAvatar::areAllNearbyInstancesBaked()
1075 { 1102 {
1076 continue; 1103 continue;
1077 } 1104 }
1078 else 1105// else
1079 if( inst->getPixelArea() < MIN_PIXEL_AREA_FOR_COMPOSITE ) 1106// if( inst->getPixelArea() < MIN_PIXEL_AREA_FOR_COMPOSITE )
1080 { 1107// {
1081 return TRUE; // Assumes sInstances is sorted by pixel area. 1108// return res; // Assumes sInstances is sorted by pixel area.
1082 } 1109// }
1083 else 1110 else
1084 if( !inst->isFullyBaked() ) 1111 if( !inst->isFullyBaked() )
1085 { 1112 {
1086 return FALSE; 1113 res = FALSE;
1114 if (inst->mHasGrey)
1115 {
1116 ++grey_avatars;
1117 }
1087 } 1118 }
1088 } 1119 }
1089 return TRUE; 1120 return res;
1090} 1121}
1091 1122
1092// static 1123// static
@@ -1131,7 +1162,7 @@ void LLVOAvatar::dumpBakedStatus()
1131 } 1162 }
1132 1163
1133 1164
1134 F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).magVec(); 1165 F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).length();
1135 llcont << " " << dist_to_camera << "m "; 1166 llcont << " " << dist_to_camera << "m ";
1136 1167
1137 llcont << " " << inst->mPixelArea << " pixels"; 1168 llcont << " " << inst->mPixelArea << " pixels";
@@ -1569,6 +1600,96 @@ void LLVOAvatar::getSpatialExtents(LLVector3& newMin, LLVector3& newMax)
1569 newMax += buffer; 1600 newMax += buffer;
1570} 1601}
1571 1602
1603//-----------------------------------------------------------------------------
1604// renderCollisionVolumes()
1605//-----------------------------------------------------------------------------
1606void LLVOAvatar::renderCollisionVolumes()
1607{
1608 for (S32 i = 0; i < mNumCollisionVolumes; i++)
1609 {
1610 mCollisionVolumes[i].renderCollision();
1611 }
1612
1613 if (mNameText.notNull())
1614 {
1615 LLVector3 unused;
1616 mNameText->lineSegmentIntersect(LLVector3(0,0,0), LLVector3(0,0,1), unused, TRUE);
1617 }
1618}
1619
1620BOOL LLVOAvatar::lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
1621 S32 face,
1622 BOOL pick_transparent,
1623 S32* face_hit,
1624 LLVector3* intersection,
1625 LLVector2* tex_coord,
1626 LLVector3* normal,
1627 LLVector3* bi_normal
1628 )
1629{
1630
1631 if (mIsSelf && !gAgent.needsRenderAvatar() || !LLPipeline::sPickAvatar)
1632 {
1633 return FALSE;
1634 }
1635
1636 if (lineSegmentBoundingBox(start, end))
1637 {
1638 for (S32 i = 0; i < mNumCollisionVolumes; ++i)
1639 {
1640 mCollisionVolumes[i].updateWorldMatrix();
1641
1642 glh::matrix4f mat((F32*) mCollisionVolumes[i].getXform()->getWorldMatrix().mMatrix);
1643 glh::matrix4f inverse = mat.inverse();
1644 glh::matrix4f norm_mat = inverse.transpose();
1645
1646 glh::vec3f p1(start.mV);
1647 glh::vec3f p2(end.mV);
1648
1649 inverse.mult_matrix_vec(p1);
1650 inverse.mult_matrix_vec(p2);
1651
1652 LLVector3 position;
1653 LLVector3 norm;
1654
1655 if (linesegment_sphere(LLVector3(p1.v), LLVector3(p2.v), LLVector3(0,0,0), 1.f, position, norm))
1656 {
1657 glh::vec3f res_pos(position.mV);
1658 mat.mult_matrix_vec(res_pos);
1659
1660 norm.normalize();
1661 glh::vec3f res_norm(norm.mV);
1662 norm_mat.mult_matrix_dir(res_norm);
1663
1664 if (intersection)
1665 {
1666 *intersection = LLVector3(res_pos.v);
1667 }
1668
1669 if (normal)
1670 {
1671 *normal = LLVector3(res_norm.v);
1672 }
1673
1674 return TRUE;
1675 }
1676 }
1677 }
1678
1679 LLVector3 position;
1680 if (mNameText.notNull() && mNameText->lineSegmentIntersect(start, end, position))
1681 {
1682 if (intersection)
1683 {
1684 *intersection = position;
1685 }
1686
1687 return TRUE;
1688 }
1689
1690 return FALSE;
1691}
1692
1572 1693
1573//----------------------------------------------------------------------------- 1694//-----------------------------------------------------------------------------
1574// parseSkeletonFile() 1695// parseSkeletonFile()
@@ -2737,8 +2858,8 @@ void LLVOAvatar::idleUpdateMisc(bool detailed_update)
2737 else 2858 else
2738 { 2859 {
2739 getSpatialExtents(ext[0], ext[1]); 2860 getSpatialExtents(ext[0], ext[1]);
2740 if ((ext[1]-mImpostorExtents[1]).magVec() > 0.05f || 2861 if ((ext[1]-mImpostorExtents[1]).length() > 0.05f ||
2741 (ext[0]-mImpostorExtents[0]).magVec() > 0.05f) 2862 (ext[0]-mImpostorExtents[0]).length() > 0.05f)
2742 { 2863 {
2743 mNeedsImpostorUpdate = TRUE; 2864 mNeedsImpostorUpdate = TRUE;
2744 } 2865 }
@@ -2905,7 +3026,7 @@ void LLVOAvatar::idleUpdateWindEffect()
2905 F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast; 3026 F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
2906 mRippleTimeLast = mRippleTimer.getElapsedTimeF32(); 3027 mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
2907 LLVector3 velocity = getVelocity(); 3028 LLVector3 velocity = getVelocity();
2908 F32 speed = velocity.magVec(); 3029 F32 speed = velocity.length();
2909 //RN: velocity varies too much frame to frame for this to work 3030 //RN: velocity varies too much frame to frame for this to work
2910 mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLCriticalDamp::getInterpolant(0.02f)); 3031 mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLCriticalDamp::getInterpolant(0.02f));
2911 mLastVel = velocity; 3032 mLastVel = velocity;
@@ -2924,7 +3045,7 @@ void LLVOAvatar::idleUpdateWindEffect()
2924 } 3045 }
2925 3046
2926 wind.mV[VZ] += hover_strength; 3047 wind.mV[VZ] += hover_strength;
2927 wind.normVec(); 3048 wind.normalize();
2928 3049
2929 wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f); 3050 wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f);
2930 F32 interp; 3051 F32 interp;
@@ -3047,10 +3168,10 @@ void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
3047 LLVector3 pixel_up_vec; 3168 LLVector3 pixel_up_vec;
3048 LLViewerCamera::getInstance()->getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec); 3169 LLViewerCamera::getInstance()->getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec);
3049 LLVector3 camera_to_av = root_pos_last - LLViewerCamera::getInstance()->getOrigin(); 3170 LLVector3 camera_to_av = root_pos_last - LLViewerCamera::getInstance()->getOrigin();
3050 camera_to_av.normVec(); 3171 camera_to_av.normalize();
3051 LLVector3 local_camera_at = camera_to_av * ~root_rot; 3172 LLVector3 local_camera_at = camera_to_av * ~root_rot;
3052 LLVector3 local_camera_up = camera_to_av % LLViewerCamera::getInstance()->getLeftAxis(); 3173 LLVector3 local_camera_up = camera_to_av % LLViewerCamera::getInstance()->getLeftAxis();
3053 local_camera_up.normVec(); 3174 local_camera_up.normalize();
3054 local_camera_up = local_camera_up * ~root_rot; 3175 local_camera_up = local_camera_up * ~root_rot;
3055 3176
3056 local_camera_up.scaleVec(mBodySize * 0.5f); 3177 local_camera_up.scaleVec(mBodySize * 0.5f);
@@ -3502,7 +3623,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
3502 3623
3503 LLVector3 xyVel = getVelocity(); 3624 LLVector3 xyVel = getVelocity();
3504 xyVel.mV[VZ] = 0.0f; 3625 xyVel.mV[VZ] = 0.0f;
3505 speed = xyVel.magVec(); 3626 speed = xyVel.length();
3506 3627
3507 BOOL throttle = TRUE; 3628 BOOL throttle = TRUE;
3508 3629
@@ -3587,14 +3708,14 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
3587 if (mIsSelf) 3708 if (mIsSelf)
3588 { 3709 {
3589 primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector()); 3710 primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector());
3590 primDir.normVec(); 3711 primDir.normalize();
3591 } 3712 }
3592 else 3713 else
3593 { 3714 {
3594 primDir = getRotation().getMatrix3().getFwdRow(); 3715 primDir = getRotation().getMatrix3().getFwdRow();
3595 } 3716 }
3596 LLVector3 velDir = getVelocity(); 3717 LLVector3 velDir = getVelocity();
3597 velDir.normVec(); 3718 velDir.normalize();
3598 if ( mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end()) 3719 if ( mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end())
3599 { 3720 {
3600 F32 vpD = velDir * primDir; 3721 F32 vpD = velDir * primDir;
@@ -3616,13 +3737,13 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
3616 LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis(); 3737 LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
3617 LLVector3 up_vector = gAgent.getReferenceUpVector(); 3738 LLVector3 up_vector = gAgent.getReferenceUpVector();
3618 at_axis -= up_vector * (at_axis * up_vector); 3739 at_axis -= up_vector * (at_axis * up_vector);
3619 at_axis.normVec(); 3740 at_axis.normalize();
3620 3741
3621 F32 dot = fwdDir * at_axis; 3742 F32 dot = fwdDir * at_axis;
3622 if (dot < 0.f) 3743 if (dot < 0.f)
3623 { 3744 {
3624 fwdDir -= 2.f * at_axis * dot; 3745 fwdDir -= 2.f * at_axis * dot;
3625 fwdDir.normVec(); 3746 fwdDir.normalize();
3626 } 3747 }
3627 } 3748 }
3628 3749
@@ -3690,7 +3811,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
3690 3811
3691 // Now compute the full world space rotation for the whole body (wQv) 3812 // Now compute the full world space rotation for the whole body (wQv)
3692 LLVector3 leftDir = upDir % fwdDir; 3813 LLVector3 leftDir = upDir % fwdDir;
3693 leftDir.normVec(); 3814 leftDir.normalize();
3694 fwdDir = leftDir % upDir; 3815 fwdDir = leftDir % upDir;
3695 LLQuaternion wQv( fwdDir, leftDir, upDir ); 3816 LLQuaternion wQv( fwdDir, leftDir, upDir );
3696 3817
@@ -4131,7 +4252,7 @@ U32 LLVOAvatar::renderSkinned(EAvatarRenderPass pass)
4131 LLVector3 collide_point = slaved_pos; 4252 LLVector3 collide_point = slaved_pos;
4132 collide_point.mV[VZ] -= foot_plane_normal.mV[VZ] * (dist_from_plane + COLLISION_TOLERANCE - FOOT_COLLIDE_FUDGE); 4253 collide_point.mV[VZ] -= foot_plane_normal.mV[VZ] * (dist_from_plane + COLLISION_TOLERANCE - FOOT_COLLIDE_FUDGE);
4133 4254
4134 gGL.begin(LLVertexBuffer::LINES); 4255 gGL.begin(LLRender::LINES);
4135 { 4256 {
4136 F32 SQUARE_SIZE = 0.2f; 4257 F32 SQUARE_SIZE = 0.2f;
4137 gGL.color4f(1.f, 0.f, 0.f, 1.f); 4258 gGL.color4f(1.f, 0.f, 0.f, 1.f);
@@ -4278,7 +4399,7 @@ U32 LLVOAvatar::renderFootShadows()
4278 LLGLDepthTest test(GL_TRUE, GL_FALSE); 4399 LLGLDepthTest test(GL_TRUE, GL_FALSE);
4279 //render foot shadows 4400 //render foot shadows
4280 LLGLEnable blend(GL_BLEND); 4401 LLGLEnable blend(GL_BLEND);
4281 mShadowImagep->bind(); 4402 gGL.getTexUnit(0)->bind(mShadowImagep.get());
4282 glColor4fv(mShadow0Facep->getRenderColor().mV); 4403 glColor4fv(mShadow0Facep->getRenderColor().mV);
4283 mShadow0Facep->renderIndexed(foot_mask); 4404 mShadow0Facep->renderIndexed(foot_mask);
4284 glColor4fv(mShadow1Facep->getRenderColor().mV); 4405 glColor4fv(mShadow1Facep->getRenderColor().mV);
@@ -4296,7 +4417,7 @@ U32 LLVOAvatar::renderImpostor(LLColor4U color)
4296 4417
4297 LLVector3 pos(getRenderPosition()+mImpostorOffset); 4418 LLVector3 pos(getRenderPosition()+mImpostorOffset);
4298 LLVector3 at = (pos - LLViewerCamera::getInstance()->getOrigin()); 4419 LLVector3 at = (pos - LLViewerCamera::getInstance()->getOrigin());
4299 at.normVec(); 4420 at.normalize();
4300 LLVector3 left = LLViewerCamera::getInstance()->getUpAxis() % at; 4421 LLVector3 left = LLViewerCamera::getInstance()->getUpAxis() % at;
4301 LLVector3 up = at%left; 4422 LLVector3 up = at%left;
4302 4423
@@ -4324,8 +4445,8 @@ U32 LLVOAvatar::renderImpostor(LLColor4U color)
4324 color.mV[3] = (U8) (alpha*255); 4445 color.mV[3] = (U8) (alpha*255);
4325 4446
4326 gGL.color4ubv(color.mV); 4447 gGL.color4ubv(color.mV);
4327 mImpostor.bindTexture(); 4448 gGL.getTexUnit(0)->bind(&mImpostor);
4328 gGL.begin(LLVertexBuffer::QUADS); 4449 gGL.begin(LLRender::QUADS);
4329 gGL.texCoord2f(0,0); 4450 gGL.texCoord2f(0,0);
4330 gGL.vertex3fv((pos+left-up).mV); 4451 gGL.vertex3fv((pos+left-up).mV);
4331 gGL.texCoord2f(1,0); 4452 gGL.texCoord2f(1,0);
@@ -4340,17 +4461,6 @@ U32 LLVOAvatar::renderImpostor(LLColor4U color)
4340 return 6; 4461 return 6;
4341} 4462}
4342 4463
4343//-----------------------------------------------------------------------------
4344// renderCollisionVolumes()
4345//-----------------------------------------------------------------------------
4346void LLVOAvatar::renderCollisionVolumes()
4347{
4348 for (S32 i = 0; i < mNumCollisionVolumes; i++)
4349 {
4350 mCollisionVolumes[i].renderCollision();
4351 }
4352}
4353
4354//------------------------------------------------------------------------ 4464//------------------------------------------------------------------------
4355// LLVOAvatar::updateTextures() 4465// LLVOAvatar::updateTextures()
4356//------------------------------------------------------------------------ 4466//------------------------------------------------------------------------
@@ -4385,23 +4495,23 @@ void LLVOAvatar::updateTextures(LLAgent &agent)
4385 { 4495 {
4386 if( head_baked && ! mHeadBakedLoaded ) 4496 if( head_baked && ! mHeadBakedLoaded )
4387 { 4497 {
4388 getTEImage( TEX_HEAD_BAKED )->bind(); 4498 gGL.getTexUnit(0)->bind(getTEImage( TEX_HEAD_BAKED ));
4389 } 4499 }
4390 if( upper_baked && ! mUpperBakedLoaded ) 4500 if( upper_baked && ! mUpperBakedLoaded )
4391 { 4501 {
4392 getTEImage( TEX_UPPER_BAKED )->bind(); 4502 gGL.getTexUnit(0)->bind(getTEImage( TEX_UPPER_BAKED ));
4393 } 4503 }
4394 if( lower_baked && ! mLowerBakedLoaded ) 4504 if( lower_baked && ! mLowerBakedLoaded )
4395 { 4505 {
4396 getTEImage( TEX_LOWER_BAKED )->bind(); 4506 gGL.getTexUnit(0)->bind(getTEImage( TEX_LOWER_BAKED ));
4397 } 4507 }
4398 if( eyes_baked && ! mEyesBakedLoaded ) 4508 if( eyes_baked && ! mEyesBakedLoaded )
4399 { 4509 {
4400 getTEImage( TEX_EYES_BAKED )->bind(); 4510 gGL.getTexUnit(0)->bind(getTEImage( TEX_EYES_BAKED ));
4401 } 4511 }
4402 if( skirt_baked && ! mSkirtBakedLoaded ) 4512 if( skirt_baked && ! mSkirtBakedLoaded )
4403 { 4513 {
4404 getTEImage( TEX_SKIRT_BAKED )->bind(); 4514 gGL.getTexUnit(0)->bind(getTEImage( TEX_SKIRT_BAKED ));
4405 } 4515 }
4406 } 4516 }
4407 4517
@@ -4432,6 +4542,7 @@ void LLVOAvatar::updateTextures(LLAgent &agent)
4432 4542
4433 mMaxPixelArea = 0.f; 4543 mMaxPixelArea = 0.f;
4434 mMinPixelArea = 99999999.f; 4544 mMinPixelArea = 99999999.f;
4545 mHasGrey = FALSE; // debug
4435 for (U32 i = 0; i < getNumTEs(); i++) 4546 for (U32 i = 0; i < getNumTEs(); i++)
4436 { 4547 {
4437 LLViewerImage *imagep = getTEImage(i); 4548 LLViewerImage *imagep = getTEImage(i);
@@ -4590,22 +4701,35 @@ void LLVOAvatar::updateTextures(LLAgent &agent)
4590void LLVOAvatar::addLocalTextureStats( LLVOAvatar::ELocTexIndex idx, LLViewerImage* imagep, 4701void LLVOAvatar::addLocalTextureStats( LLVOAvatar::ELocTexIndex idx, LLViewerImage* imagep,
4591 F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked ) 4702 F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked )
4592{ 4703{
4593 if (!covered_by_baked && 4704 if (!covered_by_baked && render_avatar) // render_avatar is always true if mIsSelf
4594 render_avatar && // always true if mIsSelf 4705 {
4595 mLocalTexture[ idx ].notNull() && mLocalTexture[idx]->getID() != IMG_DEFAULT_AVATAR) 4706 if (mLocalTexture[ idx ].notNull() && mLocalTexture[idx]->getID() != IMG_DEFAULT_AVATAR)
4596 {
4597 F32 desired_pixels;
4598 if( mIsSelf )
4599 { 4707 {
4600 desired_pixels = llmin(mPixelArea, (F32)LOCTEX_IMAGE_AREA_SELF ); 4708 F32 desired_pixels;
4601 imagep->setBoostLevel(LLViewerImage::BOOST_AVATAR_SELF); 4709 if( mIsSelf )
4710 {
4711 desired_pixels = llmin(mPixelArea, (F32)LOCTEX_IMAGE_AREA_SELF );
4712 imagep->setBoostLevel(LLViewerImage::BOOST_AVATAR_SELF);
4713 }
4714 else
4715 {
4716 desired_pixels = llmin(mPixelArea, (F32)LOCTEX_IMAGE_AREA_OTHER );
4717 imagep->setBoostLevel(LLViewerImage::BOOST_AVATAR);
4718 }
4719 imagep->addTextureStats( desired_pixels / texel_area_ratio );
4720 if (imagep->getDiscardLevel() < 0)
4721 {
4722 mHasGrey = TRUE; // for statistics gathering
4723 }
4602 } 4724 }
4603 else 4725 else
4604 { 4726 {
4605 desired_pixels = llmin(mPixelArea, (F32)LOCTEX_IMAGE_AREA_OTHER ); 4727 if (mLocalTexture[idx]->getID() == IMG_DEFAULT_AVATAR)
4606 imagep->setBoostLevel(LLViewerImage::BOOST_AVATAR); 4728 {
4729 // texture asset is missing
4730 mHasGrey = TRUE; // for statistics gathering
4731 }
4607 } 4732 }
4608 imagep->addTextureStats( desired_pixels, texel_area_ratio );
4609 } 4733 }
4610} 4734}
4611 4735
@@ -4614,7 +4738,7 @@ void LLVOAvatar::addBakedTextureStats( LLViewerImage* imagep, F32 pixel_area, F3
4614{ 4738{
4615 mMaxPixelArea = llmax(pixel_area, mMaxPixelArea); 4739 mMaxPixelArea = llmax(pixel_area, mMaxPixelArea);
4616 mMinPixelArea = llmin(pixel_area, mMinPixelArea); 4740 mMinPixelArea = llmin(pixel_area, mMinPixelArea);
4617 imagep->addTextureStats(pixel_area, texel_area_ratio); 4741 imagep->addTextureStats(pixel_area / texel_area_ratio);
4618 imagep->setBoostLevel(boost_level); 4742 imagep->setBoostLevel(boost_level);
4619} 4743}
4620 4744
@@ -4803,12 +4927,13 @@ BOOL LLVOAvatar::processSingleAnimationStateChange( const LLUUID& anim_id, BOOL
4803 // to support both spatialized and non-spatialized instances of the same sound 4927 // to support both spatialized and non-spatialized instances of the same sound
4804 //if (mIsSelf) 4928 //if (mIsSelf)
4805 //{ 4929 //{
4806 // F32 volume = gain * gSavedSettings.getF32("AudioLevelUI") 4930 // gAudiop->triggerSound(LLUUID(gSavedSettings.getString("UISndTyping")), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
4807 // gAudiop->triggerSound(LLUUID(gSavedSettings.getString("UISndTyping")), volume);
4808 //} 4931 //}
4809 //else 4932 //else
4810 LLUUID sound_id = LLUUID(gSavedSettings.getString("UISndTyping")); 4933 {
4811 gAudiop->triggerSound(sound_id, getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_SFX, char_pos_global); 4934 LLUUID sound_id = LLUUID(gSavedSettings.getString("UISndTyping"));
4935 gAudiop->triggerSound(sound_id, getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_SFX, char_pos_global);
4936 }
4812 } 4937 }
4813 } 4938 }
4814 } 4939 }
@@ -5826,7 +5951,7 @@ void LLVOAvatar::setPixelAreaAndAngle(LLAgent &agent)
5826 } 5951 }
5827 else 5952 else
5828 { 5953 {
5829 F32 radius = size.magVec(); 5954 F32 radius = size.length();
5830 mAppAngle = (F32) atan2( radius, range) * RAD_TO_DEG; 5955 mAppAngle = (F32) atan2( radius, range) * RAD_TO_DEG;
5831 } 5956 }
5832 5957
@@ -5998,7 +6123,7 @@ void LLVOAvatar::updateShadowFaces()
5998 sprite.setPosition(shadow_pos_agent); 6123 sprite.setPosition(shadow_pos_agent);
5999 6124
6000 LLVector3 foot_to_knee = mKneeLeftp->getWorldPosition() - joint_world_pos; 6125 LLVector3 foot_to_knee = mKneeLeftp->getWorldPosition() - joint_world_pos;
6001 //foot_to_knee.normVec(); 6126 //foot_to_knee.normalize();
6002 foot_to_knee -= projected_vec(foot_to_knee, sun_vec); 6127 foot_to_knee -= projected_vec(foot_to_knee, sun_vec);
6003 sprite.setYaw(azimuth(sun_vec - foot_to_knee)); 6128 sprite.setYaw(azimuth(sun_vec - foot_to_knee));
6004 6129
@@ -6031,7 +6156,7 @@ void LLVOAvatar::updateShadowFaces()
6031 sprite.setPosition(shadow_pos_agent); 6156 sprite.setPosition(shadow_pos_agent);
6032 6157
6033 LLVector3 foot_to_knee = mKneeRightp->getWorldPosition() - joint_world_pos; 6158 LLVector3 foot_to_knee = mKneeRightp->getWorldPosition() - joint_world_pos;
6034 //foot_to_knee.normVec(); 6159 //foot_to_knee.normalize();
6035 foot_to_knee -= projected_vec(foot_to_knee, sun_vec); 6160 foot_to_knee -= projected_vec(foot_to_knee, sun_vec);
6036 sprite.setYaw(azimuth(sun_vec - foot_to_knee)); 6161 sprite.setYaw(azimuth(sun_vec - foot_to_knee));
6037 6162
@@ -6392,7 +6517,7 @@ void LLVOAvatar::getOffObject()
6392 LLVector3 at_axis = LLVector3::x_axis; 6517 LLVector3 at_axis = LLVector3::x_axis;
6393 at_axis = at_axis * av_rot; 6518 at_axis = at_axis * av_rot;
6394 at_axis.mV[VZ] = 0.f; 6519 at_axis.mV[VZ] = 0.f;
6395 at_axis.normVec(); 6520 at_axis.normalize();
6396 gAgent.resetAxes(at_axis); 6521 gAgent.resetAxes(at_axis);
6397 6522
6398 //reset orientation 6523 //reset orientation
@@ -6946,7 +7071,7 @@ BOOL LLVOAvatar::bindScratchTexture( LLGLenum format )
6946 GLuint gl_name = getScratchTexName( format, &texture_bytes ); 7071 GLuint gl_name = getScratchTexName( format, &texture_bytes );
6947 if( gl_name ) 7072 if( gl_name )
6948 { 7073 {
6949 LLImageGL::bindExternalTexture( gl_name, 0, GL_TEXTURE_2D ); 7074 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name);
6950 stop_glerror(); 7075 stop_glerror();
6951 7076
6952 F32* last_bind_time = LLVOAvatar::sScratchTexLastBindTime.getIfThere( format ); 7077 F32* last_bind_time = LLVOAvatar::sScratchTexLastBindTime.getIfThere( format );
@@ -7004,7 +7129,7 @@ LLGLuint LLVOAvatar::getScratchTexName( LLGLenum format, U32* texture_bytes )
7004 glGenTextures(1, &name ); 7129 glGenTextures(1, &name );
7005 stop_glerror(); 7130 stop_glerror();
7006 7131
7007 LLImageGL::bindExternalTexture( name, 0, GL_TEXTURE_2D ); 7132 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, name);
7008 stop_glerror(); 7133 stop_glerror();
7009 7134
7010 glTexImage2D( 7135 glTexImage2D(
@@ -7019,7 +7144,7 @@ LLGLuint LLVOAvatar::getScratchTexName( LLGLenum format, U32* texture_bytes )
7019 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); 7144 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
7020 stop_glerror(); 7145 stop_glerror();
7021 7146
7022 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 7147 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
7023 stop_glerror(); 7148 stop_glerror();
7024 7149
7025 LLVOAvatar::sScratchTexNames.addData( format, new LLGLuint( name ) ); 7150 LLVOAvatar::sScratchTexNames.addData( format, new LLGLuint( name ) );
@@ -8628,7 +8753,7 @@ void LLVOAvatar::onBakedTextureMasksLoaded( BOOL success, LLViewerImage *src_vi,
8628 glGenTextures(1, (GLuint*) &gl_name ); 8753 glGenTextures(1, (GLuint*) &gl_name );
8629 stop_glerror(); 8754 stop_glerror();
8630 8755
8631 LLImageGL::bindExternalTexture( gl_name, 0, GL_TEXTURE_2D ); 8756 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name);
8632 stop_glerror(); 8757 stop_glerror();
8633 8758
8634 glTexImage2D( 8759 glTexImage2D(
@@ -9034,10 +9159,27 @@ void LLVOAvatar::cullAvatarsByPixelArea()
9034 } 9159 }
9035 } 9160 }
9036 9161
9037 if( LLVOAvatar::areAllNearbyInstancesBaked() ) 9162 S32 grey_avatars = 0;
9163 if( LLVOAvatar::areAllNearbyInstancesBaked(grey_avatars) )
9038 { 9164 {
9039 LLVOAvatar::deleteCachedImages(); 9165 LLVOAvatar::deleteCachedImages();
9040 } 9166 }
9167 else
9168 {
9169 if (gFrameTimeSeconds != sUnbakedUpdateTime) // only update once per frame
9170 {
9171 sUnbakedUpdateTime = gFrameTimeSeconds;
9172 sUnbakedTime += gFrameIntervalSeconds;
9173 }
9174 if (grey_avatars > 0)
9175 {
9176 if (gFrameTimeSeconds != sGreyUpdateTime) // only update once per frame
9177 {
9178 sGreyUpdateTime = gFrameTimeSeconds;
9179 sGreyTime += gFrameIntervalSeconds;
9180 }
9181 }
9182 }
9041} 9183}
9042 9184
9043const LLUUID& LLVOAvatar::grabLocalTexture(ETextureIndex index) 9185const LLUUID& LLVOAvatar::grabLocalTexture(ETextureIndex index)
@@ -9903,7 +10045,7 @@ void LLVOAvatar::getImpostorValues(LLVector3* extents, LLVector3& angle, F32& di
9903 extents[1] = ext[1]; 10045 extents[1] = ext[1];
9904 10046
9905 LLVector3 at = LLViewerCamera::getInstance()->getOrigin()-(getRenderPosition()+mImpostorOffset); 10047 LLVector3 at = LLViewerCamera::getInstance()->getOrigin()-(getRenderPosition()+mImpostorOffset);
9906 distance = at.normVec(); 10048 distance = at.normalize();
9907 F32 da = 1.f - (at*LLViewerCamera::getInstance()->getAtAxis()); 10049 F32 da = 1.f - (at*LLViewerCamera::getInstance()->getAtAxis());
9908 angle.mV[0] = LLViewerCamera::getInstance()->getYaw()*da; 10050 angle.mV[0] = LLViewerCamera::getInstance()->getYaw()*da;
9909 angle.mV[1] = LLViewerCamera::getInstance()->getPitch()*da; 10051 angle.mV[1] = LLViewerCamera::getInstance()->getPitch()*da;