Unstaged changes cleanup. Further vectorization. Change in binormal/bitangent calculation.

This commit is contained in:
Shyotl
2013-10-09 14:47:06 -05:00
parent b473661cf4
commit f25eb07fab
51 changed files with 1987 additions and 1895 deletions

View File

@@ -1053,13 +1053,17 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bo
{ //already cached
break;
}
volume->genBinormals(i);
volume->genTangents(i);
LLFace::cacheFaceInVRAM(face);
}
}
return TRUE;
}
return FALSE;
}
@@ -1218,7 +1222,7 @@ BOOL LLVOVolume::calcLOD()
else
{
distance = mDrawable->mDistanceWRTCamera;
radius = getVolume()->mLODScaleBias.scaledVec(getScale()).length();
radius = getVolume() ? getVolume()->mLODScaleBias.scaledVec(getScale()).length() : getScale().length();
}
@@ -3589,8 +3593,8 @@ LLVector3 LLVOVolume::volumeDirectionToAgent(const LLVector3& dir) const
}
BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, S32 face, BOOL pick_transparent, S32 *face_hitp,
LLVector3* intersection,LLVector2* tex_coord, LLVector3* normal, LLVector3* bi_normal)
BOOL LLVOVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, S32 face, BOOL pick_transparent, S32 *face_hitp,
LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
{
if (!mbCanSelect ||
@@ -3631,23 +3635,25 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
if (volume)
{
LLVector3 v_start, v_end, v_dir;
LLVector4a local_start = start;
LLVector4a local_end = end;
if (transform)
{
v_start = agentPositionToVolume(start);
v_end = agentPositionToVolume(end);
}
else
{
v_start = start;
v_end = end;
}
LLVector3 v_start(start.getF32ptr());
LLVector3 v_end(end.getF32ptr());
LLVector3 p;
LLVector3 n;
v_start = agentPositionToVolume(v_start);
v_end = agentPositionToVolume(v_end);
local_start.load3(v_start.mV);
local_end.load3(v_end.mV);
}
LLVector4a p;
LLVector4a n;
LLVector2 tc;
LLVector3 bn;
LLVector4a tn;
if (intersection != NULL)
{
@@ -3664,9 +3670,9 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
n = *normal;
}
if (bi_normal != NULL)
if (tangent != NULL)
{
bn = *bi_normal;
tn = *tangent;
}
S32 face_hit = -1;
@@ -3692,8 +3698,8 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
continue;
}
face_hit = volume->lineSegmentIntersect(v_start, v_end, i,
&p, &tc, &n, &bn);
face_hit = volume->lineSegmentIntersect(local_start, local_end, i,
&p, &tc, &n, &tn);
if (face_hit >= 0 && mDrawable->getNumFaces() > face_hit)
{
@@ -3702,7 +3708,7 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
if (face &&
(pick_transparent || !face->getTexture() || !face->getTexture()->hasGLTexture() || face->getTexture()->getMask(face->surfaceToTexture(tc, p, n))))
{
v_end = p;
local_end = p;
if (face_hitp != NULL)
{
*face_hitp = face_hit;
@@ -3712,7 +3718,9 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
{
if (transform)
{
*intersection = volumePositionToAgent(p); // must map back to agent space
LLVector3 v_p(p.getF32ptr());
intersection->load3(volumePositionToAgent(v_p).mV); // must map back to agent space
}
else
{
@@ -3724,27 +3732,36 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
{
if (transform)
{
*normal = volumeDirectionToAgent(n);
LLVector3 v_n(n.getF32ptr());
normal->load3(volumeDirectionToAgent(v_n).mV);
}
else
{
*normal = n;
}
(*normal).normVec();
(*normal).normalize3fast();
}
if (bi_normal != NULL)
if (tangent != NULL)
{
if (transform)
{
*bi_normal = volumeDirectionToAgent(bn);
LLVector3 v_tn(tn.getF32ptr());
LLVector4a trans_tangent;
trans_tangent.load3(volumeDirectionToAgent(v_tn).mV);
LLVector4Logical mask;
mask.clear();
mask.setElement<3>();
tangent->setSelectWithMask(mask, tn, trans_tangent);
}
else
{
*bi_normal = bn;
*tangent = tn;
}
(*bi_normal).normVec();
(*tangent).normalize3fast();
}
if (tex_coord != NULL)
@@ -4262,11 +4279,18 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
mFaceList.clear();
std::vector<LLFace*> fullbright_faces;
std::vector<LLFace*> bump_faces;
std::vector<LLFace*> simple_faces;
const U32 MAX_FACE_COUNT = 4096;
static LLFace** fullbright_faces = (LLFace**) ll_aligned_malloc(MAX_FACE_COUNT*sizeof(LLFace*),64);
static LLFace** bump_faces = (LLFace**) ll_aligned_malloc(MAX_FACE_COUNT*sizeof(LLFace*),64);
static LLFace** simple_faces = (LLFace**) ll_aligned_malloc(MAX_FACE_COUNT*sizeof(LLFace*),64);
static LLFace** alpha_faces = (LLFace**) ll_aligned_malloc(MAX_FACE_COUNT*sizeof(LLFace*),64);
U32 fullbright_count = 0;
U32 bump_count = 0;
U32 simple_count = 0;
U32 alpha_count = 0;
std::vector<LLFace*> alpha_faces;
U32 useage = group->mSpatialPartition->mBufferUsage;
static const LLCachedControl<S32> render_max_vbo_size("RenderMaxVBOSize", 512);
@@ -4623,7 +4647,10 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
{
if (facep->canRenderAsMask())
{ //can be treated as alpha mask
simple_faces.push_back(facep);
if (simple_count < MAX_FACE_COUNT)
{
simple_faces[simple_count++] = facep;
}
}
else
{
@@ -4631,7 +4658,10 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
{ //only treat as alpha in the pipeline if < 100% transparent
drawablep->setState(LLDrawable::HAS_ALPHA);
}
alpha_faces.push_back(facep);
if (alpha_count < MAX_FACE_COUNT)
{
alpha_faces[alpha_count++] = facep;
}
}
}
else
@@ -4645,34 +4675,52 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
&& LLPipeline::sRenderBump)
{
if (te->getBumpmap())
{ //needs normal + binormal
bump_faces.push_back(facep);
{ //needs normal + tangent
if (bump_count < MAX_FACE_COUNT)
{
bump_faces[bump_count++] = facep;
}
}
else if (te->getShiny() || !te->getFullbright())
{ //needs normal
simple_faces.push_back(facep);
if (simple_count < MAX_FACE_COUNT)
{
simple_faces[simple_count++] = facep;
}
}
else
{ //doesn't need normal
facep->setState(LLFace::FULLBRIGHT);
fullbright_faces.push_back(facep);
if (fullbright_count < MAX_FACE_COUNT)
{
fullbright_faces[fullbright_count++] = facep;
}
}
}
else
{
if (te->getBumpmap() && LLPipeline::sRenderBump)
{ //needs normal + binormal
bump_faces.push_back(facep);
{ //needs normal + tangent
if (bump_count < MAX_FACE_COUNT)
{
bump_faces[bump_count++] = facep;
}
}
else if ((te->getShiny() && LLPipeline::sRenderBump) ||
!(te->getFullbright() || bake_sunlight))
{ //needs normal
simple_faces.push_back(facep);
if (simple_count < MAX_FACE_COUNT)
{
simple_faces[simple_count++] = facep;
}
}
else
{ //doesn't need normal
facep->setState(LLFace::FULLBRIGHT);
fullbright_faces.push_back(facep);
if (fullbright_count < MAX_FACE_COUNT)
{
fullbright_faces[fullbright_count++] = facep;
}
}
}
}
@@ -4714,18 +4762,18 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
if (batch_textures)
{
bump_mask |= LLVertexBuffer::MAP_BINORMAL;
genDrawInfo(group, simple_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, simple_faces, FALSE, TRUE);
genDrawInfo(group, fullbright_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, fullbright_faces, FALSE, TRUE);
genDrawInfo(group, bump_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, bump_faces, FALSE, TRUE);
genDrawInfo(group, alpha_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, alpha_faces, TRUE, TRUE);
bump_mask |= LLVertexBuffer::MAP_TANGENT;
genDrawInfo(group, simple_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, simple_faces, simple_count, FALSE, TRUE);
genDrawInfo(group, fullbright_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, fullbright_faces, fullbright_count, FALSE, TRUE);
genDrawInfo(group, bump_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, bump_faces, bump_count, FALSE, TRUE);
genDrawInfo(group, alpha_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, alpha_faces, alpha_count, TRUE, TRUE);
}
else
{
genDrawInfo(group, simple_mask, simple_faces);
genDrawInfo(group, fullbright_mask, fullbright_faces);
genDrawInfo(group, bump_mask, bump_faces, FALSE, TRUE);
genDrawInfo(group, alpha_mask, alpha_faces, TRUE);
genDrawInfo(group, simple_mask, simple_faces, simple_count);
genDrawInfo(group, fullbright_mask, fullbright_faces, fullbright_count);
genDrawInfo(group, bump_mask, bump_faces, bump_count, FALSE, TRUE);
genDrawInfo(group, alpha_mask, alpha_faces, alpha_count, TRUE);
}
@@ -4767,13 +4815,17 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
{
LLFastTimer ftm(FTM_REBUILD_VOLUME_VB);
LLFastTimer t(FTM_REBUILD_VOLUME_GEN_DRAW_INFO); //make sure getgeometryvolume shows up in the right place in timers
S32 num_mapped_vertex_buffer = LLVertexBuffer::sMappedCount ;
group->mBuilt = 1.f;
std::set<LLVertexBuffer*> mapped_buffers;
OctreeGuard guard(group->mOctreeNode);
S32 num_mapped_vertex_buffer = LLVertexBuffer::sMappedCount ;
const U32 MAX_BUFFER_COUNT = 4096;
static LLVertexBuffer* locked_buffer[MAX_BUFFER_COUNT];
U32 buffer_count = 0;
for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{
LLDrawable* drawablep = *drawable_iter;
@@ -4807,9 +4859,9 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
}
if (buff->isLocked())
if (buff->isLocked() && buffer_count < MAX_BUFFER_COUNT)
{
mapped_buffers.insert(buff);
locked_buffer[buffer_count++] = buff;
}
}
}
@@ -4825,7 +4877,7 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
}
}
for (std::set<LLVertexBuffer*>::iterator iter = mapped_buffers.begin(); iter != mapped_buffers.end(); ++iter)
for (LLVertexBuffer** iter = locked_buffer, ** end_iter = locked_buffer+buffer_count; iter != end_iter; ++iter)
{
(*iter)->flush();
}
@@ -4904,7 +4956,7 @@ static LLFastTimer::DeclareTimer FTM_GEN_DRAW_INFO_RESIZE_VB("Resize VB");
void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::vector<LLFace*>& faces, BOOL distance_sort, BOOL batch_textures)
void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace** faces, U32 face_count, BOOL distance_sort, BOOL batch_textures, BOOL no_materials)
{
LLFastTimer t(FTM_REBUILD_VOLUME_GEN_DRAW_INFO);
@@ -4931,17 +4983,18 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
if (!distance_sort)
{
//sort faces by things that break batches
std::sort(faces.begin(), faces.end(), CompareBatchBreakerModified());
std::sort(faces, faces+face_count, CompareBatchBreakerModified());
}
else
{
//sort faces by distance
std::sort(faces.begin(), faces.end(), LLFace::CompareDistanceGreater());
std::sort(faces, faces+face_count, LLFace::CompareDistanceGreater());
}
}
bool hud_group = group->isHUDGroup() ;
std::vector<LLFace*>::iterator face_iter = faces.begin();
LLFace** face_iter = faces;
LLFace** end_faces = faces+face_count;
LLSpatialGroup::buffer_map_t buffer_map;
@@ -4973,7 +5026,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
//NEVER use more than 16 texture index channels (workaround for prevalent driver bug)
texture_index_channels = llmin(texture_index_channels, 16);
while (face_iter != faces.end())
while (face_iter != end_faces)
{
//pull off next face
LLFace* facep = *face_iter;
@@ -4999,11 +5052,15 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
U32 index_count = facep->getIndicesCount();
U32 geom_count = facep->getGeomCount();
//sum up vertices needed for this render batch
std::vector<LLFace*>::iterator i = face_iter;
LLFace** i = face_iter;
++i;
std::vector<LLViewerTexture*> texture_list;
const U32 MAX_TEXTURE_COUNT = 32;
static LLViewerTexture* texture_list[MAX_TEXTURE_COUNT];
U32 texture_count = 0;
{
LLFastTimer t(FTM_GEN_DRAW_INFO_FACE_SIZE);
@@ -5011,11 +5068,15 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
{
U8 cur_tex = 0;
facep->setTextureIndex(cur_tex);
texture_list.push_back(tex);
if (texture_count < MAX_TEXTURE_COUNT)
{
texture_list[texture_count++] = tex;
}
if (can_batch_texture(facep))
{
while (i != faces.end())
{ //populate texture_list with any textures that can be batched
//move i to the next unbatchable face
while (i != end_faces)
{
facep = *i;
if (!can_batch_texture(facep))
@@ -5028,7 +5089,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
if (distance_sort)
{ //textures might be out of order, see if texture exists in current batch
bool found = false;
for (U32 tex_idx = 0; tex_idx < texture_list.size(); ++tex_idx)
for (U32 tex_idx = 0; tex_idx < texture_count; ++tex_idx)
{
if (facep->getTexture() == texture_list[tex_idx])
{
@@ -5040,7 +5101,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
if (!found)
{
cur_tex = texture_list.size();
cur_tex = texture_count;
}
}
else
@@ -5055,7 +5116,10 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
tex = facep->getTexture();
texture_list.push_back(tex);
if (texture_count < MAX_TEXTURE_COUNT)
{
texture_list[texture_count++] = tex;
}
}
if (geom_count + facep->getGeomCount() > max_vertices)
@@ -5074,7 +5138,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
}
else
{
while (i != faces.end() &&
while (i != end_faces &&
(LLPipeline::sTextureBindTest || (distance_sort || (*i)->getTexture() == tex)))
{
facep = *i;