PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewertexture.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 831 lines | 578 code | 145 blank | 108 comment | 4 complexity | b37c58f51cc6b1555ac74ed4f2e7633a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewertexture.h
  3. * @brief Object for managing images and their textures
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVIEWERTEXTURE_H
  27. #define LL_LLVIEWERTEXTURE_H
  28. #include "lltexture.h"
  29. #include "lltimer.h"
  30. #include "llframetimer.h"
  31. #include "llhost.h"
  32. #include "llgltypes.h"
  33. #include "llrender.h"
  34. #include "llmetricperformancetester.h"
  35. #include <map>
  36. #include <list>
  37. #define MIN_VIDEO_RAM_IN_MEGA_BYTES 32
  38. #define MAX_VIDEO_RAM_IN_MEGA_BYTES 512 // 512MB max for performance reasons.
  39. class LLFace;
  40. class LLImageGL ;
  41. class LLImageRaw;
  42. class LLViewerObject;
  43. class LLViewerTexture;
  44. class LLViewerFetchedTexture ;
  45. class LLViewerMediaTexture ;
  46. class LLTexturePipelineTester ;
  47. typedef void (*loaded_callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
  48. class LLVFile;
  49. class LLMessageSystem;
  50. class LLViewerMediaImpl ;
  51. class LLVOVolume ;
  52. class LLLoadedCallbackEntry
  53. {
  54. public:
  55. typedef std::set< LLUUID > source_callback_list_t;
  56. public:
  57. LLLoadedCallbackEntry(loaded_callback_func cb,
  58. S32 discard_level,
  59. BOOL need_imageraw, // Needs image raw for the callback
  60. void* userdata,
  61. source_callback_list_t* src_callback_list,
  62. LLViewerFetchedTexture* target,
  63. BOOL pause);
  64. ~LLLoadedCallbackEntry();
  65. void removeTexture(LLViewerFetchedTexture* tex) ;
  66. loaded_callback_func mCallback;
  67. S32 mLastUsedDiscard;
  68. S32 mDesiredDiscard;
  69. BOOL mNeedsImageRaw;
  70. BOOL mPaused;
  71. void* mUserData;
  72. source_callback_list_t* mSourceCallbackList;
  73. public:
  74. static void cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list) ;
  75. };
  76. class LLTextureBar;
  77. class LLViewerTexture : public LLTexture
  78. {
  79. public:
  80. enum
  81. {
  82. MAX_IMAGE_SIZE_DEFAULT = 1024,
  83. INVALID_DISCARD_LEVEL = 0x7fff
  84. };
  85. enum
  86. {
  87. LOCAL_TEXTURE,
  88. MEDIA_TEXTURE,
  89. DYNAMIC_TEXTURE,
  90. FETCHED_TEXTURE,
  91. LOD_TEXTURE,
  92. ATLAS_TEXTURE,
  93. INVALID_TEXTURE_TYPE
  94. };
  95. enum EBoostLevel
  96. {
  97. BOOST_NONE = 0,
  98. BOOST_AVATAR_BAKED ,
  99. BOOST_AVATAR ,
  100. BOOST_CLOUDS ,
  101. BOOST_SCULPTED ,
  102. BOOST_HIGH = 10,
  103. BOOST_BUMP ,
  104. BOOST_TERRAIN , // has to be high priority for minimap / low detail
  105. BOOST_SELECTED ,
  106. BOOST_AVATAR_BAKED_SELF ,
  107. BOOST_AVATAR_SELF , // needed for baking avatar
  108. BOOST_SUPER_HIGH , //textures higher than this need to be downloaded at the required resolution without delay.
  109. BOOST_HUD ,
  110. BOOST_ICON ,
  111. BOOST_UI ,
  112. BOOST_PREVIEW ,
  113. BOOST_MAP ,
  114. BOOST_MAP_VISIBLE ,
  115. BOOST_MAX_LEVEL,
  116. //other texture Categories
  117. LOCAL = BOOST_MAX_LEVEL,
  118. AVATAR_SCRATCH_TEX,
  119. DYNAMIC_TEX,
  120. MEDIA,
  121. ATLAS,
  122. OTHER,
  123. MAX_GL_IMAGE_CATEGORY
  124. };
  125. static S32 getTotalNumOfCategories() ;
  126. static S32 getIndexFromCategory(S32 category) ;
  127. static S32 getCategoryFromIndex(S32 index) ;
  128. typedef std::vector<LLFace*> ll_face_list_t;
  129. typedef std::vector<LLVOVolume*> ll_volume_list_t;
  130. protected:
  131. virtual ~LLViewerTexture();
  132. LOG_CLASS(LLViewerTexture);
  133. public:
  134. static void initClass();
  135. static void updateClass(const F32 velocity, const F32 angular_velocity) ;
  136. LLViewerTexture(BOOL usemipmaps = TRUE);
  137. LLViewerTexture(const LLUUID& id, BOOL usemipmaps) ;
  138. LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
  139. LLViewerTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
  140. virtual S8 getType() const;
  141. virtual BOOL isMissingAsset()const ;
  142. virtual void dump(); // debug info to llinfos
  143. /*virtual*/ bool bindDefaultImage(const S32 stage = 0) ;
  144. /*virtual*/ void forceImmediateUpdate() ;
  145. const LLUUID& getID() const { return mID; }
  146. void setBoostLevel(S32 level);
  147. S32 getBoostLevel() { return mBoostLevel; }
  148. void addTextureStats(F32 virtual_size, BOOL needs_gltexture = TRUE) const;
  149. void resetTextureStats();
  150. void setMaxVirtualSizeResetInterval(S32 interval)const {mMaxVirtualSizeResetInterval = interval;}
  151. void resetMaxVirtualSizeResetCounter()const {mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;}
  152. virtual F32 getMaxVirtualSize() ;
  153. LLFrameTimer* getLastReferencedTimer() {return &mLastReferencedTimer ;}
  154. S32 getFullWidth() const { return mFullWidth; }
  155. S32 getFullHeight() const { return mFullHeight; }
  156. /*virtual*/ void setKnownDrawSize(S32 width, S32 height);
  157. virtual void addFace(LLFace* facep) ;
  158. virtual void removeFace(LLFace* facep) ;
  159. S32 getNumFaces() const;
  160. const ll_face_list_t* getFaceList() const {return &mFaceList;}
  161. virtual void addVolume(LLVOVolume* volumep);
  162. virtual void removeVolume(LLVOVolume* volumep);
  163. S32 getNumVolumes() const;
  164. const ll_volume_list_t* getVolumeList() const { return &mVolumeList; }
  165. void generateGLTexture() ;
  166. void destroyGLTexture() ;
  167. //---------------------------------------------------------------------------------------------
  168. //functions to access LLImageGL
  169. //---------------------------------------------------------------------------------------------
  170. /*virtual*/S32 getWidth(S32 discard_level = -1) const;
  171. /*virtual*/S32 getHeight(S32 discard_level = -1) const;
  172. BOOL hasGLTexture() const ;
  173. LLGLuint getTexName() const ;
  174. BOOL createGLTexture() ;
  175. BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLViewerTexture::OTHER);
  176. virtual void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
  177. void setFilteringOption(LLTexUnit::eTextureFilterOptions option);
  178. void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
  179. void setAddressMode(LLTexUnit::eTextureAddressMode mode);
  180. BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height);
  181. BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height);
  182. void setGLTextureCreated (bool initialized);
  183. void setCategory(S32 category) ;
  184. LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
  185. S32 getMaxDiscardLevel() const;
  186. S32 getDiscardLevel() const;
  187. S8 getComponents() const ;
  188. BOOL getBoundRecently() const;
  189. S32 getTextureMemory() const ;
  190. LLGLenum getPrimaryFormat() const;
  191. BOOL getIsAlphaMask() const ;
  192. LLTexUnit::eTextureType getTarget(void) const ;
  193. BOOL getMask(const LLVector2 &tc);
  194. F32 getTimePassedSinceLastBound();
  195. BOOL getMissed() const ;
  196. BOOL isJustBound()const ;
  197. void forceUpdateBindStats(void) const;
  198. U32 getTexelsInAtlas() const ;
  199. U32 getTexelsInGLTexture() const ;
  200. BOOL isGLTextureCreated() const ;
  201. S32 getDiscardLevelInAtlas() const ;
  202. //---------------------------------------------------------------------------------------------
  203. //end of functions to access LLImageGL
  204. //---------------------------------------------------------------------------------------------
  205. //-----------------
  206. /*virtual*/ void setActive() ;
  207. void forceActive() ;
  208. void setNoDelete() ;
  209. void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
  210. BOOL getDontDiscard() const { return mDontDiscard; }
  211. //-----------------
  212. BOOL isLargeImage() ;
  213. void setParcelMedia(LLViewerMediaTexture* media) {mParcelMedia = media;}
  214. BOOL hasParcelMedia() const { return mParcelMedia != NULL;}
  215. LLViewerMediaTexture* getParcelMedia() const { return mParcelMedia;}
  216. /*virtual*/ void updateBindStatsForTester() ;
  217. protected:
  218. void cleanup() ;
  219. void init(bool firstinit) ;
  220. void reorganizeFaceList() ;
  221. void reorganizeVolumeList() ;
  222. void setTexelsPerImage();
  223. private:
  224. //note: do not make this function public.
  225. /*virtual*/ LLImageGL* getGLTexture() const ;
  226. virtual void switchToCachedImage();
  227. static bool isMemoryForTextureLow() ;
  228. protected:
  229. LLUUID mID;
  230. S32 mBoostLevel; // enum describing priority level
  231. S32 mFullWidth;
  232. S32 mFullHeight;
  233. BOOL mUseMipMaps ;
  234. S8 mComponents;
  235. F32 mTexelsPerImage; // Texels per image.
  236. mutable S8 mNeedsGLTexture;
  237. mutable F32 mMaxVirtualSize; // The largest virtual size of the image, in pixels - how much data to we need?
  238. mutable S32 mMaxVirtualSizeResetCounter ;
  239. mutable S32 mMaxVirtualSizeResetInterval;
  240. mutable F32 mAdditionalDecodePriority; // priority add to mDecodePriority.
  241. LLFrameTimer mLastReferencedTimer;
  242. //GL texture
  243. LLPointer<LLImageGL> mGLTexturep ;
  244. S8 mDontDiscard; // Keep full res version of this image (for UI, etc)
  245. ll_face_list_t mFaceList ; //reverse pointer pointing to the faces using this image as texture
  246. U32 mNumFaces ;
  247. LLFrameTimer mLastFaceListUpdateTimer ;
  248. ll_volume_list_t mVolumeList;
  249. U32 mNumVolumes;
  250. LLFrameTimer mLastVolumeListUpdateTimer;
  251. //do not use LLPointer here.
  252. LLViewerMediaTexture* mParcelMedia ;
  253. protected:
  254. typedef enum
  255. {
  256. DELETED = 0, //removed from memory
  257. DELETION_CANDIDATE, //ready to be removed from memory
  258. INACTIVE, //not be used for the last certain period (i.e., 30 seconds).
  259. ACTIVE, //just being used, can become inactive if not being used for a certain time (10 seconds).
  260. NO_DELETE = 99 //stay in memory, can not be removed.
  261. } LLGLTextureState;
  262. LLGLTextureState mTextureState ;
  263. public:
  264. static const U32 sCurrentFileVersion;
  265. static S32 sImageCount;
  266. static S32 sRawCount;
  267. static S32 sAuxCount;
  268. static LLFrameTimer sEvaluationTimer;
  269. static F32 sDesiredDiscardBias;
  270. static F32 sDesiredDiscardScale;
  271. static S32 sBoundTextureMemoryInBytes;
  272. static S32 sTotalTextureMemoryInBytes;
  273. static S32 sMaxBoundTextureMemInMegaBytes;
  274. static S32 sMaxTotalTextureMemInMegaBytes;
  275. static S32 sMaxDesiredTextureMemInBytes ;
  276. static S8 sCameraMovingDiscardBias;
  277. static S32 sMaxSculptRez ;
  278. static S32 sMinLargeImageSize ;
  279. static S32 sMaxSmallImageSize ;
  280. static BOOL sFreezeImageScalingDown ;//do not scale down image res if set.
  281. static F32 sCurrentTime ;
  282. static BOOL sUseTextureAtlas ;
  283. static LLPointer<LLViewerTexture> sNullImagep; // Null texture for non-textured objects.
  284. static LLPointer<LLViewerTexture> sBlackImagep; // Texture to show NOTHING (pure black)
  285. };
  286. //
  287. //textures are managed in gTextureList.
  288. //raw image data is fetched from remote or local cache
  289. //but the raw image this texture pointing to is fixed.
  290. //
  291. class LLViewerFetchedTexture : public LLViewerTexture
  292. {
  293. friend class LLTextureBar; // debug info only
  294. friend class LLTextureView; // debug info only
  295. protected:
  296. /*virtual*/ ~LLViewerFetchedTexture();
  297. public:
  298. LLViewerFetchedTexture(const LLUUID& id, const LLHost& host = LLHost::invalid, BOOL usemipmaps = TRUE);
  299. LLViewerFetchedTexture(const LLImageRaw* raw, BOOL usemipmaps);
  300. LLViewerFetchedTexture(const std::string& url, const LLUUID& id, BOOL usemipmaps = TRUE);
  301. public:
  302. static F32 maxDecodePriority();
  303. struct Compare
  304. {
  305. // lhs < rhs
  306. bool operator()(const LLPointer<LLViewerFetchedTexture> &lhs, const LLPointer<LLViewerFetchedTexture> &rhs) const
  307. {
  308. const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs;
  309. const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs;
  310. // greater priority is "less"
  311. const F32 lpriority = lhsp->getDecodePriority();
  312. const F32 rpriority = rhsp->getDecodePriority();
  313. if (lpriority > rpriority) // higher priority
  314. return true;
  315. if (lpriority < rpriority)
  316. return false;
  317. return lhsp < rhsp;
  318. }
  319. };
  320. public:
  321. /*virtual*/ S8 getType() const ;
  322. /*virtual*/ void forceImmediateUpdate() ;
  323. /*virtual*/ void dump() ;
  324. // Set callbacks to get called when the image gets updated with higher
  325. // resolution versions.
  326. void setLoadedCallback(loaded_callback_func cb,
  327. S32 discard_level, BOOL keep_imageraw, BOOL needs_aux,
  328. void* userdata, LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause = FALSE);
  329. bool hasCallbacks() { return mLoadedCallbackList.empty() ? false : true; }
  330. void pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
  331. void unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
  332. bool doLoadedCallbacks();
  333. void deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
  334. void clearCallbackEntryList() ;
  335. void addToCreateTexture();
  336. // ONLY call from LLViewerTextureList
  337. BOOL createTexture(S32 usename = 0);
  338. void destroyTexture() ;
  339. virtual void processTextureStats() ;
  340. F32 calcDecodePriority() ;
  341. BOOL needsAux() const { return mNeedsAux; }
  342. // Host we think might have this image, used for baked av textures.
  343. void setTargetHost(LLHost host) { mTargetHost = host; }
  344. LLHost getTargetHost() const { return mTargetHost; }
  345. // Set the decode priority for this image...
  346. // DON'T CALL THIS UNLESS YOU KNOW WHAT YOU'RE DOING, it can mess up
  347. // the priority list, and cause horrible things to happen.
  348. void setDecodePriority(F32 priority = -1.0f);
  349. F32 getDecodePriority() const { return mDecodePriority; };
  350. void setAdditionalDecodePriority(F32 priority) ;
  351. void updateVirtualSize() ;
  352. S32 getDesiredDiscardLevel() { return mDesiredDiscardLevel; }
  353. void setMinDiscardLevel(S32 discard) { mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); }
  354. bool updateFetch();
  355. // Override the computation of discard levels if we know the exact output
  356. // size of the image. Used for UI textures to not decode, even if we have
  357. // more data.
  358. /*virtual*/ void setKnownDrawSize(S32 width, S32 height);
  359. void setIsMissingAsset();
  360. /*virtual*/ BOOL isMissingAsset() const { return mIsMissingAsset; }
  361. // returns dimensions of original image for local files (before power of two scaling)
  362. // and returns 0 for all asset system images
  363. S32 getOriginalWidth() { return mOrigWidth; }
  364. S32 getOriginalHeight() { return mOrigHeight; }
  365. BOOL isInImageList() const {return mInImageList ;}
  366. void setInImageList(BOOL flag) {mInImageList = flag ;}
  367. LLFrameTimer* getLastPacketTimer() {return &mLastPacketTimer;}
  368. U32 getFetchPriority() const { return mFetchPriority ;}
  369. F32 getDownloadProgress() const {return mDownloadProgress ;}
  370. LLImageRaw* reloadRawImage(S8 discard_level) ;
  371. void destroyRawImage();
  372. bool needsToSaveRawImage();
  373. const std::string& getUrl() const {return mUrl;}
  374. //---------------
  375. BOOL isDeleted() ;
  376. BOOL isInactive() ;
  377. BOOL isDeletionCandidate();
  378. void setDeletionCandidate() ;
  379. void setInactive() ;
  380. BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
  381. //---------------
  382. void setForSculpt();
  383. BOOL forSculpt() const {return mForSculpt;}
  384. BOOL isForSculptOnly() const;
  385. //raw image management
  386. void checkCachedRawSculptImage() ;
  387. LLImageRaw* getRawImage()const { return mRawImage ;}
  388. S32 getRawImageLevel() const {return mRawDiscardLevel;}
  389. LLImageRaw* getCachedRawImage() const { return mCachedRawImage ;}
  390. S32 getCachedRawImageLevel() const {return mCachedRawDiscardLevel;}
  391. BOOL isCachedRawImageReady() const {return mCachedRawImageReady ;}
  392. BOOL isRawImageValid()const { return mIsRawImageValid ; }
  393. void forceToSaveRawImage(S32 desired_discard = 0, F32 kept_time = 0.f) ;
  394. /*virtual*/ void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
  395. void destroySavedRawImage() ;
  396. LLImageRaw* getSavedRawImage() ;
  397. BOOL hasSavedRawImage() const ;
  398. F32 getElapsedLastReferencedSavedRawImageTime() const ;
  399. BOOL isFullyLoaded() const;
  400. BOOL hasFetcher() const { return mHasFetcher;}
  401. void setCanUseHTTP(bool can_use_http) {mCanUseHTTP = can_use_http;}
  402. protected:
  403. /*virtual*/ void switchToCachedImage();
  404. S32 getCurrentDiscardLevelForFetching() ;
  405. private:
  406. void init(bool firstinit) ;
  407. void cleanup() ;
  408. void saveRawImage() ;
  409. void setCachedRawImage() ;
  410. //for atlas
  411. void resetFaceAtlas() ;
  412. void invalidateAtlas(BOOL rebuild_geom) ;
  413. BOOL insertToAtlas() ;
  414. private:
  415. BOOL mFullyLoaded;
  416. protected:
  417. std::string mLocalFileName;
  418. S32 mOrigWidth;
  419. S32 mOrigHeight;
  420. // Override the computation of discard levels if we know the exact output size of the image.
  421. // Used for UI textures to not decode, even if we have more data.
  422. S32 mKnownDrawWidth;
  423. S32 mKnownDrawHeight;
  424. BOOL mKnownDrawSizeChanged ;
  425. std::string mUrl;
  426. S32 mRequestedDiscardLevel;
  427. F32 mRequestedDownloadPriority;
  428. S32 mFetchState;
  429. U32 mFetchPriority;
  430. F32 mDownloadProgress;
  431. F32 mFetchDeltaTime;
  432. F32 mRequestDeltaTime;
  433. F32 mDecodePriority; // The priority for decoding this image.
  434. S32 mMinDiscardLevel;
  435. S8 mDesiredDiscardLevel; // The discard level we'd LIKE to have - if we have it and there's space
  436. S8 mMinDesiredDiscardLevel; // The minimum discard level we'd like to have
  437. S8 mNeedsAux; // We need to decode the auxiliary channels
  438. S8 mDecodingAux; // Are we decoding high components
  439. S8 mIsRawImageValid;
  440. S8 mHasFetcher; // We've made a fecth request
  441. S8 mIsFetching; // Fetch request is active
  442. bool mCanUseHTTP ; //This texture can be fetched through http if true.
  443. mutable S8 mIsMissingAsset; // True if we know that there is no image asset with this image id in the database.
  444. typedef std::list<LLLoadedCallbackEntry*> callback_list_t;
  445. S8 mLoadedCallbackDesiredDiscardLevel;
  446. BOOL mPauseLoadedCallBacks;
  447. callback_list_t mLoadedCallbackList;
  448. F32 mLastCallBackActiveTime;
  449. LLPointer<LLImageRaw> mRawImage;
  450. S32 mRawDiscardLevel;
  451. // Used ONLY for cloth meshes right now. Make SURE you know what you're
  452. // doing if you use it for anything else! - djs
  453. LLPointer<LLImageRaw> mAuxRawImage;
  454. //keep a copy of mRawImage for some special purposes
  455. //when mForceToSaveRawImage is set.
  456. BOOL mForceToSaveRawImage ;
  457. BOOL mSaveRawImage;
  458. LLPointer<LLImageRaw> mSavedRawImage;
  459. S32 mSavedRawDiscardLevel;
  460. S32 mDesiredSavedRawDiscardLevel;
  461. F32 mLastReferencedSavedRawImageTime ;
  462. F32 mKeptSavedRawImageTime ;
  463. //a small version of the copy of the raw image (<= 64 * 64)
  464. LLPointer<LLImageRaw> mCachedRawImage;
  465. S32 mCachedRawDiscardLevel;
  466. BOOL mCachedRawImageReady; //the rez of the mCachedRawImage reaches the upper limit.
  467. LLHost mTargetHost; // if LLHost::invalid, just request from agent's simulator
  468. // Timers
  469. LLFrameTimer mLastPacketTimer; // Time since last packet.
  470. LLFrameTimer mStopFetchingTimer; // Time since mDecodePriority == 0.f.
  471. BOOL mInImageList; // TRUE if image is in list (in which case don't reset priority!)
  472. BOOL mNeedsCreateTexture;
  473. BOOL mForSculpt ; //a flag if the texture is used as sculpt data.
  474. BOOL mIsFetched ; //is loaded from remote or from cache, not generated locally.
  475. public:
  476. static LLPointer<LLViewerFetchedTexture> sMissingAssetImagep; // Texture to show for an image asset that is not in the database
  477. static LLPointer<LLViewerFetchedTexture> sWhiteImagep; // Texture to show NOTHING (whiteness)
  478. static LLPointer<LLViewerFetchedTexture> sDefaultImagep; // "Default" texture for error cases, the only case of fetched texture which is generated in local.
  479. static LLPointer<LLViewerFetchedTexture> sSmokeImagep; // Old "Default" translucent texture
  480. };
  481. //
  482. //the image data is fetched from remote or from local cache
  483. //the resolution of the texture is adjustable: depends on the view-dependent parameters.
  484. //
  485. class LLViewerLODTexture : public LLViewerFetchedTexture
  486. {
  487. protected:
  488. /*virtual*/ ~LLViewerLODTexture(){}
  489. public:
  490. LLViewerLODTexture(const LLUUID& id, const LLHost& host = LLHost::invalid, BOOL usemipmaps = TRUE);
  491. LLViewerLODTexture(const std::string& url, const LLUUID& id, BOOL usemipmaps = TRUE);
  492. /*virtual*/ S8 getType() const;
  493. // Process image stats to determine priority/quality requirements.
  494. /*virtual*/ void processTextureStats();
  495. BOOL isUpdateFrozen() ;
  496. private:
  497. void init(bool firstinit) ;
  498. bool scaleDown() ;
  499. private:
  500. F32 mDiscardVirtualSize; // Virtual size used to calculate desired discard
  501. F32 mCalculatedDiscardLevel; // Last calculated discard level
  502. };
  503. //
  504. //the image data is fetched from the media pipeline periodically
  505. //the resolution of the texture is also adjusted by the media pipeline
  506. //
  507. class LLViewerMediaTexture : public LLViewerTexture
  508. {
  509. protected:
  510. /*virtual*/ ~LLViewerMediaTexture() ;
  511. public:
  512. LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
  513. /*virtual*/ S8 getType() const;
  514. void reinit(BOOL usemipmaps = TRUE);
  515. BOOL getUseMipMaps() {return mUseMipMaps ; }
  516. void setUseMipMaps(BOOL mipmap) ;
  517. void setPlaying(BOOL playing) ;
  518. BOOL isPlaying() const {return mIsPlaying;}
  519. void setMediaImpl() ;
  520. void initVirtualSize() ;
  521. void invalidateMediaImpl() ;
  522. void addMediaToFace(LLFace* facep) ;
  523. void removeMediaFromFace(LLFace* facep) ;
  524. /*virtual*/ void addFace(LLFace* facep) ;
  525. /*virtual*/ void removeFace(LLFace* facep) ;
  526. /*virtual*/ F32 getMaxVirtualSize() ;
  527. private:
  528. void switchTexture(LLFace* facep) ;
  529. BOOL findFaces() ;
  530. void stopPlaying() ;
  531. private:
  532. //
  533. //an instant list, recording all faces referencing or can reference to this media texture.
  534. //NOTE: it is NOT thread safe.
  535. //
  536. std::list< LLFace* > mMediaFaceList ;
  537. //an instant list keeping all textures which are replaced by the current media texture,
  538. //is only used to avoid the removal of those textures from memory.
  539. std::list< LLPointer<LLViewerTexture> > mTextureList ;
  540. LLViewerMediaImpl* mMediaImplp ;
  541. BOOL mIsPlaying ;
  542. U32 mUpdateVirtualSizeTime ;
  543. public:
  544. static void updateClass() ;
  545. static void cleanUpClass() ;
  546. static LLViewerMediaTexture* findMediaTexture(const LLUUID& media_id) ;
  547. static void removeMediaImplFromTexture(const LLUUID& media_id) ;
  548. private:
  549. typedef std::map< LLUUID, LLPointer<LLViewerMediaTexture> > media_map_t ;
  550. static media_map_t sMediaMap ;
  551. };
  552. //just an interface class, do not create instance from this class.
  553. class LLViewerTextureManager
  554. {
  555. private:
  556. //make the constructor private to preclude creating instances from this class.
  557. LLViewerTextureManager(){}
  558. public:
  559. //texture pipeline tester
  560. static LLTexturePipelineTester* sTesterp ;
  561. //returns NULL if tex is not a LLViewerFetchedTexture nor derived from LLViewerFetchedTexture.
  562. static LLViewerFetchedTexture* staticCastToFetchedTexture(LLTexture* tex, BOOL report_error = FALSE) ;
  563. //
  564. //"find-texture" just check if the texture exists, if yes, return it, otherwise return null.
  565. //
  566. static LLViewerTexture* findTexture(const LLUUID& id) ;
  567. static LLViewerMediaTexture* findMediaTexture(const LLUUID& id) ;
  568. static LLViewerMediaTexture* createMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
  569. //
  570. //"get-texture" will create a new texture if the texture does not exist.
  571. //
  572. static LLViewerMediaTexture* getMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
  573. static LLPointer<LLViewerTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE);
  574. static LLPointer<LLViewerTexture> getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
  575. static LLPointer<LLViewerTexture> getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
  576. static LLPointer<LLViewerTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
  577. static LLViewerFetchedTexture* getFetchedTexture(const LLUUID &image_id,
  578. BOOL usemipmap = TRUE,
  579. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE, // Get the requested level immediately upon creation.
  580. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  581. LLGLint internal_format = 0,
  582. LLGLenum primary_format = 0,
  583. LLHost request_from_host = LLHost()
  584. );
  585. static LLViewerFetchedTexture* getFetchedTextureFromFile(const std::string& filename,
  586. BOOL usemipmap = TRUE,
  587. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,
  588. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  589. LLGLint internal_format = 0,
  590. LLGLenum primary_format = 0,
  591. const LLUUID& force_id = LLUUID::null
  592. );
  593. static LLViewerFetchedTexture* getFetchedTextureFromUrl(const std::string& url,
  594. BOOL usemipmap = TRUE,
  595. LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_NONE,
  596. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  597. LLGLint internal_format = 0,
  598. LLGLenum primary_format = 0,
  599. const LLUUID& force_id = LLUUID::null
  600. );
  601. static LLViewerFetchedTexture* getFetchedTextureFromHost(const LLUUID& image_id, LLHost host) ;
  602. static void init() ;
  603. static void cleanup() ;
  604. };
  605. //
  606. //this class is used for test/debug only
  607. //it tracks the activities of the texture pipeline
  608. //records them, and outputs them to log files
  609. //
  610. class LLTexturePipelineTester : public LLMetricPerformanceTesterWithSession
  611. {
  612. enum
  613. {
  614. MIN_LARGE_IMAGE_AREA = 262144 //512 * 512
  615. };
  616. public:
  617. LLTexturePipelineTester() ;
  618. ~LLTexturePipelineTester() ;
  619. void update();
  620. void updateTextureBindingStats(const LLViewerTexture* imagep) ;
  621. void updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache) ;
  622. void updateGrayTextureBinding() ;
  623. void setStablizingTime() ;
  624. private:
  625. void reset() ;
  626. void updateStablizingTime() ;
  627. /*virtual*/ void outputTestRecord(LLSD* sd) ;
  628. private:
  629. BOOL mPause ;
  630. private:
  631. BOOL mUsingDefaultTexture; //if set, some textures are still gray.
  632. U32 mTotalBytesUsed ; //total bytes of textures bound/used for the current frame.
  633. U32 mTotalBytesUsedForLargeImage ; //total bytes of textures bound/used for the current frame for images larger than 256 * 256.
  634. U32 mLastTotalBytesUsed ; //total bytes of textures bound/used for the previous frame.
  635. U32 mLastTotalBytesUsedForLargeImage ; //total bytes of textures bound/used for the previous frame for images larger than 256 * 256.
  636. //
  637. //data size
  638. //
  639. U32 mTotalBytesLoaded ; //total bytes fetched by texture pipeline
  640. U32 mTotalBytesLoadedFromCache ; //total bytes fetched by texture pipeline from local cache
  641. U32 mTotalBytesLoadedForLargeImage ; //total bytes fetched by texture pipeline for images larger than 256 * 256.
  642. U32 mTotalBytesLoadedForSculpties ; //total bytes fetched by texture pipeline for sculpties
  643. //
  644. //time
  645. //NOTE: the error tolerances of the following timers is one frame time.
  646. //
  647. F32 mStartFetchingTime ;
  648. F32 mTotalGrayTime ; //total loading time when no gray textures.
  649. F32 mTotalStablizingTime ; //total stablizing time when texture memory overflows
  650. F32 mStartTimeLoadingSculpties ; //the start moment of loading sculpty images.
  651. F32 mEndTimeLoadingSculpties ; //the end moment of loading sculpty images.
  652. F32 mStartStablizingTime ;
  653. F32 mEndStablizingTime ;
  654. private:
  655. //
  656. //The following members are used for performance analyzing
  657. //
  658. class LLTextureTestSession : public LLTestSession
  659. {
  660. public:
  661. LLTextureTestSession() ;
  662. /*virtual*/ ~LLTextureTestSession() ;
  663. void reset() ;
  664. F32 mTotalFetchingTime ;
  665. F32 mTotalGrayTime ;
  666. F32 mTotalStablizingTime ;
  667. F32 mStartTimeLoadingSculpties ;
  668. F32 mTotalTimeLoadingSculpties ;
  669. S32 mTotalBytesLoaded ;
  670. S32 mTotalBytesLoadedFromCache ;
  671. S32 mTotalBytesLoadedForLargeImage ;
  672. S32 mTotalBytesLoadedForSculpties ;
  673. typedef struct _texture_instant_preformance_t
  674. {
  675. S32 mAverageBytesUsedPerSecond ;
  676. S32 mAverageBytesUsedForLargeImagePerSecond ;
  677. F32 mAveragePercentageBytesUsedPerSecond ;
  678. F32 mTime ;
  679. }texture_instant_preformance_t ;
  680. std::vector<texture_instant_preformance_t> mInstantPerformanceList ;
  681. S32 mInstantPerformanceListCounter ;
  682. };
  683. /*virtual*/ LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) ;
  684. /*virtual*/ void compareTestSessions(std::ofstream* os) ;
  685. };
  686. #endif