summaryrefslogtreecommitdiff
path: root/indra/newview/llface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llface.cpp')
-rw-r--r--indra/newview/llface.cpp298
1 files changed, 273 insertions, 25 deletions
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index e49ef8b969..53330e4d98 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -52,6 +52,7 @@
#include "llvovolume.h"
#include "pipeline.h"
#include "llviewerregion.h"
+#include "llviewerwindow.h"
#define LL_MAX_INDICES_COUNT 1000000
@@ -156,6 +157,7 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
mGeomIndex = 0;
mIndicesCount = 0;
mIndicesIndex = 0;
+ mIndexInTex = 0;
mTexture = NULL;
mTEOffset = -1;
@@ -175,25 +177,41 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
mLastIndicesCount = mIndicesCount;
mLastIndicesIndex = mIndicesIndex;
+ mImportanceToCamera = 0.f ;
+ mBoundingSphereRadius = 0.0f ;
+
mAtlasInfop = NULL ;
mUsingAtlas = FALSE ;
+ mHasMedia = FALSE ;
}
+static LLFastTimer::DeclareTimer FTM_DESTROY_FACE("Destroy Face");
+static LLFastTimer::DeclareTimer FTM_DESTROY_TEXTURE("Texture");
+static LLFastTimer::DeclareTimer FTM_DESTROY_DRAWPOOL("Drawpool");
+static LLFastTimer::DeclareTimer FTM_DESTROY_TEXTURE_MATRIX("Texture Matrix");
+static LLFastTimer::DeclareTimer FTM_DESTROY_DRAW_INFO("Draw Info");
+static LLFastTimer::DeclareTimer FTM_DESTROY_ATLAS("Atlas");
+static LLFastTimer::DeclareTimer FTM_FACE_DEREF("Deref");
void LLFace::destroy()
{
+ LLFastTimer t(FTM_DESTROY_FACE);
if(mTexture.notNull())
{
+ LLFastTimer t(FTM_DESTROY_TEXTURE);
mTexture->removeFace(this) ;
}
+
if (mDrawPoolp)
{
+ LLFastTimer t(FTM_DESTROY_DRAWPOOL);
mDrawPoolp->removeFace(this);
mDrawPoolp = NULL;
}
if (mTextureMatrix)
{
+ LLFastTimer t(FTM_DESTROY_TEXTURE_MATRIX);
delete mTextureMatrix;
mTextureMatrix = NULL;
@@ -207,12 +225,22 @@ void LLFace::destroy()
}
}
}
-
- setDrawInfo(NULL);
- removeAtlas();
- mDrawablep = NULL;
- mVObjp = NULL;
+ {
+ LLFastTimer t(FTM_DESTROY_DRAW_INFO);
+ setDrawInfo(NULL);
+ }
+
+ {
+ LLFastTimer t(FTM_DESTROY_ATLAS);
+ removeAtlas();
+ }
+
+ {
+ LLFastTimer t(FTM_FACE_DEREF);
+ mDrawablep = NULL;
+ mVObjp = NULL;
+ }
}
@@ -256,6 +284,7 @@ void LLFace::setPool(LLFacePool* new_pool, LLViewerTexture *texturep)
}
mDrawPoolp = new_pool;
}
+
setTexture(texturep) ;
}
@@ -294,7 +323,8 @@ void LLFace::switchTexture(LLViewerTexture* new_texture)
if(!new_texture)
{
- llerrs << "Can not switch to a null texture." << llendl ;
+ llerrs << "Can not switch to a null texture." << llendl;
+ return;
}
new_texture->addTextureStats(mTexture->getMaxVirtualSize()) ;
@@ -515,8 +545,8 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color)
/* removed in lieu of raycast uv detection
void LLFace::renderSelectedUV()
{
- LLViewerTexture* red_blue_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test1.j2c", TRUE, TRUE);
- LLViewerTexture* green_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test2.tga", TRUE, TRUE);
+ LLViewerTexture* red_blue_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test1.j2c", TRUE, LLViewerTexture::BOOST_UI);
+ LLViewerTexture* green_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test2.tga", TRUE, LLViewerTexture::BOOST_UI);
LLGLSUVSelect object_select;
@@ -750,7 +780,9 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
}
mCenterLocal = (newMin+newMax)*0.5f;
-
+ LLVector3 tmp = (newMin - newMax) ;
+ mBoundingSphereRadius = tmp.length() * 0.5f ;
+
updateCenterAgent();
}
@@ -851,20 +883,31 @@ void LLFace::updateRebuildFlags()
}
}
+static LLFastTimer::DeclareTimer FTM_FACE_GET_GEOM("Face Geom");
+
BOOL LLFace::getGeometryVolume(const LLVolume& volume,
const S32 &f,
const LLMatrix4& mat_vert, const LLMatrix3& mat_normal,
const U16 &index_offset)
{
+ LLFastTimer t(FTM_FACE_GET_GEOM);
const LLVolumeFace &vf = volume.getVolumeFace(f);
S32 num_vertices = (S32)vf.mVertices.size();
- S32 num_indices = (S32)vf.mIndices.size();
+ S32 num_indices = LLPipeline::sUseTriStrips ? (S32)vf.mTriStrip.size() : (S32) vf.mIndices.size();
if (mVertexBuffer.notNull())
{
if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices())
{
- llwarns << "Index buffer overflow!" << llendl;
+ llwarns << "Index buffer overflow!" << llendl;
+ llwarns << "Indices Count: " << mIndicesCount
+ << " VF Num Indices: " << num_indices
+ << " Indices Index: " << mIndicesIndex
+ << " VB Num Indices: " << mVertexBuffer->getNumIndices() << llendl;
+ llwarns << "Last Indices Count: " << mLastIndicesCount
+ << " Last Indices Index: " << mLastIndicesIndex
+ << " Face Index: " << f
+ << " Pool Type: " << mPoolType << llendl;
return FALSE;
}
@@ -1022,17 +1065,20 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
if (rebuild_color)
{
- GLfloat alpha[4] =
- {
- 0.00f,
- 0.25f,
- 0.5f,
- 0.75f
- };
-
- if (getPoolType() != LLDrawPool::POOL_ALPHA && (LLPipeline::sRenderDeferred || (LLPipeline::sRenderBump && tep->getShiny())))
+ if (tep)
{
- color.mV[3] = U8 (alpha[tep->getShiny()] * 255);
+ GLfloat alpha[4] =
+ {
+ 0.00f,
+ 0.25f,
+ 0.5f,
+ 0.75f
+ };
+
+ if (getPoolType() != LLDrawPool::POOL_ALPHA && (LLPipeline::sRenderDeferred || (LLPipeline::sRenderBump && tep->getShiny())))
+ {
+ color.mV[3] = U8 (alpha[tep->getShiny()] * 255);
+ }
}
}
@@ -1040,9 +1086,19 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
if (full_rebuild)
{
mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
- for (S32 i = 0; i < num_indices; i++)
+ if (LLPipeline::sUseTriStrips)
{
- *indicesp++ = vf.mIndices[i] + index_offset;
+ for (U32 i = 0; i < (U32) num_indices; i++)
+ {
+ *indicesp++ = vf.mTriStrip[i] + index_offset;
+ }
+ }
+ else
+ {
+ for (U32 i = 0; i < (U32) num_indices; i++)
+ {
+ *indicesp++ = vf.mIndices[i] + index_offset;
+ }
}
}
@@ -1305,6 +1361,193 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
return TRUE;
}
+//check if the face has a media
+BOOL LLFace::hasMedia() const
+{
+ if(mHasMedia)
+ {
+ return TRUE ;
+ }
+ if(mTexture.notNull())
+ {
+ return mTexture->hasParcelMedia() ; //if has a parcel media
+ }
+
+ return FALSE ; //no media.
+}
+
+const F32 LEAST_IMPORTANCE = 0.05f ;
+const F32 LEAST_IMPORTANCE_FOR_LARGE_IMAGE = 0.3f ;
+
+F32 LLFace::getTextureVirtualSize()
+{
+ F32 radius;
+ F32 cos_angle_to_view_dir;
+ BOOL in_frustum = calcPixelArea(cos_angle_to_view_dir, radius);
+
+ if (mPixelArea < 0.0001f || !in_frustum)
+ {
+ setVirtualSize(0.f) ;
+ return 0.f;
+ }
+
+ //get area of circle in texture space
+ LLVector2 tdim = mTexExtents[1] - mTexExtents[0];
+ F32 texel_area = (tdim * 0.5f).lengthSquared()*3.14159f;
+ if (texel_area <= 0)
+ {
+ // Probably animated, use default
+ texel_area = 1.f;
+ }
+
+ //apply texel area to face area to get accurate ratio
+ //face_area /= llclamp(texel_area, 1.f/64.f, 16.f);
+ F32 face_area = mPixelArea / llclamp(texel_area, 0.015625f, 128.f);
+
+ if(face_area > LLViewerTexture::sMaxSmallImageSize)
+ {
+ if(mImportanceToCamera < LEAST_IMPORTANCE) //if the face is not important, do not load hi-res.
+ {
+ static const F32 MAX_LEAST_IMPORTANCE_IMAGE_SIZE = 128.0f * 128.0f ;
+ face_area = llmin(face_area * 0.5f, MAX_LEAST_IMPORTANCE_IMAGE_SIZE) ;
+ }
+ else if(face_area > LLViewerTexture::sMinLargeImageSize) //if is large image, shrink face_area by considering the partial overlapping.
+ {
+ if(mImportanceToCamera < LEAST_IMPORTANCE_FOR_LARGE_IMAGE)//if the face is not important, do not load hi-res.
+ {
+ face_area = LLViewerTexture::sMinLargeImageSize ;
+ }
+ else if(mTexture.notNull() && mTexture->isLargeImage())
+ {
+ face_area *= adjustPartialOverlapPixelArea(cos_angle_to_view_dir, radius );
+ }
+ }
+ }
+
+ setVirtualSize(face_area) ;
+
+ return face_area;
+}
+
+BOOL LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
+{
+ //get area of circle around face
+ LLVector3 center = getPositionAgent();
+ LLVector3 size = (mExtents[1] - mExtents[0]) * 0.5f;
+ LLViewerCamera* camera = LLViewerCamera::getInstance();
+
+ F32 size_squared = size.lengthSquared() ;
+ LLVector3 lookAt = center - camera->getOrigin();
+ F32 dist = lookAt.normVec() ;
+
+ //get area of circle around node
+ F32 app_angle = atanf(fsqrtf(size_squared) / dist);
+ radius = app_angle*LLDrawable::sCurPixelAngle;
+ mPixelArea = radius*radius * 3.14159f;
+ cos_angle_to_view_dir = lookAt * camera->getXAxis() ;
+
+ //if has media, check if the face is out of the view frustum.
+ if(hasMedia())
+ {
+ if(!camera->AABBInFrustum(center, size))
+ {
+ mImportanceToCamera = 0.f ;
+ return false ;
+ }
+ if(cos_angle_to_view_dir > camera->getCosHalfFov()) //the center is within the view frustum
+ {
+ cos_angle_to_view_dir = 1.0f ;
+ }
+ else
+ {
+ if(dist * dist * (lookAt - camera->getXAxis()).lengthSquared() < size_squared)
+ {
+ cos_angle_to_view_dir = 1.0f ;
+ }
+ }
+ }
+
+ if(dist < mBoundingSphereRadius) //camera is very close
+ {
+ cos_angle_to_view_dir = 1.0f ;
+ mImportanceToCamera = 1.0f ;
+ }
+ else
+ {
+ mImportanceToCamera = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
+ }
+
+ return true ;
+}
+
+//the projection of the face partially overlaps with the screen
+F32 LLFace::adjustPartialOverlapPixelArea(F32 cos_angle_to_view_dir, F32 radius )
+{
+ F32 screen_radius = (F32)llmax(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()) ;
+ F32 center_angle = acosf(cos_angle_to_view_dir) ;
+ F32 d = center_angle * LLDrawable::sCurPixelAngle ;
+
+ if(d + radius > screen_radius + 5.f)
+ {
+ //----------------------------------------------
+ //calculate the intersection area of two circles
+ //F32 radius_square = radius * radius ;
+ //F32 d_square = d * d ;
+ //F32 screen_radius_square = screen_radius * screen_radius ;
+ //face_area =
+ // radius_square * acosf((d_square + radius_square - screen_radius_square)/(2 * d * radius)) +
+ // screen_radius_square * acosf((d_square + screen_radius_square - radius_square)/(2 * d * screen_radius)) -
+ // 0.5f * sqrtf((-d + radius + screen_radius) * (d + radius - screen_radius) * (d - radius + screen_radius) * (d + radius + screen_radius)) ;
+ //----------------------------------------------
+
+ //the above calculation is too expensive
+ //the below is a good estimation: bounding box of the bounding sphere:
+ F32 alpha = 0.5f * (radius + screen_radius - d) / radius ;
+ alpha = llclamp(alpha, 0.f, 1.f) ;
+ return alpha * alpha ;
+ }
+ return 1.0f ;
+}
+
+const S8 FACE_IMPORTANCE_LEVEL = 4 ;
+const F32 FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL][2] = //{distance, importance_weight}
+ {{16.1f, 1.0f}, {32.1f, 0.5f}, {48.1f, 0.2f}, {96.1f, 0.05f} } ;
+const F32 FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[FACE_IMPORTANCE_LEVEL][2] = //{cos(angle), importance_weight}
+ {{0.985f /*cos(10 degrees)*/, 1.0f}, {0.94f /*cos(20 degrees)*/, 0.8f}, {0.866f /*cos(30 degrees)*/, 0.64f}, {0.0f, 0.36f}} ;
+
+//static
+F32 LLFace::calcImportanceToCamera(F32 cos_angle_to_view_dir, F32 dist)
+{
+ F32 importance = 0.f ;
+
+ if(cos_angle_to_view_dir > LLViewerCamera::getInstance()->getCosHalfFov() &&
+ dist < FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL - 1][0])
+ {
+ LLViewerCamera* camera = LLViewerCamera::getInstance();
+ F32 camera_moving_speed = camera->getAverageSpeed() ;
+ F32 camera_angular_speed = camera->getAverageAngularSpeed();
+
+ if(camera_moving_speed > 10.0f || camera_angular_speed > 1.0f)
+ {
+ //if camera moves or rotates too fast, ignore the importance factor
+ return 0.f ;
+ }
+
+ //F32 camera_relative_speed = camera_moving_speed * (lookAt * LLViewerCamera::getInstance()->getVelocityDir()) ;
+
+ S32 i = 0 ;
+ for(i = 0; i < FACE_IMPORTANCE_LEVEL && dist > FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][0]; ++i);
+ i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
+ F32 dist_factor = FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][1] ;
+
+ for(i = 0; i < FACE_IMPORTANCE_LEVEL && cos_angle_to_view_dir < FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][0] ; ++i) ;
+ i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
+ importance = dist_factor * FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][1] ;
+ }
+
+ return importance ;
+}
+
BOOL LLFace::verify(const U32* indices_array) const
{
BOOL ok = TRUE;
@@ -1407,8 +1650,13 @@ S32 LLFace::pushVertices(const U16* index_array) const
{
if (mIndicesCount)
{
- mVertexBuffer->drawRange(LLRender::TRIANGLES, mGeomIndex, mGeomIndex+mGeomCount-1, mIndicesCount, mIndicesIndex);
- gPipeline.addTrianglesDrawn(mIndicesCount/3);
+ U32 render_type = LLRender::TRIANGLES;
+ if (mDrawInfo)
+ {
+ render_type = mDrawInfo->mDrawMode;
+ }
+ mVertexBuffer->drawRange(render_type, mGeomIndex, mGeomIndex+mGeomCount-1, mIndicesCount, mIndicesIndex);
+ gPipeline.addTrianglesDrawn(mIndicesCount, render_type);
}
return mIndicesCount;