summaryrefslogtreecommitdiff
path: root/indra/newview/llviewertexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rw-r--r--indra/newview/llviewertexture.cpp695
1 files changed, 399 insertions, 296 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index ae9db94000..01d437f9eb 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -293,6 +293,8 @@ void LLViewerTextureManager::init()
}
}
imagep->createGLTexture(0, image_raw);
+ //cache the raw image
+ imagep->setCachedRawImage(0, image_raw) ;
image_raw = NULL;
#else
LLViewerFetchedTexture::sDefaultImagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, TRUE, LLViewerTexture::BOOST_UI);
@@ -495,6 +497,10 @@ void LLViewerTexture::init(bool firstinit)
mNeedsResetMaxVirtualSize = FALSE ;
mAdditionalDecodePriority = 0.f ;
mParcelMedia = NULL ;
+ mNumFaces = 0 ;
+ mNumVolumes = 0;
+ mFaceList.clear() ;
+ mVolumeList.clear();
}
//virtual
@@ -506,7 +512,7 @@ S8 LLViewerTexture::getType() const
void LLViewerTexture::cleanup()
{
mFaceList.clear() ;
-
+ mVolumeList.clear();
if(mGLTexturep)
{
mGLTexturep->cleanup();
@@ -627,16 +633,115 @@ void LLViewerTexture::setKnownDrawSize(S32 width, S32 height)
//virtual
void LLViewerTexture::addFace(LLFace* facep)
{
- mFaceList.push_back(facep) ;
+ if(mNumFaces >= mFaceList.size())
+ {
+ mFaceList.resize(2 * mNumFaces + 1) ;
+ }
+ mFaceList[mNumFaces] = facep ;
+ facep->setIndexInTex(mNumFaces) ;
+ mNumFaces++ ;
+ mLastFaceListUpdateTimer.reset() ;
}
//virtual
void LLViewerTexture::removeFace(LLFace* facep)
{
- mFaceList.remove(facep) ;
+ if(mNumFaces > 1)
+ {
+ S32 index = facep->getIndexInTex() ;
+ mFaceList[index] = mFaceList[--mNumFaces] ;
+ mFaceList[index]->setIndexInTex(index) ;
+ }
+ else
+ {
+ mFaceList.clear() ;
+ mNumFaces = 0 ;
+ }
+ mLastFaceListUpdateTimer.reset() ;
+}
+
+S32 LLViewerTexture::getNumFaces() const
+{
+ return mNumFaces ;
+}
+
+
+//virtual
+void LLViewerTexture::addVolume(LLVOVolume* volumep)
+{
+ if( mNumVolumes >= mVolumeList.size())
+ {
+ mVolumeList.resize(2 * mNumVolumes + 1) ;
+ }
+ mVolumeList[mNumVolumes] = volumep ;
+ volumep->setIndexInTex(mNumVolumes) ;
+ mNumVolumes++ ;
+ mLastVolumeListUpdateTimer.reset() ;
}
//virtual
+void LLViewerTexture::removeVolume(LLVOVolume* volumep)
+{
+ if(mNumVolumes > 1)
+ {
+ S32 index = volumep->getIndexInTex() ;
+ mVolumeList[index] = mVolumeList[--mNumVolumes] ;
+ mVolumeList[index]->setIndexInTex(index) ;
+ }
+ else
+ {
+ mVolumeList.clear() ;
+ mNumVolumes = 0 ;
+ }
+ mLastVolumeListUpdateTimer.reset() ;
+}
+
+S32 LLViewerTexture::getNumVolumes() const
+{
+ return mNumVolumes ;
+}
+
+void LLViewerTexture::reorganizeFaceList()
+{
+ static const F32 MAX_WAIT_TIME = 20.f; // seconds
+ static const U32 MAX_EXTRA_BUFFER_SIZE = 4 ;
+
+ if(mNumFaces + MAX_EXTRA_BUFFER_SIZE > mFaceList.size())
+ {
+ return ;
+ }
+
+ if(mLastFaceListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
+ {
+ return ;
+ }
+
+ mLastFaceListUpdateTimer.reset() ;
+ mFaceList.erase(mFaceList.begin() + mNumFaces, mFaceList.end());
+}
+
+void LLViewerTexture::reorganizeVolumeList()
+{
+ static const F32 MAX_WAIT_TIME = 20.f; // seconds
+ static const U32 MAX_EXTRA_BUFFER_SIZE = 4 ;
+
+ if(mNumVolumes + MAX_EXTRA_BUFFER_SIZE > mVolumeList.size())
+ {
+ return ;
+ }
+
+ if(mLastVolumeListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
+ {
+ return ;
+ }
+
+ mLastVolumeListUpdateTimer.reset() ;
+ mVolumeList.erase(mVolumeList.begin() + mNumVolumes, mVolumeList.end());
+}
+
+
+
+//virtual
void LLViewerTexture::switchToCachedImage()
{
//nothing here.
@@ -671,7 +776,7 @@ void LLViewerTexture::generateGLTexture()
LLImageGL* LLViewerTexture::getGLTexture() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep ;
}
@@ -688,7 +793,7 @@ BOOL LLViewerTexture::createGLTexture()
BOOL LLViewerTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ;
@@ -696,63 +801,69 @@ BOOL LLViewerTexture::createGLTexture(S32 discard_level, const LLImageRaw* image
{
mFullWidth = mGLTexturep->getCurrentWidth() ;
mFullHeight = mGLTexturep->getCurrentHeight() ;
- mComponents = mGLTexturep->getComponents() ;
+ mComponents = mGLTexturep->getComponents() ;
}
return ret ;
}
+//virtual
+void LLViewerTexture::setCachedRawImage(S32 discard_level, LLImageRaw* imageraw)
+{
+ //nothing here.
+}
+
void LLViewerTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ;
}
void LLViewerTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
mGLTexturep->setAddressMode(mode) ;
}
void LLViewerTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
mGLTexturep->setFilteringOption(option) ;
}
//virtual
S32 LLViewerTexture::getWidth(S32 discard_level) const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getWidth(discard_level) ;
}
//virtual
S32 LLViewerTexture::getHeight(S32 discard_level) const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getHeight(discard_level) ;
}
S32 LLViewerTexture::getMaxDiscardLevel() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getMaxDiscardLevel() ;
}
S32 LLViewerTexture::getDiscardLevel() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getDiscardLevel() ;
}
S8 LLViewerTexture::getComponents() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getComponents() ;
}
LLGLuint LLViewerTexture::getTexName() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getTexName() ;
}
@@ -777,124 +888,124 @@ BOOL LLViewerTexture::getBoundRecently() const
LLTexUnit::eTextureType LLViewerTexture::getTarget(void) const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getTarget() ;
}
BOOL LLViewerTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height) ;
}
BOOL LLViewerTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height) ;
}
void LLViewerTexture::setGLTextureCreated (bool initialized)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
mGLTexturep->setGLTextureCreated (initialized) ;
}
void LLViewerTexture::setCategory(S32 category)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
mGLTexturep->setCategory(category) ;
}
LLTexUnit::eTextureAddressMode LLViewerTexture::getAddressMode(void) const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getAddressMode() ;
}
S32 LLViewerTexture::getTextureMemory() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->mTextureMemory ;
}
LLGLenum LLViewerTexture::getPrimaryFormat() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getPrimaryFormat() ;
}
BOOL LLViewerTexture::getIsAlphaMask() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getIsAlphaMask() ;
}
BOOL LLViewerTexture::getMask(const LLVector2 &tc)
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getMask(tc) ;
}
F32 LLViewerTexture::getTimePassedSinceLastBound()
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getTimePassedSinceLastBound() ;
}
BOOL LLViewerTexture::getMissed() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getMissed() ;
}
BOOL LLViewerTexture::isJustBound() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->isJustBound() ;
}
void LLViewerTexture::forceUpdateBindStats(void) const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->forceUpdateBindStats() ;
}
U32 LLViewerTexture::getTexelsInAtlas() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getTexelsInAtlas() ;
}
U32 LLViewerTexture::getTexelsInGLTexture() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getTexelsInGLTexture() ;
}
BOOL LLViewerTexture::isGLTextureCreated() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->isGLTextureCreated() ;
}
S32 LLViewerTexture::getDiscardLevelInAtlas() const
{
- llassert_always(mGLTexturep.notNull()) ;
+ llassert(mGLTexturep.notNull()) ;
return mGLTexturep->getDiscardLevelInAtlas() ;
}
@@ -930,12 +1041,6 @@ void LLViewerTexture::updateBindStatsForTester()
//start of LLViewerFetchedTexture
//----------------------------------------------------------------------------------------------
-//static
-F32 LLViewerFetchedTexture::maxDecodePriority()
-{
- return 6000000.f;
-}
-
LLViewerFetchedTexture::LLViewerFetchedTexture(const LLUUID& id, const LLHost& host, BOOL usemipmaps)
: LLViewerTexture(id, usemipmaps),
mTargetHost(host)
@@ -985,6 +1090,8 @@ void LLViewerFetchedTexture::init(bool firstinit)
// does not contain this image.
mIsMissingAsset = FALSE;
+ mLoadedCallbackDesiredDiscardLevel = 0;
+
mNeedsCreateTexture = FALSE;
mIsRawImageValid = FALSE;
@@ -997,6 +1104,7 @@ void LLViewerFetchedTexture::init(bool firstinit)
mFetchPriority = 0;
mDownloadProgress = 0.f;
mFetchDeltaTime = 999999.f;
+ mRequestDeltaTime = 0.f;
mForSculpt = FALSE ;
mIsFetched = FALSE ;
@@ -1149,20 +1257,30 @@ void LLViewerFetchedTexture::destroyTexture()
mFullyLoaded = FALSE ;
}
-//
-//do not change the discard level of the loaded texture image.
-BOOL LLViewerFetchedTexture::keepReuestedDiscardLevel()
+void LLViewerFetchedTexture::addToCreateTexture()
{
- if (!mLoadedCallbackList.empty())
+ bool force_update = false ;
+ if (getComponents() != mRawImage->getComponents())
{
- return TRUE ;
- }
+ // We've changed the number of components, so we need to move any
+ // objects using this pool to a different pool.
+ mComponents = mRawImage->getComponents();
+ mGLTexturep->setComponents(mComponents) ;
+ force_update = true ;
- return FALSE ;
-}
+ for(U32 i = 0 ; i < mNumFaces ; i++)
+ {
+ mFaceList[i]->dirtyTexture() ;
+ }
+
+ //discard the cached raw image and the saved raw image
+ mCachedRawImageReady = FALSE ;
+ mCachedRawDiscardLevel = -1 ;
+ mCachedRawImage = NULL ;
+ mSavedRawDiscardLevel = -1 ;
+ mSavedRawImage = NULL ;
+ }
-void LLViewerFetchedTexture::addToCreateTexture()
-{
if(isForSculptOnly())
{
//just update some variables, not to create a real GL texture.
@@ -1170,6 +1288,11 @@ void LLViewerFetchedTexture::addToCreateTexture()
mNeedsCreateTexture = FALSE ;
destroyRawImage();
}
+ else if(!force_update && getDiscardLevel() > -1 && getDiscardLevel() <= mRawDiscardLevel)
+ {
+ mNeedsCreateTexture = FALSE ;
+ destroyRawImage();
+ }
else
{
#if 1
@@ -1178,7 +1301,7 @@ void LLViewerFetchedTexture::addToCreateTexture()
//so do not scale down the over qualified image.
//Note: scaling down image is expensensive. Do it only when very necessary.
//
- if(mRequestedDiscardLevel <= mDesiredDiscardLevel && !keepReuestedDiscardLevel())
+ if(mRequestedDiscardLevel <= mDesiredDiscardLevel && !mForceToSaveRawImage)
{
S32 w = mFullWidth >> mRawDiscardLevel;
S32 h = mFullHeight >> mRawDiscardLevel;
@@ -1291,28 +1414,12 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
setActive() ;
}
- //
- // Iterate through the list of image loading callbacks to see
- // what sort of data they need.
- //
- // *TODO: Fix image callback code
- BOOL imageraw_callbacks = FALSE;
- for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
- iter != mLoadedCallbackList.end(); )
- {
- LLLoadedCallbackEntry *entryp = *iter++;
- if (entryp->mNeedsImageRaw)
- {
- imageraw_callbacks = TRUE;
- break;
- }
- }
-
- if (!imageraw_callbacks)
+ if (!mForceToSaveRawImage)
{
mNeedsAux = FALSE;
- destroyRawImage();
}
+ destroyRawImage();
+
return res;
}
@@ -1379,6 +1486,13 @@ void LLViewerFetchedTexture::processTextureStats()
}
}
+const F32 MAX_PRIORITY_PIXEL = 999.f ; //pixel area
+const F32 PRIORITY_BOOST_LEVEL_FACTOR = 1000.f ; //boost level
+const F32 PRIORITY_DELTA_DISCARD_LEVEL_FACTOR = 100000.f ; //delta discard
+const S32 MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY = 4 ;
+const F32 PRIORITY_ADDITIONAL_FACTOR = 1000000.f ; //additional
+const S32 MAX_ADDITIONAL_LEVEL_FOR_PRIORITY = 8 ;
+const F32 PRIORITY_BOOST_HIGH_FACTOR = 10000000.f ;//boost high
F32 LLViewerFetchedTexture::calcDecodePriority()
{
#ifndef LL_RELEASE_FOR_DOWNLOAD
@@ -1388,25 +1502,20 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
}
#endif
- if(mFullyLoaded)//already loaded for static texture
- {
- return -4.0f ; //alreay fetched
- }
-
if (mNeedsCreateTexture)
{
return mDecodePriority; // no change while waiting to create
}
- if(mForceToSaveRawImage)
+ if(mFullyLoaded && !mForceToSaveRawImage)//already loaded for static texture
{
- return maxDecodePriority() ;
+ return -4.0f ; //alreay fetched
}
-
- S32 cur_discard = getDiscardLevel();
+
+ S32 cur_discard = getCurrentDiscardLevelForFetching();
bool have_all_data = (cur_discard >= 0 && (cur_discard <= mDesiredDiscardLevel));
F32 pixel_priority = fsqrtf(mMaxVirtualSize);
- F32 priority;
+ F32 priority = 0.f;
if (mIsMissingAsset)
{
priority = 0.0f;
@@ -1449,8 +1558,8 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
static const F64 log_2 = log(2.0);
F32 desired = (F32)(log(32.0/pixel_priority) / log_2);
S32 ddiscard = MAX_DISCARD_LEVEL - (S32)desired;
- ddiscard = llclamp(ddiscard, 0, 4);
- priority = (ddiscard+1)*100000.f;
+ ddiscard = llclamp(ddiscard, 0, MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY);
+ priority = (ddiscard + 1) * PRIORITY_DELTA_DISCARD_LEVEL_FACTOR;
}
else if ((mMinDiscardLevel > 0) && (cur_discard <= mMinDiscardLevel))
{
@@ -1469,50 +1578,66 @@ F32 LLViewerFetchedTexture::calcDecodePriority()
{
desired_discard -= 2;
}
- else if (!isJustBound() && mCachedRawImageReady && !mBoostLevel)
- {
- // We haven't rendered this in the last half second, and we have a cached raw image, leave the desired discard as-is
- desired_discard = cur_discard;
- }
- else if (mGLTexturep.notNull() && !mGLTexturep->getBoundRecently() && mBoostLevel == LLViewerTexture::BOOST_NONE)
+ else if (!isJustBound() && mCachedRawImageReady)
{
- // We haven't rendered this in a while, de-prioritize it
- desired_discard += 2;
+ //if(mBoostLevel < BOOST_HIGH)
+ //{
+ // // We haven't rendered this in a while, de-prioritize it
+ // desired_discard += 2;
+ //}
+ //else
+ {
+ // We haven't rendered this in the last half second, and we have a cached raw image, leave the desired discard as-is
+ desired_discard = cur_discard;
+ }
}
+
S32 ddiscard = cur_discard - desired_discard;
- ddiscard = llclamp(ddiscard, 0, 4);
- priority = (ddiscard+1)*100000.f;
+ ddiscard = llclamp(ddiscard, 0, MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY);
+ priority = (ddiscard + 1) * PRIORITY_DELTA_DISCARD_LEVEL_FACTOR;
}
// Priority Formula:
// BOOST_HIGH + ADDITIONAL PRI + DELTA DISCARD + BOOST LEVEL + PIXELS
- // [10,000,000] + [1-9,000,000] + [1-400,000] + [1-20,000] + [0-999]
+ // [10,000,000] + [1,000,000-9,000,000] + [100,000-500,000] + [1-20,000] + [0-999]
if (priority > 0.0f)
{
- pixel_priority = llclamp(pixel_priority, 0.0f, 999.f);
+ pixel_priority = llclamp(pixel_priority, 0.0f, MAX_PRIORITY_PIXEL);
- priority = pixel_priority + 1000.f * mBoostLevel;
+ priority += pixel_priority + PRIORITY_BOOST_LEVEL_FACTOR * mBoostLevel;
if ( mBoostLevel > BOOST_HIGH)
{
- priority += 10000000.f;
+ priority += PRIORITY_BOOST_HIGH_FACTOR;
}
if(mAdditionalDecodePriority > 0.0f)
{
- // 1-9
- S32 additional_priority = (S32)(1.0f + mAdditionalDecodePriority*8.0f + .5f); // round
- // priority range += 0-9,000,000
- priority += 1000000.f * (F32)additional_priority;
+ // priority range += 1,000,000.f-9,000,000.f
+ priority += PRIORITY_ADDITIONAL_FACTOR * (1.0 + mAdditionalDecodePriority * MAX_ADDITIONAL_LEVEL_FOR_PRIORITY);
}
}
return priority;
}
+
+//static
+F32 LLViewerFetchedTexture::maxDecodePriority()
+{
+ static const F32 max_priority = PRIORITY_BOOST_HIGH_FACTOR + //boost_high
+ PRIORITY_ADDITIONAL_FACTOR * (MAX_ADDITIONAL_LEVEL_FOR_PRIORITY + 1) + //additional (view dependent factors)
+ PRIORITY_DELTA_DISCARD_LEVEL_FACTOR * (MAX_DELTA_DISCARD_LEVEL_FOR_PRIORITY + 1) + //delta discard
+ PRIORITY_BOOST_LEVEL_FACTOR * (BOOST_MAX_LEVEL - 1) + //boost level
+ MAX_PRIORITY_PIXEL + 1.0f ; //pixel area.
+
+ return max_priority ;
+}
+
//============================================================================
void LLViewerFetchedTexture::setDecodePriority(F32 priority)
{
- llassert(!mInImageList);
+ llassert(!mInImageList);
+
mDecodePriority = priority;
}
@@ -1531,23 +1656,52 @@ void LLViewerFetchedTexture::updateVirtualSize()
{
addTextureStats(0.f, FALSE) ;//reset
}
- if(mFaceList.size() > 0)
+
+ if(mForceToSaveRawImage)
+ {
+ setAdditionalDecodePriority(0.75f) ; //boost the fetching priority
+ }
+
+ for(U32 i = 0 ; i < mNumFaces ; i++)
{
- for(std::list<LLFace*>::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
+ LLFace* facep = mFaceList[i] ;
+ if(facep->getDrawable()->isRecentlyVisible())
{
- LLFace* facep = *iter ;
- if(facep->getDrawable()->isRecentlyVisible())
- {
- addTextureStats(facep->getVirtualSize()) ;
- setAdditionalDecodePriority(facep->getImportanceToCamera()) ;
- }
- }
+ addTextureStats(facep->getVirtualSize()) ;
+ setAdditionalDecodePriority(facep->getImportanceToCamera()) ;
+ }
}
mNeedsResetMaxVirtualSize = TRUE ;
+ reorganizeFaceList() ;
+ reorganizeVolumeList();
+}
+
+S32 LLViewerFetchedTexture::getCurrentDiscardLevelForFetching()
+{
+ S32 current_discard = getDiscardLevel() ;
+ if(mForceToSaveRawImage)
+ {
+ if(mSavedRawDiscardLevel < 0 || current_discard < 0)
+ {
+ current_discard = -1 ;
+ }
+ else
+ {
+ current_discard = llmax(current_discard, mSavedRawDiscardLevel) ;
+ }
+ }
+
+ return current_discard ;
}
bool LLViewerFetchedTexture::updateFetch()
{
+ static LLCachedControl<bool> textures_decode_disabled(gSavedSettings,"TextureDecodeDisabled");
+ if(textures_decode_disabled)
+ {
+ return false ;
+ }
+
mFetchState = 0;
mFetchPriority = 0;
mFetchDeltaTime = 999999.f;
@@ -1576,24 +1730,16 @@ bool LLViewerFetchedTexture::updateFetch()
return false; // process any raw image data in callbacks before replacing
}
- S32 current_discard = getDiscardLevel() ;
+ S32 current_discard = getCurrentDiscardLevelForFetching() ;
S32 desired_discard = getDesiredDiscardLevel();
F32 decode_priority = getDecodePriority();
decode_priority = llmax(decode_priority, 0.0f);
-
+
if (mIsFetching)
{
// Sets mRawDiscardLevel, mRawImage, mAuxRawImage
S32 fetch_discard = current_discard;
- if(mForceToSaveRawImage)
- {
- if(fetch_discard >= 0)
- {
- fetch_discard = llmax(fetch_discard, mSavedRawDiscardLevel) ;
- }
- }
-
if (mRawImage.notNull()) sRawCount--;
if (mAuxRawImage.notNull()) sAuxCount--;
bool finished = LLAppViewer::getTextureFetch()->getRequestFinished(getID(), fetch_discard, mRawImage, mAuxRawImage);
@@ -1621,18 +1767,6 @@ bool LLViewerFetchedTexture::updateFetch()
if ((mRawImage->getDataSize() > 0 && mRawDiscardLevel >= 0) &&
(current_discard < 0 || mRawDiscardLevel < current_discard))
{
- if (getComponents() != mRawImage->getComponents())
- {
- // We've changed the number of components, so we need to move any
- // objects using this pool to a different pool.
- mComponents = mRawImage->getComponents();
- mGLTexturep->setComponents(mComponents) ;
-
- for(ll_face_list_t::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
- {
- (*iter)->dirtyTexture() ;
- }
- }
mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
@@ -1698,18 +1832,6 @@ bool LLViewerFetchedTexture::updateFetch()
}
}
- if (!mDontDiscard)
- {
- if (mBoostLevel == 0)
- {
- desired_discard = llmax(desired_discard, current_discard-1);
- }
- else
- {
- desired_discard = llmax(desired_discard, current_discard-2);
- }
- }
-
bool make_request = true;
if (decode_priority <= 0)
{
@@ -1723,12 +1845,24 @@ bool LLViewerFetchedTexture::updateFetch()
{
make_request = false;
}
- else if (!isJustBound() && mCachedRawImageReady)
- {
- make_request = false;
- }
- else
+ //else if (!isJustBound() && mCachedRawImageReady)
+ //{
+ // make_request = false;
+ //}
+
+ if(make_request)
{
+ //load the texture progressively.
+ S32 delta_level = (mBoostLevel > LLViewerTexture::BOOST_NONE) ? 2 : 1 ;
+ if(current_discard < 0)
+ {
+ desired_discard = llmax(desired_discard, getMaxDiscardLevel() - delta_level);
+ }
+ else
+ {
+ desired_discard = llmax(desired_discard, current_discard - delta_level);
+ }
+
if (mIsFetching)
{
if (mRequestedDiscardLevel <= desired_discard)
@@ -1748,7 +1882,7 @@ bool LLViewerFetchedTexture::updateFetch()
if (make_request)
{
S32 w=0, h=0, c=0;
- if (current_discard >= 0)
+ if (getDiscardLevel() >= 0)
{
w = mGLTexturep->getWidth(0);
h = mGLTexturep->getHeight(0);
@@ -1789,72 +1923,6 @@ bool LLViewerFetchedTexture::updateFetch()
return mIsFetching ? true : false;
}
-//
-//force to fetch a new raw image for this texture
-//
-BOOL LLViewerFetchedTexture::forceFetch()
-{
- if(!mForceToSaveRawImage)
- {
- return false ;
- }
- if(mDesiredSavedRawDiscardLevel < getDiscardLevel())
- {
- //no need to force fetching. normal fetching flow will do the work.
- //return false ;
- }
- if (mNeedsCreateTexture)
- {
- // We may be fetching still (e.g. waiting on write)
- // but don't check until we've processed the raw data we have
- //return false;
- }
- if(mIsFetching)
- {
- return false ;
- }
- if (mIsMissingAsset)
- {
- mForceToSaveRawImage = false ;
- llassert_always(!mHasFetcher);
- return false; // skip
- }
- if (!mLoadedCallbackList.empty() && mRawImage.notNull())
- {
- return false; // process any raw image data in callbacks before replacing
- }
- if(mRawImage.notNull() && mRawDiscardLevel <= mDesiredSavedRawDiscardLevel)
- {
- return false ; // mRawImage is enough
- }
-
- S32 desired_discard = mDesiredSavedRawDiscardLevel ;
- S32 current_discard = getDiscardLevel();
-
- bool fetch_request_created = false;
- S32 w=0, h=0, c=0;
- if (current_discard >= 0)
- {
- w = getWidth(0);
- h = getHeight(0);
- c = getComponents();
- }
- fetch_request_created = LLAppViewer::getTextureFetch()->createRequest(mUrl, getID(),getTargetHost(), maxDecodePriority(),
- w, h, c, desired_discard, needsAux());
-
- if (fetch_request_created)
- {
- mHasFetcher = TRUE;
- mIsFetching = TRUE;
- mRequestedDiscardLevel = desired_discard ;
-
- mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority,
- mFetchPriority, mFetchDeltaTime, mRequestDeltaTime);
- }
-
- return mIsFetching ? true : false;
-}
-
void LLViewerFetchedTexture::setIsMissingAsset()
{
if (mUrl.empty())
@@ -1896,6 +1964,10 @@ void LLViewerFetchedTexture::setLoadedCallback( loaded_callback_func loaded_call
LLLoadedCallbackEntry* entryp = new LLLoadedCallbackEntry(loaded_callback, discard_level, keep_imageraw, userdata);
mLoadedCallbackList.push_back(entryp);
mNeedsAux |= needs_aux;
+ if(keep_imageraw)
+ {
+ forceToSaveRawImage(discard_level) ;
+ }
if (mNeedsAux && mAuxRawImage.isNull() && getDiscardLevel() >= 0)
{
// We need aux data, but we've already loaded the image, and it didn't have any
@@ -2144,8 +2216,15 @@ LLImageRaw* LLViewerFetchedTexture::reloadRawImage(S8 discard_level)
if(mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= discard_level)
{
- mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents()) ;
- mRawImage->copy(getSavedRawImage()) ;
+ if(mSavedRawDiscardLevel != discard_level)
+ {
+ mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents()) ;
+ mRawImage->copy(getSavedRawImage()) ;
+ }
+ else
+ {
+ mRawImage = getSavedRawImage() ;
+ }
mRawDiscardLevel = discard_level ;
}
else
@@ -2155,13 +2234,18 @@ LLImageRaw* LLViewerFetchedTexture::reloadRawImage(S8 discard_level)
{
mRawImage = mCachedRawImage ;
mRawDiscardLevel = mCachedRawDiscardLevel;
-
- forceToSaveRawImage(discard_level) ;
}
else //cached raw image is good enough, copy it.
{
- mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents()) ;
- mRawImage->copy(mCachedRawImage) ;
+ if(mCachedRawDiscardLevel != discard_level)
+ {
+ mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents()) ;
+ mRawImage->copy(mCachedRawImage) ;
+ }
+ else
+ {
+ mRawImage = mCachedRawImage ;
+ }
mRawDiscardLevel = discard_level ;
}
}
@@ -2177,24 +2261,19 @@ void LLViewerFetchedTexture::destroyRawImage()
if (mRawImage.notNull())
{
- sRawCount--;
- setCachedRawImage() ;
+ sRawCount--;
if(mForceToSaveRawImage)
{
saveRawImage() ;
}
+ setCachedRawImage() ;
}
mRawImage = NULL;
mAuxRawImage = NULL;
mIsRawImageValid = FALSE;
mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-
- if(mForceToSaveRawImage)
- {
- forceFetch() ;
- }
}
//use the mCachedRawImage to (re)generate the gl texture.
@@ -2221,6 +2300,18 @@ void LLViewerFetchedTexture::switchToCachedImage()
}
}
+//cache the imageraw forcefully.
+//virtual
+void LLViewerFetchedTexture::setCachedRawImage(S32 discard_level, LLImageRaw* imageraw)
+{
+ if(imageraw != mRawImage.get())
+ {
+ mCachedRawImage = imageraw ;
+ mCachedRawDiscardLevel = discard_level ;
+ mCachedRawImageReady = TRUE ;
+ }
+}
+
void LLViewerFetchedTexture::setCachedRawImage()
{
if(mRawImage == mCachedRawImage)
@@ -2269,17 +2360,12 @@ void LLViewerFetchedTexture::setCachedRawImage()
{
--i ;
}
- //if(mForSculpt)
- //{
- // mRawImage->scaleDownWithoutBlending(w >> i, h >> i) ;
- //}
- //else
- {
- mRawImage->scale(w >> i, h >> i) ;
- }
+
+ mRawImage->scale(w >> i, h >> i) ;
}
mCachedRawImage = mRawImage ;
- mCachedRawDiscardLevel = mRawDiscardLevel + i ;
+ mRawDiscardLevel += i ;
+ mCachedRawDiscardLevel = mRawDiscardLevel ;
}
}
@@ -2300,7 +2386,7 @@ void LLViewerFetchedTexture::checkCachedRawSculptImage()
void LLViewerFetchedTexture::saveRawImage()
{
- if(mRawImage.isNull() || mSavedRawDiscardLevel == mRawDiscardLevel)
+ if(mRawImage.isNull() || mRawImage == mSavedRawImage || (mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= mRawDiscardLevel))
{
return ;
}
@@ -2318,12 +2404,22 @@ void LLViewerFetchedTexture::saveRawImage()
void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard)
{
- if(!mForceToSaveRawImage && (mDesiredSavedRawDiscardLevel < 0 || mDesiredSavedRawDiscardLevel > desired_discard))
+ if(!mForceToSaveRawImage || mDesiredSavedRawDiscardLevel < 0 || mDesiredSavedRawDiscardLevel > desired_discard)
{
mForceToSaveRawImage = TRUE ;
mDesiredSavedRawDiscardLevel = desired_discard ;
- forceFetch() ;
+ //copy from the cached raw image if exists.
+ if(mCachedRawImage.notNull() && mRawImage.isNull() )
+ {
+ mRawImage = mCachedRawImage ;
+ mRawDiscardLevel = mCachedRawDiscardLevel ;
+
+ saveRawImage() ;
+
+ mRawImage = NULL ;
+ mRawDiscardLevel = INVALID_DISCARD_LEVEL ;
+ }
}
}
void LLViewerFetchedTexture::destroySavedRawImage()
@@ -2349,7 +2445,7 @@ BOOL LLViewerFetchedTexture::hasSavedRawImage() const
F32 LLViewerFetchedTexture::getElapsedLastReferencedSavedRawImageTime() const
{
- return mLastReferencedSavedRawImageTime - sCurrentTime ;
+ return sCurrentTime - mLastReferencedSavedRawImageTime ;
}
//----------------------------------------------------------------------------------------------
//atlasing
@@ -2362,16 +2458,13 @@ void LLViewerFetchedTexture::resetFaceAtlas()
//invalidate all atlas slots for this image.
void LLViewerFetchedTexture::invalidateAtlas(BOOL rebuild_geom)
{
- for(ll_face_list_t::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
+ for(U32 i = 0 ; i < mNumFaces ; i++)
{
- if(*iter)
+ LLFace* facep = mFaceList[i] ;
+ facep->removeAtlas() ;
+ if(rebuild_geom && facep->getDrawable() && facep->getDrawable()->getSpatialGroup())
{
- LLFace* facep = (LLFace*)*iter ;
- facep->removeAtlas() ;
- if(rebuild_geom && facep->getDrawable() && facep->getDrawable()->getSpatialGroup())
- {
- facep->getDrawable()->getSpatialGroup()->setState(LLSpatialGroup::GEOM_DIRTY);
- }
+ facep->getDrawable()->getSpatialGroup()->setState(LLSpatialGroup::GEOM_DIRTY);
}
}
}
@@ -2382,7 +2475,7 @@ BOOL LLViewerFetchedTexture::insertToAtlas()
{
return FALSE ;
}
- if(mFaceList.size() < 1)
+ if(getNumFaces() < 1)
{
return FALSE ;
}
@@ -2406,12 +2499,10 @@ BOOL LLViewerFetchedTexture::insertToAtlas()
//if the atlas slot pointers for some faces are null, process them later.
ll_face_list_t waiting_list ;
-
- for(ll_face_list_t::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
+ for(U32 i = 0 ; i < mNumFaces ; i++)
{
- if(*iter)
{
- facep = (LLFace*)*iter ;
+ facep = mFaceList[i] ;
//face can not use atlas.
if(!facep->canUseAtlas())
@@ -2631,7 +2722,7 @@ void LLViewerLODTexture::processTextureStats()
}
else
{
- if(isLargeImage() && !isJustBound() && mAdditionalDecodePriority < 1.0f)
+ if(isLargeImage() && !isJustBound() && mAdditionalDecodePriority < 0.3f)
{
//if is a big image and not being used recently, nor close to the view point, do not load hi-res data.
mMaxVirtualSize = llmin(mMaxVirtualSize, (F32)LLViewerTexture::sMinLargeImageSize) ;
@@ -2695,6 +2786,11 @@ void LLViewerLODTexture::processTextureStats()
}
}
}
+
+ if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0)
+ {
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel) ;
+ }
}
void LLViewerLODTexture::scaleDown()
@@ -2723,8 +2819,7 @@ void LLViewerMediaTexture::updateClass()
#if 0
//force to play media.
- gSavedSettings.setBOOL("AudioSteamingMedia", true) ;
- gSavedSettings.setBOOL("AudioStreamingVideo", true) ;
+ gSavedSettings.setBOOL("AudioStreamingMedia", true) ;
#endif
for(media_map_t::iterator iter = sMediaMap.begin() ; iter != sMediaMap.end(); )
@@ -2818,12 +2913,11 @@ LLViewerMediaTexture::~LLViewerMediaTexture()
void LLViewerMediaTexture::reinit(BOOL usemipmaps /* = TRUE */)
{
- mGLTexturep = NULL ;
- init(false);
+ llassert(mGLTexturep.notNull()) ;
+
mUseMipMaps = usemipmaps ;
getLastReferencedTimer()->reset() ;
-
- generateGLTexture() ;
+ mGLTexturep->setUseMipMaps(mUseMipMaps) ;
mGLTexturep->setNeedsAlphaAndPickMask(FALSE) ;
}
@@ -2869,9 +2963,10 @@ BOOL LLViewerMediaTexture::findFaces()
if(tex) //this media is a parcel media for tex.
{
const ll_face_list_t* face_list = tex->getFaceList() ;
- for(ll_face_list_t::const_iterator iter = face_list->begin(); iter != face_list->end(); ++iter)
+ U32 end = tex->getNumFaces() ;
+ for(U32 i = 0 ; i < end ; i++)
{
- mMediaFaceList.push_back(*iter) ;
+ mMediaFaceList.push_back((*face_list)[i]) ;
}
}
@@ -2927,6 +3022,10 @@ void LLViewerMediaTexture::initVirtualSize()
void LLViewerMediaTexture::addMediaToFace(LLFace* facep)
{
+ if(facep)
+ {
+ facep->setHasMedia(true) ;
+ }
if(!mIsPlaying)
{
return ; //no need to add the face because the media is not in playing.
@@ -2937,20 +3036,22 @@ void LLViewerMediaTexture::addMediaToFace(LLFace* facep)
void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep)
{
- if(!mIsPlaying)
- {
- return ; //no need to remove the face because the media is not in playing.
- }
if(!facep)
{
return ;
}
+ facep->setHasMedia(false) ;
+
+ if(!mIsPlaying)
+ {
+ return ; //no need to remove the face because the media is not in playing.
+ }
mIsPlaying = FALSE ; //set to remove the media from the face.
switchTexture(facep) ;
mIsPlaying = TRUE ; //set the flag back.
- if(mFaceList.empty()) //no face referencing to this media
+ if(getNumFaces() < 1) //no face referencing to this media
{
stopPlaying() ;
}
@@ -2962,7 +3063,7 @@ void LLViewerMediaTexture::addFace(LLFace* facep)
LLViewerTexture::addFace(facep) ;
const LLTextureEntry* te = facep->getTextureEntry() ;
- if(te)
+ if(te && te->getID().notNull())
{
LLViewerTexture* tex = gTextureList.findImage(te->getID()) ;
if(tex)
@@ -2979,7 +3080,10 @@ void LLViewerMediaTexture::addFace(LLFace* facep)
return ;
}
- llerrs << "The face does not have a valid texture before media texture." << llendl ;
+ if(te && te->getID().notNull()) //should have a texture
+ {
+ llerrs << "The face does not have a valid texture before media texture." << llendl ;
+ }
}
//virtual
@@ -2988,7 +3092,7 @@ void LLViewerMediaTexture::removeFace(LLFace* facep)
LLViewerTexture::removeFace(facep) ;
const LLTextureEntry* te = facep->getTextureEntry() ;
- if(te)
+ if(te && te->getID().notNull())
{
LLViewerTexture* tex = gTextureList.findImage(te->getID()) ;
if(tex)
@@ -3006,17 +3110,17 @@ void LLViewerMediaTexture::removeFace(LLFace* facep)
//
//we have some trouble here: the texture of the face is changed.
//we need to find the former texture, and remove it from the list to avoid memory leaking.
- if(mFaceList.empty())
+ if(!mNumFaces)
{
mTextureList.clear() ;
return ;
}
- S32 end = mFaceList.size() ;
+ S32 end = getNumFaces() ;
std::vector<const LLTextureEntry*> te_list(end) ;
S32 i = 0 ;
- for(ll_face_list_t::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
+ for(U32 j = 0 ; j < mNumFaces ; j++)
{
- te_list[i++] = (*iter)->getTextureEntry() ;//all textures are in use.
+ te_list[i++] = mFaceList[j]->getTextureEntry() ;//all textures are in use.
}
for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
iter != mTextureList.end(); ++iter)
@@ -3049,7 +3153,10 @@ void LLViewerMediaTexture::removeFace(LLFace* facep)
}
}
- llerrs << "mTextureList texture reference number is corrupted." << llendl ;
+ if(te && te->getID().notNull()) //should have a texture
+ {
+ llerrs << "mTextureList texture reference number is corrupted." << llendl ;
+ }
}
void LLViewerMediaTexture::stopPlaying()
@@ -3085,11 +3192,15 @@ void LLViewerMediaTexture::switchTexture(LLFace* facep)
const LLTextureEntry* te = facep->getTextureEntry() ;
if(te)
{
- LLViewerTexture* tex = gTextureList.findImage(te->getID()) ;
+ LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID()) : NULL ;
if(!tex && te->getID() != mID)//try parcel media.
{
tex = gTextureList.findImage(mID) ;
}
+ if(!tex)
+ {
+ tex = LLViewerFetchedTexture::sDefaultImagep ;
+ }
facep->switchTexture(tex) ;
}
}
@@ -3134,16 +3245,9 @@ void LLViewerMediaTexture::setPlaying(BOOL playing)
}
else //stop playing this media
{
- if(mFaceList.empty())
+ for(U32 i = mNumFaces ; i ; i--)
{
- return ;
- }
-
- ll_face_list_t::iterator cur ;
- for(ll_face_list_t::iterator iter = mFaceList.begin(); iter!= mFaceList.end(); )
- {
- cur = iter++ ;
- switchTexture(*cur) ; //cur could be removed in this function.
+ switchTexture(mFaceList[i - 1]) ; //current face could be removed in this function.
}
}
return ;
@@ -3165,17 +3269,14 @@ F32 LLViewerMediaTexture::getMaxVirtualSize()
if(mIsPlaying) //media is playing
{
- if(mFaceList.size() > 0)
- {
- for(std::list<LLFace*>::iterator iter = mFaceList.begin(); iter != mFaceList.end(); ++iter)
+ for(U32 i = 0 ; i < mNumFaces ; i++)
+ {
+ LLFace* facep = mFaceList[i] ;
+ if(facep->getDrawable()->isRecentlyVisible())
{
- LLFace* facep = *iter ;
- if(facep->getDrawable()->isRecentlyVisible())
- {
- addTextureStats(facep->getVirtualSize()) ;
- }
- }
- }
+ addTextureStats(facep->getVirtualSize()) ;
+ }
+ }
}
else //media is not in playing
{
@@ -3195,6 +3296,8 @@ F32 LLViewerMediaTexture::getMaxVirtualSize()
}
mNeedsResetMaxVirtualSize = TRUE ;
+ reorganizeFaceList() ;
+ reorganizeVolumeList();
return mMaxVirtualSize ;
}