Migrated gl matrix stack to LLMatrix4a

This commit is contained in:
Shyotl
2014-06-22 03:34:51 -05:00
parent 8f6a578ec0
commit 061178ad82
64 changed files with 1533 additions and 1070 deletions

View File

@@ -903,14 +903,12 @@ BOOL LLVOTree::updateGeometry(LLDrawable *drawable)
void LLVOTree::updateMesh()
{
LLMatrix4 matrix;
// Translate to tree base HACK - adjustment in Z plants tree underground
const LLVector3 &pos_region = getPositionRegion();
//gGL.translatef(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f);
LLMatrix4 trans_mat;
trans_mat.setTranslation(pos_region.mV[VX], pos_region.mV[VY], pos_region.mV[VZ] - 0.1f);
trans_mat *= matrix;
LLMatrix4a trans_mat;
trans_mat.setIdentity();
trans_mat.setTranslate_affine(pos_region - LLVector3(0.f,0.f,0.1f));
// Rotate to tree position and bend for current trunk/wind
// Note that trunk stiffness controls the amount of bend at the trunk as
@@ -923,16 +921,13 @@ void LLVOTree::updateMesh()
LLQuaternion(90.f*DEG_TO_RAD, LLVector4(0,0,1)) *
getRotation();
LLMatrix4 rot_mat(rot);
rot_mat *= trans_mat;
LLMatrix4a rot_mat = trans_mat;
rot_mat.mul(LLQuaternion2(rot));
F32 radius = getScale().magVec()*0.05f;
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] =
scale_mat.mMatrix[1][1] =
scale_mat.mMatrix[2][2] = radius;
scale_mat *= rot_mat;
LLMatrix4a scale_mat = rot_mat;
rot_mat.applyScale_affine(radius);
// const F32 THRESH_ANGLE_FOR_BILLBOARD = 15.f;
// const F32 BLEND_RANGE_FOR_BILLBOARD = 3.f;
@@ -953,8 +948,8 @@ void LLVOTree::updateMesh()
buff->allocateBuffer(vert_count, index_count, TRUE);
facep->setVertexBuffer(buff);
LLStrider<LLVector3> vertices;
LLStrider<LLVector3> normals;
LLStrider<LLVector4a> vertices;
LLStrider<LLVector4a> normals;
LLStrider<LLVector2> tex_coords;
LLStrider<U16> indices;
U16 idx_offset = 0;
@@ -964,26 +959,26 @@ void LLVOTree::updateMesh()
buff->getTexCoord0Strider(tex_coords);
buff->getIndexStrider(indices);
genBranchPipeline(vertices, normals, tex_coords, indices, idx_offset, scale_mat, mTrunkLOD, stop_depth, mDepth, mTrunkDepth, 1.0, mTwist, droop, mBranches, alpha);
genBranchPipeline(vertices, normals, tex_coords, indices, idx_offset, rot_mat, mTrunkLOD, stop_depth, mDepth, mTrunkDepth, 1.0, mTwist, droop, mBranches, alpha);
mReferenceBuffer->flush();
buff->flush();
}
void LLVOTree::appendMesh(LLStrider<LLVector3>& vertices,
LLStrider<LLVector3>& normals,
void LLVOTree::appendMesh(LLStrider<LLVector4a>& vertices,
LLStrider<LLVector4a>& normals,
LLStrider<LLVector2>& tex_coords,
LLStrider<U16>& indices,
U16& cur_idx,
LLMatrix4& matrix,
LLMatrix4& norm_mat,
LLMatrix4a& matrix,
LLMatrix4a& norm_mat,
S32 vert_start,
S32 vert_count,
S32 index_count,
S32 index_offset)
{
LLStrider<LLVector3> v;
LLStrider<LLVector3> n;
LLStrider<LLVector4a> v;
LLStrider<LLVector4a> n;
LLStrider<LLVector2> t;
LLStrider<U16> idx;
@@ -996,10 +991,10 @@ void LLVOTree::appendMesh(LLStrider<LLVector3>& vertices,
for (S32 i = 0; i < vert_count; i++)
{
U16 index = vert_start + i;
*vertices++ = v[index] * matrix;
LLVector3 norm = n[index] * norm_mat;
norm.normalize();
*normals++ = norm;
matrix.affineTransform(v[index],*vertices++);
LLVector4a& norm = *normals++;
norm_mat.perspectiveTransform(n[index],norm);
norm.normalize3fast();
*tex_coords++ = t[index];
}
@@ -1015,12 +1010,12 @@ void LLVOTree::appendMesh(LLStrider<LLVector3>& vertices,
}
void LLVOTree::genBranchPipeline(LLStrider<LLVector3>& vertices,
LLStrider<LLVector3>& normals,
void LLVOTree::genBranchPipeline(LLStrider<LLVector4a>& vertices,
LLStrider<LLVector4a>& normals,
LLStrider<LLVector2>& tex_coords,
LLStrider<U16>& indices,
U16& index_offset,
LLMatrix4& matrix,
LLMatrix4a& matrix,
S32 trunk_LOD,
S32 stop_level,
U16 depth,
@@ -1049,46 +1044,44 @@ void LLVOTree::genBranchPipeline(LLStrider<LLVector3>& vertices,
{
llassert(sLODIndexCount[trunk_LOD] > 0);
width = scale * length * aspect;
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] = width;
scale_mat.mMatrix[1][1] = width;
scale_mat.mMatrix[2][2] = scale*length;
scale_mat *= matrix;
glh::matrix4f norm((F32*) scale_mat.mMatrix);
LLMatrix4 norm_mat = LLMatrix4(norm.inverse().transpose().m);
LLMatrix4a scale_mat = matrix;
scale_mat.applyScale_affine(width,width,scale*length);
LLMatrix4a norm_mat = scale_mat;
norm_mat.invert();
norm_mat.transpose();
appendMesh(vertices, normals, tex_coords, indices, index_offset, scale_mat, norm_mat,
sLODVertexOffset[trunk_LOD], sLODVertexCount[trunk_LOD], sLODIndexCount[trunk_LOD], sLODIndexOffset[trunk_LOD]);
}
LLMatrix4a trans_matrix = matrix;
trans_matrix.applyTranslation_affine(0.f,0.f,scale*length);
const LLMatrix4a& trans_mat = trans_matrix;
// Recurse to create more branches
for (S32 i=0; i < (S32)branches; i++)
{
LLMatrix4 trans_mat;
trans_mat.setTranslation(0,0,scale*length);
trans_mat *= matrix;
LLQuaternion rot =
LLQuaternion(20.f*DEG_TO_RAD, LLVector4(0.f, 0.f, 1.f)) *
LLQuaternion(droop*DEG_TO_RAD, LLVector4(0.f, 1.f, 0.f)) *
LLQuaternion(((constant_twist + ((i%2==0)?twist:-twist))*i)*DEG_TO_RAD, LLVector4(0.f, 0.f, 1.f));
LLMatrix4 rot_mat(rot);
rot_mat *= trans_mat;
LLMatrix4a rot_mat = trans_mat;
rot_mat.mul(LLQuaternion2(rot));
genBranchPipeline(vertices, normals, tex_coords, indices, index_offset, rot_mat, trunk_LOD, stop_level, depth - 1, 0, scale*mScaleStep, twist, droop, branches, alpha);
}
// Recurse to continue trunk
if (trunk_depth)
{
LLMatrix4 trans_mat;
trans_mat.setTranslation(0,0,scale*length);
trans_mat *= matrix;
LLMatrix4 rot_mat(70.5f*DEG_TO_RAD, LLVector4(0,0,1));
rot_mat *= trans_mat; // rotate a bit around Z when ascending
static const LLMatrix4a srot_mat = gGL.genRot(70.5f,0.f,0.f,1.f);
LLMatrix4a rot_mat;
rot_mat.setMul(trans_mat, srot_mat); // rotate a bit around Z when ascending
genBranchPipeline(vertices, normals, tex_coords, indices, index_offset, rot_mat, trunk_LOD, stop_level, depth, trunk_depth-1, scale*mScaleStep, twist, droop, branches, alpha);
}
}
@@ -1098,15 +1091,12 @@ void LLVOTree::genBranchPipeline(LLStrider<LLVector3>& vertices,
// Append leaves as two 90 deg crossed quads with leaf textures
//
{
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] =
scale_mat.mMatrix[1][1] =
scale_mat.mMatrix[2][2] = scale*mLeafScale;
LLMatrix4a scale_mat = matrix;
scale_mat.applyScale_affine(scale*mLeafScale);
scale_mat *= matrix;
glh::matrix4f norm((F32*) scale_mat.mMatrix);
LLMatrix4 norm_mat = LLMatrix4(norm.inverse().transpose().m);
LLMatrix4a norm_mat = scale_mat;
norm_mat.invert();
norm_mat.transpose();
appendMesh(vertices, normals, tex_coords, indices, index_offset, scale_mat, norm_mat, 0, LEAF_VERTICES, LEAF_INDICES, 0);
}
@@ -1150,7 +1140,7 @@ void LLVOTree::calcNumVerts(U32& vert_count, U32& index_count, S32 trunk_LOD, S3
}
}
U32 LLVOTree::drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD, S32 stop_level, U16 depth, U16 trunk_depth, F32 scale, F32 twist, F32 droop, F32 branches, F32 alpha)
U32 LLVOTree::drawBranchPipeline(LLMatrix4a& matrix, U16* indicesp, S32 trunk_LOD, S32 stop_level, U16 depth, U16 trunk_depth, F32 scale, F32 twist, F32 droop, F32 branches, F32 alpha)
{
U32 ret = 0;
//
@@ -1178,13 +1168,10 @@ U32 LLVOTree::drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD
{
llassert(sLODIndexCount[trunk_LOD] > 0);
width = scale * length * aspect;
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] = width;
scale_mat.mMatrix[1][1] = width;
scale_mat.mMatrix[2][2] = scale*length;
scale_mat *= matrix;
LLMatrix4a scale_mat = matrix;
scale_mat.applyScale_affine(width, width, scale*length);
gGL.loadMatrix((F32*) scale_mat.mMatrix);
gGL.loadMatrix(scale_mat);
gGL.syncMatrices();
glDrawElements(GL_TRIANGLES, sLODIndexCount[trunk_LOD], GL_UNSIGNED_SHORT, indicesp + sLODIndexOffset[trunk_LOD]);
gPipeline.addTrianglesDrawn(LEAF_INDICES);
@@ -1192,32 +1179,31 @@ U32 LLVOTree::drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD
ret += sLODIndexCount[trunk_LOD];
}
LLMatrix4a trans_matrix = matrix;
trans_matrix.applyTranslation_affine(0.f,0.f,scale*length);
const LLMatrix4a& trans_mat = trans_matrix;
// Recurse to create more branches
for (S32 i=0; i < (S32)branches; i++)
{
LLMatrix4 trans_mat;
trans_mat.setTranslation(0,0,scale*length);
trans_mat *= matrix;
LLQuaternion rot =
LLQuaternion(20.f*DEG_TO_RAD, LLVector4(0.f, 0.f, 1.f)) *
LLQuaternion(droop*DEG_TO_RAD, LLVector4(0.f, 1.f, 0.f)) *
LLQuaternion(((constant_twist + ((i%2==0)?twist:-twist))*i)*DEG_TO_RAD, LLVector4(0.f, 0.f, 1.f));
LLMatrix4 rot_mat(rot);
rot_mat *= trans_mat;
LLMatrix4a rot_mat = trans_mat;
rot_mat.mul(LLQuaternion2(rot));
ret += drawBranchPipeline(rot_mat, indicesp, trunk_LOD, stop_level, depth - 1, 0, scale*mScaleStep, twist, droop, branches, alpha);
}
// Recurse to continue trunk
if (trunk_depth)
{
LLMatrix4 trans_mat;
trans_mat.setTranslation(0,0,scale*length);
trans_mat *= matrix;
static const LLMatrix4a srot_mat = gGL.genRot(70.5f,0.f,0.f,1.f);
LLMatrix4a rot_mat;
rot_mat.setMul(trans_mat, srot_mat); // rotate a bit around Z when ascending
LLMatrix4 rot_mat(70.5f*DEG_TO_RAD, LLVector4(0,0,1));
rot_mat *= trans_mat; // rotate a bit around Z when ascending
ret += drawBranchPipeline(rot_mat, indicesp, trunk_LOD, stop_level, depth, trunk_depth-1, scale*mScaleStep, twist, droop, branches, alpha);
}
}
@@ -1227,15 +1213,10 @@ U32 LLVOTree::drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD
// Draw leaves as two 90 deg crossed quads with leaf textures
//
{
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] =
scale_mat.mMatrix[1][1] =
scale_mat.mMatrix[2][2] = scale*mLeafScale;
LLMatrix4a scale_mat = matrix;
scale_mat.applyScale_affine(scale*mLeafScale);
scale_mat *= matrix;
gGL.loadMatrix((F32*) scale_mat.mMatrix);
gGL.loadMatrix(scale_mat);
gGL.syncMatrices();
glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_SHORT, indicesp);
gPipeline.addTrianglesDrawn(LEAF_INDICES);
@@ -1250,18 +1231,14 @@ U32 LLVOTree::drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD
// Draw the tree as a single billboard texture
//
LLMatrix4 scale_mat;
scale_mat.mMatrix[0][0] =
scale_mat.mMatrix[1][1] =
scale_mat.mMatrix[2][2] = mBillboardScale*mBillboardRatio;
scale_mat *= matrix;
LLMatrix4a scale_mat = matrix;
scale_mat.applyScale_affine(mBillboardScale*mBillboardRatio);
gGL.matrixMode(LLRender::MM_TEXTURE);
gGL.translatef(0.0, -0.5, 0.0);
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.loadMatrix((F32*) scale_mat.mMatrix);
gGL.loadMatrix(scale_mat);
gGL.syncMatrices();
glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_SHORT, indicesp);
gPipeline.addTrianglesDrawn(LEAF_INDICES);
@@ -1370,8 +1347,8 @@ LLTreePartition::LLTreePartition()
void LLVOTree::generateSilhouetteVertices(std::vector<LLVector3> &vertices,
std::vector<LLVector3> &normals,
const LLVector3& obj_cam_vec,
const LLMatrix4& local_matrix,
const LLMatrix3& normal_matrix)
const LLMatrix4a& local_matrix_,
const LLMatrix4a& normal_matrix)
{
vertices.clear();
normals.clear();
@@ -1379,6 +1356,8 @@ void LLVOTree::generateSilhouetteVertices(std::vector<LLVector3> &vertices,
F32 height = mBillboardScale; // *mBillboardRatio * 0.5;
F32 width = height * mTrunkAspect;
LLMatrix4 local_matrix(local_matrix_.getF32ptr());
LLVector3 position1 = LLVector3(-width * 0.5, 0, 0) * local_matrix;
LLVector3 position2 = LLVector3(-width * 0.5, 0, height) * local_matrix;
LLVector3 position3 = LLVector3(width * 0.5, 0, height) * local_matrix;
@@ -1468,9 +1447,13 @@ void LLVOTree::generateSilhouette(LLSelectNode* nodep, const LLVector3& view_poi
// compose final matrix
LLMatrix4 local_matrix;
local_matrix.initAll(scale, rotation, position);
LLMatrix4a lmat;
lmat.loadu(local_matrix);
LLMatrix4a nmat;
nmat.setIdentity();
generateSilhouetteVertices(nodep->mSilhouetteVertices, nodep->mSilhouetteNormals,
LLVector3(0, 0, 0), local_matrix, LLMatrix3());
LLVector3(0, 0, 0), lmat, nmat);
nodep->mSilhouetteExists = TRUE;
}