diff options
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rwxr-xr-x | indra/newview/llviewertexture.cpp | 367 |
1 files changed, 120 insertions, 247 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index f468df0674..2872c277b1 100755 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -55,8 +55,6 @@ #include "llappviewer.h" #include "llface.h" #include "llviewercamera.h" -#include "lltextureatlas.h" -#include "lltextureatlasmanager.h" #include "lltextureentry.h" #include "lltexturemanagerbridge.h" #include "llmediaentry.h" @@ -78,6 +76,7 @@ LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sMissingAssetImagep = LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sWhiteImagep = NULL; LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sDefaultImagep = NULL; LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sSmokeImagep = NULL; +LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sFlatNormalImagep = NULL; LLViewerMediaTexture::media_map_t LLViewerMediaTexture::sMediaMap ; LLTexturePipelineTester* LLViewerTextureManager::sTesterp = NULL ; const std::string sTesterName("TextureTester"); @@ -103,7 +102,6 @@ S32 LLViewerTexture::sMinLargeImageSize = 65536 ; //256 * 256. S32 LLViewerTexture::sMaxSmallImageSize = MAX_CACHED_RAW_IMAGE_AREA ; BOOL LLViewerTexture::sFreezeImageScalingDown = FALSE ; F32 LLViewerTexture::sCurrentTime = 0.0f ; -BOOL LLViewerTexture::sUseTextureAtlas = FALSE ; F32 LLViewerTexture::sTexelPixelRatio = 1.0f; LLViewerTexture::EDebugTexels LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_OFF; @@ -282,7 +280,7 @@ LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture( } LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromFile( - const std::string& filename, + const std::string& filename, FTType f_type, BOOL usemipmaps, LLViewerTexture::EBoostLevel boost_priority, @@ -295,7 +293,7 @@ LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromFile( } //static -LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string& url, +LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string& url, FTType f_type, BOOL usemipmaps, LLViewerTexture::EBoostLevel boost_priority, @@ -402,7 +400,7 @@ void LLViewerTextureManager::init() LLViewerTexture::sCheckerBoardImagep = LLViewerTextureManager::getLocalTexture(image_raw.get(), TRUE); LLViewerTexture::initClass() ; - + // Create a texture manager bridge. gTextureManagerBridgep = new LLViewerTextureManagerBridge; @@ -430,6 +428,7 @@ void LLViewerTextureManager::cleanup() LLViewerFetchedTexture::sSmokeImagep = NULL; LLViewerFetchedTexture::sMissingAssetImagep = NULL; LLViewerFetchedTexture::sWhiteImagep = NULL; + LLViewerFetchedTexture::sFlatNormalImagep = NULL; LLViewerMediaTexture::cleanUpClass() ; } @@ -570,7 +569,6 @@ void LLViewerTexture::updateClass(const F32 velocity, const F32 angular_velocity } } sDesiredDiscardBias = llclamp(sDesiredDiscardBias, desired_discard_bias_min, desired_discard_bias_max); - LLViewerTexture::sUseTextureAtlas = gSavedSettings.getBOOL("EnableTextureAtlas") ; F32 camera_moving_speed = LLViewerCamera::getInstance()->getAverageSpeed() ; F32 camera_angular_speed = LLViewerCamera::getInstance()->getAverageAngularSpeed(); @@ -637,9 +635,14 @@ void LLViewerTexture::init(bool firstinit) mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval ; mAdditionalDecodePriority = 0.f ; mParcelMedia = NULL ; - mNumFaces = 0 ; + mNumVolumes = 0; - mFaceList.clear() ; + mFaceList[LLRender::DIFFUSE_MAP].clear() ; + mFaceList[LLRender::NORMAL_MAP].clear() ; + mFaceList[LLRender::SPECULAR_MAP].clear() ; + mNumFaces[LLRender::DIFFUSE_MAP] = + mNumFaces[LLRender::NORMAL_MAP] = + mNumFaces[LLRender::SPECULAR_MAP] = 0 ; mVolumeList.clear(); } @@ -651,7 +654,9 @@ S8 LLViewerTexture::getType() const void LLViewerTexture::cleanup() { - mFaceList.clear() ; + mFaceList[LLRender::DIFFUSE_MAP].clear() ; + mFaceList[LLRender::NORMAL_MAP].clear() ; + mFaceList[LLRender::SPECULAR_MAP].clear() ; mVolumeList.clear(); } @@ -791,38 +796,57 @@ void LLViewerTexture::setKnownDrawSize(S32 width, S32 height) } //virtual -void LLViewerTexture::addFace(LLFace* facep) +void LLViewerTexture::addFace(U32 ch, LLFace* facep) { - if(mNumFaces >= mFaceList.size()) + llassert(ch < LLRender::NUM_TEXTURE_CHANNELS); + + if(mNumFaces[ch] >= mFaceList[ch].size()) { - mFaceList.resize(2 * mNumFaces + 1) ; + mFaceList[ch].resize(2 * mNumFaces[ch] + 1) ; } - mFaceList[mNumFaces] = facep ; - facep->setIndexInTex(mNumFaces) ; - mNumFaces++ ; + mFaceList[ch][mNumFaces[ch]] = facep ; + facep->setIndexInTex(ch, mNumFaces[ch]) ; + mNumFaces[ch]++ ; mLastFaceListUpdateTimer.reset() ; } //virtual -void LLViewerTexture::removeFace(LLFace* facep) +void LLViewerTexture::removeFace(U32 ch, LLFace* facep) { - if(mNumFaces > 1) + llassert(ch < LLRender::NUM_TEXTURE_CHANNELS); + + if(mNumFaces[ch] > 1) { - S32 index = facep->getIndexInTex() ; - mFaceList[index] = mFaceList[--mNumFaces] ; - mFaceList[index]->setIndexInTex(index) ; + S32 index = facep->getIndexInTex(ch) ; + llassert(index < mFaceList[ch].size()); + llassert(index < mNumFaces[ch]); + mFaceList[ch][index] = mFaceList[ch][--mNumFaces[ch]] ; + mFaceList[ch][index]->setIndexInTex(ch, index) ; } else { - mFaceList.clear() ; - mNumFaces = 0 ; + mFaceList[ch].clear() ; + mNumFaces[ch] = 0 ; } mLastFaceListUpdateTimer.reset() ; } -S32 LLViewerTexture::getNumFaces() const +S32 LLViewerTexture::getTotalNumFaces() const +{ + S32 ret = 0; + + for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) + { + ret += mNumFaces[i]; + } + + return ret; +} + +S32 LLViewerTexture::getNumFaces(U32 ch) const { - return mNumFaces ; + llassert(ch < LLRender::NUM_TEXTURE_CHANNELS); + return mNumFaces[ch]; } @@ -845,6 +869,8 @@ void LLViewerTexture::removeVolume(LLVOVolume* volumep) if(mNumVolumes > 1) { S32 index = volumep->getIndexInTex() ; + llassert(index < mVolumeList.size()); + llassert(index < mNumVolumes); mVolumeList[index] = mVolumeList[--mNumVolumes] ; mVolumeList[index]->setIndexInTex(index) ; } @@ -866,18 +892,22 @@ 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()) + if(mLastFaceListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME) { return ; } - if(mLastFaceListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME) + for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) + { + if(mNumFaces[i] + MAX_EXTRA_BUFFER_SIZE > mFaceList[i].size()) { return ; } + mFaceList[i].erase(mFaceList[i].begin() + mNumFaces[i], mFaceList[i].end()); + } + mLastFaceListUpdateTimer.reset() ; - mFaceList.erase(mFaceList.begin() + mNumFaces, mFaceList.end()); } void LLViewerTexture::reorganizeVolumeList() @@ -1206,7 +1236,7 @@ void LLViewerFetchedTexture::destroyTexture() { return ; } - + //LL_DEBUGS("Avatar") << mID << llendl; destroyGLTexture() ; mFullyLoaded = FALSE ; @@ -1223,9 +1253,14 @@ void LLViewerFetchedTexture::addToCreateTexture() mGLTexturep->setComponents(mComponents) ; force_update = true ; - for(U32 i = 0 ; i < mNumFaces ; i++) + for (U32 j = 0; j < LLRender::NUM_TEXTURE_CHANNELS; ++j) + { + llassert(mNumFaces[j] <= mFaceList[j].size()); + + for(U32 i = 0 ; i < mNumFaces[j]; i++) { - mFaceList[i]->dirtyTexture() ; + mFaceList[j][i]->dirtyTexture() ; + } } //discard the cached raw image and the saved raw image @@ -1369,11 +1404,8 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/) return FALSE; } - if(!(res = insertToAtlas())) - { res = mGLTexturep->createGLTexture(mRawDiscardLevel, mRawImage, usename, TRUE, mBoostLevel); - resetFaceAtlas() ; - } + setActive() ; if (!needsToSaveRawImage()) @@ -1662,9 +1694,13 @@ void LLViewerFetchedTexture::updateVirtualSize() addTextureStats(0.f, FALSE) ;//reset } - for(U32 i = 0 ; i < mNumFaces ; i++) + for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch) { - LLFace* facep = mFaceList[i] ; + llassert(mNumFaces[ch] <= mFaceList[ch].size()); + + for(U32 i = 0 ; i < mNumFaces[ch]; i++) + { + LLFace* facep = mFaceList[ch][i] ; if( facep ) { LLDrawable* drawable = facep->getDrawable(); @@ -1683,7 +1719,7 @@ void LLViewerFetchedTexture::updateVirtualSize() } } } - + } //reset whether or not a face was selected after 10 seconds const F32 SELECTION_RESET_TIME = 10.f; @@ -2775,190 +2811,6 @@ F32 LLViewerFetchedTexture::getElapsedLastReferencedSavedRawImageTime() const { return sCurrentTime - mLastReferencedSavedRawImageTime ; } -//---------------------------------------------------------------------------------------------- -//atlasing -//---------------------------------------------------------------------------------------------- -void LLViewerFetchedTexture::resetFaceAtlas() -{ - //Nothing should be done here. -} - -//invalidate all atlas slots for this image. -void LLViewerFetchedTexture::invalidateAtlas(BOOL rebuild_geom) -{ - for(U32 i = 0 ; i < mNumFaces ; i++) - { - LLFace* facep = mFaceList[i] ; - facep->removeAtlas() ; - if(rebuild_geom && facep->getDrawable() && facep->getDrawable()->getSpatialGroup()) - { - facep->getDrawable()->getSpatialGroup()->setState(LLSpatialGroup::GEOM_DIRTY); - } - } -} - -BOOL LLViewerFetchedTexture::insertToAtlas() -{ - if(!LLViewerTexture::sUseTextureAtlas) - { - return FALSE ; - } - if(getNumFaces() < 1) - { - return FALSE ; - } - if(mGLTexturep->getDiscardLevelInAtlas() > 0 && mRawDiscardLevel >= mGLTexturep->getDiscardLevelInAtlas()) - { - return FALSE ; - } - if(!LLTextureAtlasManager::getInstance()->canAddToAtlas(mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents(), mGLTexturep->getTexTarget())) - { - return FALSE ; - } - - BOOL ret = TRUE ;//if ret is set to false, will generate a gl texture for this image. - S32 raw_w = mRawImage->getWidth() ; - S32 raw_h = mRawImage->getHeight() ; - F32 xscale = 1.0f, yscale = 1.0f ; - LLPointer<LLTextureAtlasSlot> slot_infop; - LLTextureAtlasSlot* cur_slotp ;//no need to be smart pointer. - LLSpatialGroup* groupp ; - LLFace* facep; - - //if the atlas slot pointers for some faces are null, process them later. - ll_face_list_t waiting_list ; - for(U32 i = 0 ; i < mNumFaces ; i++) - { - { - facep = mFaceList[i] ; - - //face can not use atlas. - if(!facep->canUseAtlas()) - { - if(facep->getAtlasInfo()) - { - facep->removeAtlas() ; - } - ret = FALSE ; - continue ; - } - - //the atlas slot is updated - slot_infop = facep->getAtlasInfo() ; - groupp = facep->getDrawable()->getSpatialGroup() ; - - if(slot_infop) - { - if(slot_infop->getSpatialGroup() != groupp) - { - if((cur_slotp = groupp->getCurUpdatingSlot(this))) //switch slot - { - facep->setAtlasInfo(cur_slotp) ; - facep->setAtlasInUse(TRUE) ; - continue ; - } - else //do not forget to update slot_infop->getSpatialGroup(). - { - LLSpatialGroup* gp = slot_infop->getSpatialGroup() ; - gp->setCurUpdatingTime(gFrameCount) ; - gp->setCurUpdatingTexture(this) ; - gp->setCurUpdatingSlot(slot_infop) ; - } - } - else //same group - { - if(gFrameCount && slot_infop->getUpdatedTime() == gFrameCount)//slot is just updated - { - facep->setAtlasInUse(TRUE) ; - continue ; - } - } - } - else - { - //if the slot is null, wait to process them later. - waiting_list.push_back(facep) ; - continue ; - } - - //---------- - //insert to atlas - if(!slot_infop->getAtlas()->insertSubTexture(mGLTexturep, mRawDiscardLevel, mRawImage, slot_infop->getSlotCol(), slot_infop->getSlotRow())) - { - - //the texture does not qualify to add to atlas, do not bother to try for other faces. - //invalidateAtlas(); - return FALSE ; - } - - //update texture scale - slot_infop->getAtlas()->getTexCoordScale(raw_w, raw_h, xscale, yscale) ; - slot_infop->setTexCoordScale(xscale, yscale) ; - slot_infop->setValid() ; - slot_infop->setUpdatedTime(gFrameCount) ; - - //update spatial group atlas info - groupp->setCurUpdatingTime(gFrameCount) ; - groupp->setCurUpdatingTexture(this) ; - groupp->setCurUpdatingSlot(slot_infop) ; - - //make the face to switch to the atlas. - facep->setAtlasInUse(TRUE) ; - } - } - - //process the waiting_list - for(std::vector<LLFace*>::iterator iter = waiting_list.begin(); iter != waiting_list.end(); ++iter) - { - facep = (LLFace*)*iter ; - groupp = facep->getDrawable()->getSpatialGroup() ; - - //check if this texture already inserted to atlas for this group - if((cur_slotp = groupp->getCurUpdatingSlot(this))) - { - facep->setAtlasInfo(cur_slotp) ; - facep->setAtlasInUse(TRUE) ; - continue ; - } - - //need to reserve a slot from atlas - slot_infop = LLTextureAtlasManager::getInstance()->reserveAtlasSlot(llmax(mFullWidth, mFullHeight), getComponents(), groupp, this) ; - - facep->setAtlasInfo(slot_infop) ; - - groupp->setCurUpdatingTime(gFrameCount) ; - groupp->setCurUpdatingTexture(this) ; - groupp->setCurUpdatingSlot(slot_infop) ; - - //slot allocation failed. - if(!slot_infop || !slot_infop->getAtlas()) - { - ret = FALSE ; - facep->setAtlasInUse(FALSE) ; - continue ; - } - - //insert to atlas - if(!slot_infop->getAtlas()->insertSubTexture(mGLTexturep, mRawDiscardLevel, mRawImage, slot_infop->getSlotCol(), slot_infop->getSlotRow())) - { - //the texture does not qualify to add to atlas, do not bother to try for other faces. - ret = FALSE ; - //invalidateAtlas(); - break ; - } - - //update texture scale - slot_infop->getAtlas()->getTexCoordScale(raw_w, raw_h, xscale, yscale) ; - slot_infop->setTexCoordScale(xscale, yscale) ; - slot_infop->setValid() ; - slot_infop->setUpdatedTime(gFrameCount) ; - - //make the face to switch to the atlas. - facep->setAtlasInUse(TRUE) ; - } - - return ret ; -} //---------------------------------------------------------------------------------------------- //end of LLViewerFetchedTexture @@ -3305,13 +3157,16 @@ BOOL LLViewerMediaTexture::findFaces() LLViewerTexture* tex = gTextureList.findImage(mID) ; if(tex) //this media is a parcel media for tex. { - const ll_face_list_t* face_list = tex->getFaceList() ; - U32 end = tex->getNumFaces() ; + for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch) + { + const ll_face_list_t* face_list = tex->getFaceList(ch) ; + U32 end = tex->getNumFaces(ch) ; for(U32 i = 0 ; i < end ; i++) { mMediaFaceList.push_back((*face_list)[i]) ; } } + } if(!mMediaImplp) { @@ -3374,7 +3229,7 @@ void LLViewerMediaTexture::addMediaToFace(LLFace* facep) return ; //no need to add the face because the media is not in playing. } - switchTexture(facep) ; + switchTexture(LLRender::DIFFUSE_MAP, facep) ; } void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep) @@ -3391,19 +3246,19 @@ void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep) } mIsPlaying = FALSE ; //set to remove the media from the face. - switchTexture(facep) ; + switchTexture(LLRender::DIFFUSE_MAP, facep) ; mIsPlaying = TRUE ; //set the flag back. - if(getNumFaces() < 1) //no face referencing to this media + if(getTotalNumFaces() < 1) //no face referencing to this media { stopPlaying() ; } } //virtual -void LLViewerMediaTexture::addFace(LLFace* facep) +void LLViewerMediaTexture::addFace(U32 ch, LLFace* facep) { - LLViewerTexture::addFace(facep) ; + LLViewerTexture::addFace(ch, facep) ; const LLTextureEntry* te = facep->getTextureEntry() ; if(te && te->getID().notNull()) @@ -3430,9 +3285,9 @@ void LLViewerMediaTexture::addFace(LLFace* facep) } //virtual -void LLViewerMediaTexture::removeFace(LLFace* facep) +void LLViewerMediaTexture::removeFace(U32 ch, LLFace* facep) { - LLViewerTexture::removeFace(facep) ; + LLViewerTexture::removeFace(ch, facep) ; const LLTextureEntry* te = facep->getTextureEntry() ; if(te && te->getID().notNull()) @@ -3450,24 +3305,35 @@ void LLViewerMediaTexture::removeFace(LLFace* facep) } } + std::vector<const LLTextureEntry*> te_list; + + for (U32 ch = 0; ch < 3; ++ch) + { // //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(!mNumFaces) + + llassert(mNumFaces[ch] <= mFaceList[ch].size()); + + for(U32 j = 0 ; j < mNumFaces[ch] ; j++) + { + te_list.push_back(mFaceList[ch][j]->getTextureEntry());//all textures are in use. + } + } + + if (te_list.empty()) { mTextureList.clear() ; return ; } - S32 end = getNumFaces() ; - std::vector<const LLTextureEntry*> te_list(end) ; - S32 i = 0 ; - for(U32 j = 0 ; j < mNumFaces ; j++) - { - te_list[i++] = mFaceList[j]->getTextureEntry() ;//all textures are in use. - } + + S32 end = te_list.size(); + for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin(); iter != mTextureList.end(); ++iter) { + S32 i = 0; + for(i = 0 ; i < end ; i++) { if(te_list[i] && te_list[i]->getID() == (*iter)->getID())//the texture is in use. @@ -3512,7 +3378,7 @@ void LLViewerMediaTexture::stopPlaying() mIsPlaying = FALSE ; } -void LLViewerMediaTexture::switchTexture(LLFace* facep) +void LLViewerMediaTexture::switchTexture(U32 ch, LLFace* facep) { if(facep) { @@ -3528,7 +3394,7 @@ void LLViewerMediaTexture::switchTexture(LLFace* facep) if(mIsPlaying) //old textures switch to the media texture { - facep->switchTexture(this) ; + facep->switchTexture(ch, this) ; } else //switch to old textures. { @@ -3544,7 +3410,7 @@ void LLViewerMediaTexture::switchTexture(LLFace* facep) { tex = LLViewerFetchedTexture::sDefaultImagep ; } - facep->switchTexture(tex) ; + facep->switchTexture(ch, tex) ; } } } @@ -3583,14 +3449,17 @@ void LLViewerMediaTexture::setPlaying(BOOL playing) for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter) { - switchTexture(*iter) ; + switchTexture(LLRender::DIFFUSE_MAP, *iter) ; } } else //stop playing this media { - for(U32 i = mNumFaces ; i ; i--) + U32 ch = LLRender::DIFFUSE_MAP; + + llassert(mNumFaces[ch] <= mFaceList[ch].size()); + for(U32 i = mNumFaces[ch] ; i ; i--) { - switchTexture(mFaceList[i - 1]) ; //current face could be removed in this function. + switchTexture(ch, mFaceList[ch][i - 1]) ; //current face could be removed in this function. } } return ; @@ -3612,15 +3481,19 @@ F32 LLViewerMediaTexture::getMaxVirtualSize() if(mIsPlaying) //media is playing { - for(U32 i = 0 ; i < mNumFaces ; i++) + for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch) { - LLFace* facep = mFaceList[i] ; + llassert(mNumFaces[ch] <= mFaceList[ch].size()); + for(U32 i = 0 ; i < mNumFaces[ch] ; i++) + { + LLFace* facep = mFaceList[ch][i] ; if(facep->getDrawable()->isRecentlyVisible()) { addTextureStats(facep->getVirtualSize()) ; } } } + } else //media is not in playing { findFaces() ; |