diff options
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rw-r--r-- | indra/newview/llviewertexture.cpp | 608 |
1 files changed, 343 insertions, 265 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index 0ad269392d..9b5b210bf7 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -82,7 +82,7 @@ LLTexturePipelineTester* LLViewerTextureManager::sTesterp = NULL ; S32 LLViewerTexture::sImageCount = 0; S32 LLViewerTexture::sRawCount = 0; S32 LLViewerTexture::sAuxCount = 0; -LLTimer LLViewerTexture::sEvaluationTimer; +LLFrameTimer LLViewerTexture::sEvaluationTimer; F32 LLViewerTexture::sDesiredDiscardBias = 0.f; F32 LLViewerTexture::sDesiredDiscardScale = 1.1f; S32 LLViewerTexture::sBoundTextureMemoryInBytes = 0; @@ -102,7 +102,7 @@ F32 LLViewerTexture::sCurrentTime = 0.0f ; BOOL LLViewerTexture::sUseTextureAtlas = FALSE ; const F32 desired_discard_bias_min = -2.0f; // -max number of levels to improve image quality by -const F32 desired_discard_bias_max = 1.5f; // max number of levels to reduce image quality by +const F32 desired_discard_bias_max = (F32)MAX_DISCARD_LEVEL; // max number of levels to reduce image quality by const F64 log_2 = log(2.0); //---------------------------------------------------------------------------------------------- @@ -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); @@ -367,7 +369,7 @@ S32 LLViewerTexture::getCategoryFromIndex(S32 index) } // tuning params -const F32 discard_bias_delta = .05f; +const F32 discard_bias_delta = .25f; const F32 discard_delta_time = 0.5f; const S32 min_non_tex_system_mem = (128<<20); // 128 MB // non-const (used externally @@ -490,13 +492,16 @@ void LLViewerTexture::init(bool firstinit) mTextureState = NO_DELETE ; mDontDiscard = FALSE; + mCanResetMaxVirtualSize = true ; mMaxVirtualSize = 0.f; mNeedsGLTexture = FALSE ; mNeedsResetMaxVirtualSize = FALSE ; mAdditionalDecodePriority = 0.f ; mParcelMedia = NULL ; mNumFaces = 0 ; + mNumVolumes = 0; mFaceList.clear() ; + mVolumeList.clear(); } //virtual @@ -508,7 +513,7 @@ S8 LLViewerTexture::getType() const void LLViewerTexture::cleanup() { mFaceList.clear() ; - + mVolumeList.clear(); if(mGLTexturep) { mGLTexturep->cleanup(); @@ -586,6 +591,11 @@ void LLViewerTexture::forceImmediateUpdate() { } +void LLViewerTexture::setResetMaxVirtualSizeFlag(bool flag) +{ + mCanResetMaxVirtualSize = flag ; +} + void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) const { if(needs_gltexture) @@ -609,7 +619,7 @@ void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) co void LLViewerTexture::resetTextureStats() { - mMaxVirtualSize = 0.0f; + mMaxVirtualSize = 0.0f ; mAdditionalDecodePriority = 0.f ; mNeedsResetMaxVirtualSize = FALSE ; } @@ -661,6 +671,42 @@ 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 @@ -680,6 +726,27 @@ void LLViewerTexture::reorganizeFaceList() 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() { @@ -715,7 +782,7 @@ void LLViewerTexture::generateGLTexture() LLImageGL* LLViewerTexture::getGLTexture() const { - llassert_always(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()) ; return mGLTexturep ; } @@ -732,7 +799,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) ; @@ -740,63 +807,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() ; } @@ -821,124 +894,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() ; } @@ -974,12 +1047,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) @@ -1010,6 +1077,7 @@ void LLViewerFetchedTexture::init(bool firstinit) mRequestedDiscardLevel = -1; mRequestedDownloadPriority = 0.f; mFullyLoaded = FALSE; + mCanUseHTTP = true ; mDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1; mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1; @@ -1196,20 +1264,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. @@ -1217,6 +1295,11 @@ void LLViewerFetchedTexture::addToCreateTexture() mNeedsCreateTexture = FALSE ; destroyRawImage(); } + else if(!force_update && getDiscardLevel() > -1 && getDiscardLevel() <= mRawDiscardLevel) + { + mNeedsCreateTexture = FALSE ; + destroyRawImage(); + } else { #if 1 @@ -1225,7 +1308,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; @@ -1338,24 +1421,7 @@ 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(); @@ -1367,22 +1433,28 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/) //virtual void LLViewerFetchedTexture::setKnownDrawSize(S32 width, S32 height) { - if(mKnownDrawWidth != width || mKnownDrawHeight != height) + if(mKnownDrawWidth < width || mKnownDrawHeight < height) { - mKnownDrawWidth = width; - mKnownDrawHeight = height; + mKnownDrawWidth = llmax(mKnownDrawWidth, width) ; + mKnownDrawHeight = llmax(mKnownDrawHeight, height) ; mKnownDrawSizeChanged = TRUE ; mFullyLoaded = FALSE ; } - addTextureStats((F32)(width * height)); + addTextureStats((F32)(mKnownDrawWidth * mKnownDrawHeight)); } //virtual void LLViewerFetchedTexture::processTextureStats() { - if(mFullyLoaded)//already loaded + if(mFullyLoaded) { + if(mDesiredDiscardLevel <= mMinDesiredDiscardLevel)//already loaded + { + return ; + } + mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ; + mFullyLoaded = FALSE ; return ; } @@ -1416,6 +1488,7 @@ void LLViewerFetchedTexture::processTextureStats() mDesiredDiscardLevel = (S8)llmin(log((F32)mFullWidth / mKnownDrawWidth) / log_2, log((F32)mFullHeight / mKnownDrawHeight) / log_2) ; mDesiredDiscardLevel = llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel()) ; + mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel) ; } mKnownDrawSizeChanged = FALSE ; @@ -1426,6 +1499,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 @@ -1435,41 +1515,36 @@ 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 -1.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; } else if(mDesiredDiscardLevel >= cur_discard && cur_discard > -1) { - priority = -1.0f ; + priority = -2.0f ; } else if(mCachedRawDiscardLevel > -1 && mDesiredDiscardLevel >= mCachedRawDiscardLevel) { - priority = -1.0f; + priority = -3.0f; } else if (mDesiredDiscardLevel > getMaxDiscardLevel()) { // Don't decode anything we don't need - priority = -1.0f; + priority = -4.0f; } else if ((mBoostLevel == LLViewerTexture::BOOST_UI || mBoostLevel == LLViewerTexture::BOOST_ICON) && !have_all_data) { @@ -1483,10 +1558,14 @@ F32 LLViewerFetchedTexture::calcDecodePriority() // Always want high boosted images priority = 1.f; } + else if(mForceToSaveRawImage) + { + //force to fetch the raw image. + priority = 1.f; + } else { - // Leave the priority as-is - return mDecodePriority; + priority = -5.f; //stop fetching } } else if (cur_discard < 0) @@ -1496,17 +1575,13 @@ 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)) { // larger mips are corrupted - priority = -3.0f; - } - else if (cur_discard <= mDesiredDiscardLevel) - { - priority = -4.0f; + priority = -6.0f; } else { @@ -1523,51 +1598,59 @@ F32 LLViewerFetchedTexture::calcDecodePriority() // 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; - //} + 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, -1, 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); // firing a lot, figure out why - if (mInImageList) // above llassert() softened to a warning - { - llwarns << "BAD STUFF! mInImageList" << llendl; - } + llassert(!mInImageList); + mDecodePriority = priority; } @@ -1587,6 +1670,11 @@ void LLViewerFetchedTexture::updateVirtualSize() addTextureStats(0.f, FALSE) ;//reset } + if(mForceToSaveRawImage) + { + setAdditionalDecodePriority(0.75f) ; //boost the fetching priority + } + for(U32 i = 0 ; i < mNumFaces ; i++) { LLFace* facep = mFaceList[i] ; @@ -1596,8 +1684,31 @@ void LLViewerFetchedTexture::updateVirtualSize() setAdditionalDecodePriority(facep->getImportanceToCamera()) ; } } - mNeedsResetMaxVirtualSize = TRUE ; + + if(mCanResetMaxVirtualSize) + { + 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() @@ -1636,7 +1747,7 @@ 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); @@ -1646,14 +1757,6 @@ bool LLViewerFetchedTexture::updateFetch() // 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); @@ -1666,7 +1769,7 @@ bool LLViewerFetchedTexture::updateFetch() else { mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority, - mFetchPriority, mFetchDeltaTime, mRequestDeltaTime); + mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP); } // We may have data ready regardless of whether or not we are finished (e.g. waiting on write) @@ -1681,18 +1784,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(U32 i = 0 ; i < mNumFaces ; i++) - { - mFaceList[i]->dirtyTexture() ; - } - } mFullWidth = mRawImage->getWidth() << mRawDiscardLevel; mFullHeight = mRawImage->getHeight() << mRawDiscardLevel; @@ -1758,18 +1849,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) { @@ -1787,8 +1866,20 @@ bool LLViewerFetchedTexture::updateFetch() //{ // make_request = false; //} - else + + 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) @@ -1808,17 +1899,23 @@ 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); c = mComponents; } + + const U32 override_tex_discard_level = gSavedSettings.getU32("TextureDiscardLevel"); + if (override_tex_discard_level != 0) + { + desired_discard = override_tex_discard_level; + } // bypass texturefetch directly by pulling from LLTextureCache bool fetch_request_created = false; fetch_request_created = LLAppViewer::getTextureFetch()->createRequest(mUrl, getID(),getTargetHost(), decode_priority, - w, h, c, desired_discard, needsAux()); + w, h, c, desired_discard, needsAux(), mCanUseHTTP); if (fetch_request_created) { @@ -1826,7 +1923,7 @@ bool LLViewerFetchedTexture::updateFetch() mIsFetching = TRUE; mRequestedDiscardLevel = desired_discard; mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority, - mFetchPriority, mFetchDeltaTime, mRequestDeltaTime); + mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP); } // if createRequest() failed, we're finishing up a request for this UUID, @@ -1849,73 +1946,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(); - } - setDecodePriority(maxDecodePriority()) ; - fetch_request_created = LLAppViewer::getTextureFetch()->createRequest(mUrl, getID(),getTargetHost(), getDecodePriority(), - 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()) @@ -1957,6 +1987,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 @@ -2030,10 +2064,13 @@ bool LLViewerFetchedTexture::doLoadedCallbacks() bool run_raw_callbacks = false; bool need_readback = false; + mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1; for(callback_list_t::iterator iter = mLoadedCallbackList.begin(); iter != mLoadedCallbackList.end(); ) { LLLoadedCallbackEntry *entryp = *iter++; + mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, (S8)entryp->mDesiredDiscard) ; + if (entryp->mNeedsImageRaw) { if (mNeedsAux) @@ -2165,6 +2202,7 @@ bool LLViewerFetchedTexture::doLoadedCallbacks() if (mLoadedCallbackList.empty()) { gTextureList.mCallbackList.erase(this); + mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1; } // Done with any raw image data at this point (will be re-created if we still have callbacks) @@ -2205,8 +2243,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 @@ -2216,13 +2261,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 ; } } @@ -2238,24 +2288,22 @@ void LLViewerFetchedTexture::destroyRawImage() if (mRawImage.notNull()) { - sRawCount--; - setCachedRawImage() ; + sRawCount--; - if(mForceToSaveRawImage) + if(mIsRawImageValid) { - saveRawImage() ; - } + 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. @@ -2282,6 +2330,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) @@ -2330,17 +2390,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 ; } } @@ -2361,7 +2416,7 @@ void LLViewerFetchedTexture::checkCachedRawSculptImage() void LLViewerFetchedTexture::saveRawImage() { - if(mRawImage.isNull() || mSavedRawDiscardLevel == mRawDiscardLevel) + if(mRawImage.isNull() || mRawImage == mSavedRawImage || (mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= mRawDiscardLevel)) { return ; } @@ -2379,12 +2434,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() @@ -2410,7 +2475,7 @@ BOOL LLViewerFetchedTexture::hasSavedRawImage() const F32 LLViewerFetchedTexture::getElapsedLastReferencedSavedRawImageTime() const { - return mLastReferencedSavedRawImageTime - sCurrentTime ; + return sCurrentTime - mLastReferencedSavedRawImageTime ; } //---------------------------------------------------------------------------------------------- //atlasing @@ -2687,7 +2752,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) ; @@ -2707,7 +2772,7 @@ void LLViewerLODTexture::processTextureStats() mCalculatedDiscardLevel = discard_level; } } - if (mBoostLevel < LLViewerTexture::BOOST_HIGH) + if (mBoostLevel < LLViewerTexture::BOOST_SCULPTED) { discard_level += sDesiredDiscardBias; discard_level *= sDesiredDiscardScale; // scale @@ -2733,8 +2798,7 @@ void LLViewerLODTexture::processTextureStats() // S32 current_discard = getDiscardLevel(); - if ((sDesiredDiscardBias > 0.0f) && - (current_discard >= 0 && mDesiredDiscardLevel >= current_discard)) + if (sDesiredDiscardBias > 0.0f && mBoostLevel < LLViewerTexture::BOOST_SCULPTED && current_discard >= 0) { // Limit the amount of GL memory bound each frame if ( BYTES_TO_MEGA_BYTES(sBoundTextureMemoryInBytes) > sMaxBoundTextureMemInMegaBytes * texmem_middle_bound_scale && @@ -2751,6 +2815,11 @@ void LLViewerLODTexture::processTextureStats() } } } + + if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0) + { + mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel) ; + } } void LLViewerLODTexture::scaleDown() @@ -2873,12 +2942,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) ; } @@ -2983,6 +3051,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. @@ -2993,14 +3065,16 @@ 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) ; @@ -3250,8 +3324,12 @@ F32 LLViewerMediaTexture::getMaxVirtualSize() } } - mNeedsResetMaxVirtualSize = TRUE ; + if(mCanResetMaxVirtualSize) + { + mNeedsResetMaxVirtualSize = TRUE ; + } reorganizeFaceList() ; + reorganizeVolumeList(); return mMaxVirtualSize ; } |