aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerjointmesh.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:54 -0500
committerJacek Antonelli2008-08-15 23:44:54 -0500
commitb2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch)
tree3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/newview/llviewerjointmesh.cpp
parentSecond Life viewer sources 1.14.0.1 (diff)
downloadmeta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/newview/llviewerjointmesh.cpp')
-rw-r--r--linden/indra/newview/llviewerjointmesh.cpp178
1 files changed, 99 insertions, 79 deletions
diff --git a/linden/indra/newview/llviewerjointmesh.cpp b/linden/indra/newview/llviewerjointmesh.cpp
index 3070cb4..216e29f 100644
--- a/linden/indra/newview/llviewerjointmesh.cpp
+++ b/linden/indra/newview/llviewerjointmesh.cpp
@@ -4,6 +4,7 @@
4 * 4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc. 5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 * 6 *
7 * Second Life Viewer Source Code
7 * The source code in this file ("Source Code") is provided by Linden Lab 8 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0 9 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement 10 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -53,6 +54,7 @@
53#include "llvoavatar.h" 54#include "llvoavatar.h"
54#include "llsky.h" 55#include "llsky.h"
55#include "pipeline.h" 56#include "pipeline.h"
57#include "llglslshader.h"
56 58
57#if !LL_DARWIN && !LL_LINUX 59#if !LL_DARWIN && !LL_LINUX
58extern PFNGLWEIGHTPOINTERARBPROC glWeightPointerARB; 60extern PFNGLWEIGHTPOINTERARBPROC glWeightPointerARB;
@@ -65,7 +67,6 @@ static LLPointer<LLVertexBuffer> sRenderBuffer = NULL;
65static const U32 sRenderMask = LLVertexBuffer::MAP_VERTEX | 67static const U32 sRenderMask = LLVertexBuffer::MAP_VERTEX |
66 LLVertexBuffer::MAP_NORMAL | 68 LLVertexBuffer::MAP_NORMAL |
67 LLVertexBuffer::MAP_TEXCOORD; 69 LLVertexBuffer::MAP_TEXCOORD;
68LLMatrix4 gBlendMat;
69 70
70//----------------------------------------------------------------------------- 71//-----------------------------------------------------------------------------
71//----------------------------------------------------------------------------- 72//-----------------------------------------------------------------------------
@@ -498,7 +499,7 @@ void LLViewerJointMesh::uploadJointMatrices()
498 //cgGLSetParameterArray4f(gPipeline.mAvatarMatrix, offset, 1, vector); 499 //cgGLSetParameterArray4f(gPipeline.mAvatarMatrix, offset, 1, vector);
499 } 500 }
500 } 501 }
501 glUniform4fvARB(gPipeline.mAvatarMatrixParam, 45, mat); 502 glUniform4fvARB(gAvatarMatrixParam, 45, mat);
502 } 503 }
503} 504}
504 505
@@ -573,14 +574,14 @@ U32 LLViewerJointMesh::drawShape( F32 pixelArea, BOOL first_pass)
573 { 574 {
574 glColor4f(0,0,0,1); 575 glColor4f(0,0,0,1);
575 576
576 if (gPipeline.mMaterialIndex > 0) 577 if (gMaterialIndex > 0)
577 { 578 {
578 glVertexAttrib4fvARB(gPipeline.mMaterialIndex, mColor.mV); 579 glVertexAttrib4fvARB(gMaterialIndex, mColor.mV);
579 } 580 }
580 581
581 if (mShiny && gPipeline.mSpecularIndex > 0) 582 if (mShiny && gSpecularIndex > 0)
582 { 583 {
583 glVertexAttrib4fARB(gPipeline.mSpecularIndex, 1,1,1,1); 584 glVertexAttrib4fARB(gSpecularIndex, 1,1,1,1);
584 } 585 }
585 } 586 }
586 else 587 else
@@ -902,89 +903,108 @@ BOOL LLViewerJointMesh::updateLOD(F32 pixel_area, BOOL activate)
902 return (valid != activate); 903 return (valid != activate);
903} 904}
904 905
906
905void LLViewerJointMesh::updateGeometry() 907void LLViewerJointMesh::updateGeometry()
906{ 908{
907 if (mValid && mMesh && mFace && 909 if (!(mValid
908 mMesh->hasWeights() && 910 && mMesh
909 mFace->mVertexBuffer.notNull() && 911 && mFace
910 gPipeline.getVertexShaderLevel(LLPipeline::SHADER_AVATAR) == 0) 912 && mMesh->hasWeights()
913 && mFace->mVertexBuffer.notNull()
914 && LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_AVATAR) == 0))
911 { 915 {
912 uploadJointMatrices(); 916 return;
913 LLStrider<LLVector3> o_vertices; 917 }
914 LLStrider<LLVector3> o_normals; 918
919 uploadJointMatrices();
915 920
916 //get vertex and normal striders 921 LLStrider<LLVector3> o_vertices;
917 LLVertexBuffer *buffer = mFace->mVertexBuffer; 922 LLStrider<LLVector3> o_normals;
918 buffer->getVertexStrider(o_vertices, 0);
919 buffer->getNormalStrider(o_normals, 0);
920 923
924 //get vertex and normal striders
925 LLVertexBuffer *buffer = mFace->mVertexBuffer;
926 buffer->getVertexStrider(o_vertices, 0);
927 buffer->getNormalStrider(o_normals, 0);
928
929 F32 last_weight = F32_MAX;
930 LLMatrix4 gBlendMat;
931 LLMatrix3 gBlendRotMat;
932
933 const F32* weights = mMesh->getWeights();
934 const LLVector3* coords = mMesh->getCoords();
935 const LLVector3* normals = mMesh->getNormals();
936 for (U32 index = 0; index < mMesh->getNumVertices(); index++)
937 {
938 U32 bidx = index + mMesh->mFaceVertexOffset;
939
940 // blend by first matrix
941 F32 w = weights[index];
942
943 // Maybe we don't have to change gBlendMat.
944 // Profiles of a single-avatar scene on a Mac show this to be a very
945 // common case. JC
946 if (w == last_weight)
921 { 947 {
922 LLVector4 tpos0, tnorm0, tpos1, tnorm1, tbinorm0, tbinorm1; 948 o_vertices[bidx] = coords[index] * gBlendMat;
923 F32 last_weight = F32_MAX; 949 o_normals[bidx] = normals[index] * gBlendRotMat;
924 LLMatrix3 gBlendRotMat; 950 continue;
951 }
952
953 last_weight = w;
925 954
955 S32 joint = llfloor(w);
956 w -= joint;
926 957
927 for (U32 index= 0; index < mMesh->getNumVertices(); index++) 958 // No lerp required in this case.
928 { 959 if (w == 1.0f)
929 // blend by first matrix 960 {
930 F32 w = mMesh->getWeights()[index]; 961 gBlendMat = gJointMat[joint+1];
931 962 o_vertices[bidx] = coords[index] * gBlendMat;
932 if (w != last_weight) 963 gBlendRotMat = gJointRot[joint+1];
933 { 964 o_normals[bidx] = normals[index] * gBlendRotMat;
934 last_weight = w; 965 continue;
935 966 }
936 S32 joint = llfloor(w); 967
937 w -= joint; 968 // Try to keep all the accesses to the matrix data as close
938 969 // together as possible. This function is a hot spot on the
939 LLMatrix4 &m0 = gJointMat[joint+1]; 970 // Mac. JC
940 LLMatrix4 &m1 = gJointMat[joint+0]; 971 LLMatrix4 &m0 = gJointMat[joint+1];
941 LLMatrix3 &n0 = gJointRot[joint+1]; 972 LLMatrix4 &m1 = gJointMat[joint+0];
942 LLMatrix3 &n1 = gJointRot[joint+0]; 973
943 974 gBlendMat.mMatrix[VX][VX] = lerp(m1.mMatrix[VX][VX], m0.mMatrix[VX][VX], w);
944 if (w == 1.0f) 975 gBlendMat.mMatrix[VX][VY] = lerp(m1.mMatrix[VX][VY], m0.mMatrix[VX][VY], w);
945 { 976 gBlendMat.mMatrix[VX][VZ] = lerp(m1.mMatrix[VX][VZ], m0.mMatrix[VX][VZ], w);
946 gBlendMat = m0;
947 gBlendRotMat = n0;
948 }
949 else
950 {
951 gBlendMat.mMatrix[VX][VX] = lerp(m1.mMatrix[VX][VX], m0.mMatrix[VX][VX], w);
952 gBlendMat.mMatrix[VX][VY] = lerp(m1.mMatrix[VX][VY], m0.mMatrix[VX][VY], w);
953 gBlendMat.mMatrix[VX][VZ] = lerp(m1.mMatrix[VX][VZ], m0.mMatrix[VX][VZ], w);
954
955 gBlendMat.mMatrix[VY][VX] = lerp(m1.mMatrix[VY][VX], m0.mMatrix[VY][VX], w);
956 gBlendMat.mMatrix[VY][VY] = lerp(m1.mMatrix[VY][VY], m0.mMatrix[VY][VY], w);
957 gBlendMat.mMatrix[VY][VZ] = lerp(m1.mMatrix[VY][VZ], m0.mMatrix[VY][VZ], w);
958
959 gBlendMat.mMatrix[VZ][VX] = lerp(m1.mMatrix[VZ][VX], m0.mMatrix[VZ][VX], w);
960 gBlendMat.mMatrix[VZ][VY] = lerp(m1.mMatrix[VZ][VY], m0.mMatrix[VZ][VY], w);
961 gBlendMat.mMatrix[VZ][VZ] = lerp(m1.mMatrix[VZ][VZ], m0.mMatrix[VZ][VZ], w);
962
963 gBlendMat.mMatrix[VW][VX] = lerp(m1.mMatrix[VW][VX], m0.mMatrix[VW][VX], w);
964 gBlendMat.mMatrix[VW][VY] = lerp(m1.mMatrix[VW][VY], m0.mMatrix[VW][VY], w);
965 gBlendMat.mMatrix[VW][VZ] = lerp(m1.mMatrix[VW][VZ], m0.mMatrix[VW][VZ], w);
966
967 gBlendRotMat.mMatrix[VX][VX] = lerp(n1.mMatrix[VX][VX], n0.mMatrix[VX][VX], w);
968 gBlendRotMat.mMatrix[VX][VY] = lerp(n1.mMatrix[VX][VY], n0.mMatrix[VX][VY], w);
969 gBlendRotMat.mMatrix[VX][VZ] = lerp(n1.mMatrix[VX][VZ], n0.mMatrix[VX][VZ], w);
970
971 gBlendRotMat.mMatrix[VY][VX] = lerp(n1.mMatrix[VY][VX], n0.mMatrix[VY][VX], w);
972 gBlendRotMat.mMatrix[VY][VY] = lerp(n1.mMatrix[VY][VY], n0.mMatrix[VY][VY], w);
973 gBlendRotMat.mMatrix[VY][VZ] = lerp(n1.mMatrix[VY][VZ], n0.mMatrix[VY][VZ], w);
974
975 gBlendRotMat.mMatrix[VZ][VX] = lerp(n1.mMatrix[VZ][VX], n0.mMatrix[VZ][VX], w);
976 gBlendRotMat.mMatrix[VZ][VY] = lerp(n1.mMatrix[VZ][VY], n0.mMatrix[VZ][VY], w);
977 gBlendRotMat.mMatrix[VZ][VZ] = lerp(n1.mMatrix[VZ][VZ], n0.mMatrix[VZ][VZ], w);
978 }
979 }
980 977
981 // write result 978 gBlendMat.mMatrix[VY][VX] = lerp(m1.mMatrix[VY][VX], m0.mMatrix[VY][VX], w);
982 U32 bidx = index + mMesh->mFaceVertexOffset; 979 gBlendMat.mMatrix[VY][VY] = lerp(m1.mMatrix[VY][VY], m0.mMatrix[VY][VY], w);
980 gBlendMat.mMatrix[VY][VZ] = lerp(m1.mMatrix[VY][VZ], m0.mMatrix[VY][VZ], w);
983 981
984 o_vertices[bidx] = mMesh->getCoords()[index] * gBlendMat; 982 gBlendMat.mMatrix[VZ][VX] = lerp(m1.mMatrix[VZ][VX], m0.mMatrix[VZ][VX], w);
985 o_normals[bidx] = mMesh->getNormals()[index] * gBlendRotMat; 983 gBlendMat.mMatrix[VZ][VY] = lerp(m1.mMatrix[VZ][VY], m0.mMatrix[VZ][VY], w);
986 } 984 gBlendMat.mMatrix[VZ][VZ] = lerp(m1.mMatrix[VZ][VZ], m0.mMatrix[VZ][VZ], w);
987 } 985
986 gBlendMat.mMatrix[VW][VX] = lerp(m1.mMatrix[VW][VX], m0.mMatrix[VW][VX], w);
987 gBlendMat.mMatrix[VW][VY] = lerp(m1.mMatrix[VW][VY], m0.mMatrix[VW][VY], w);
988 gBlendMat.mMatrix[VW][VZ] = lerp(m1.mMatrix[VW][VZ], m0.mMatrix[VW][VZ], w);
989
990 o_vertices[bidx] = coords[index] * gBlendMat;
991
992 LLMatrix3 &n0 = gJointRot[joint+1];
993 LLMatrix3 &n1 = gJointRot[joint+0];
994
995 gBlendRotMat.mMatrix[VX][VX] = lerp(n1.mMatrix[VX][VX], n0.mMatrix[VX][VX], w);
996 gBlendRotMat.mMatrix[VX][VY] = lerp(n1.mMatrix[VX][VY], n0.mMatrix[VX][VY], w);
997 gBlendRotMat.mMatrix[VX][VZ] = lerp(n1.mMatrix[VX][VZ], n0.mMatrix[VX][VZ], w);
998
999 gBlendRotMat.mMatrix[VY][VX] = lerp(n1.mMatrix[VY][VX], n0.mMatrix[VY][VX], w);
1000 gBlendRotMat.mMatrix[VY][VY] = lerp(n1.mMatrix[VY][VY], n0.mMatrix[VY][VY], w);
1001 gBlendRotMat.mMatrix[VY][VZ] = lerp(n1.mMatrix[VY][VZ], n0.mMatrix[VY][VZ], w);
1002
1003 gBlendRotMat.mMatrix[VZ][VX] = lerp(n1.mMatrix[VZ][VX], n0.mMatrix[VZ][VX], w);
1004 gBlendRotMat.mMatrix[VZ][VY] = lerp(n1.mMatrix[VZ][VY], n0.mMatrix[VZ][VY], w);
1005 gBlendRotMat.mMatrix[VZ][VZ] = lerp(n1.mMatrix[VZ][VZ], n0.mMatrix[VZ][VZ], w);
1006
1007 o_normals[bidx] = normals[index] * gBlendRotMat;
988 } 1008 }
989} 1009}
990 1010