llviewertexture.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /**
  2. * @file llviewertexture.h
  3. * @brief Object for managing images and their textures
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERTEXTURE_H
  33. #define LL_LLVIEWERTEXTURE_H
  34. #include <list>
  35. #include "llatomic.h"
  36. #include "llcorehttpcommon.h"
  37. #include "hbfastmap.h"
  38. #include "llgltexture.h"
  39. #include "llhost.h"
  40. #include "llrender.h"
  41. #include "lltimer.h"
  42. #include "lluuid.h"
  43. #include "llface.h"
  44. class LLImageGL;
  45. class LLImageRaw;
  46. class LLMessageSystem;
  47. class LLViewerObject;
  48. class LLViewerTexture;
  49. class LLViewerFetchedTexture;
  50. class LLViewerMediaTexture;
  51. class LLVOVolume;
  52. class LLViewerMediaImpl;
  53. typedef void (*loaded_callback_func)(bool success,
  54. LLViewerFetchedTexture* src_vi,
  55. LLImageRaw* srcp,
  56. LLImageRaw* src_auxp,
  57. S32 discard_level,
  58. bool final,
  59. void* userdata);
  60. class LLLoadedCallbackEntry
  61. {
  62. public:
  63. LLLoadedCallbackEntry(loaded_callback_func cb,
  64. S32 discard_level,
  65. // whether we need image raw for the callback
  66. bool need_imageraw,
  67. void* userdata, uuid_list_t* src_cb_list,
  68. LLViewerFetchedTexture* target, bool pause);
  69. void removeTexture(LLViewerFetchedTexture* tex);
  70. static void cleanUpCallbackList(uuid_list_t* cb_list);
  71. public:
  72. loaded_callback_func mCallback;
  73. void* mUserData;
  74. uuid_list_t* mSourceCallbackList;
  75. S32 mLastUsedDiscard;
  76. S32 mDesiredDiscard;
  77. bool mNeedsImageRaw;
  78. bool mPaused;
  79. };
  80. class LLTextureBar;
  81. class LLViewerTexture : public LLGLTexture
  82. {
  83. friend class LLBumpImageList;
  84. friend class LLUIImageList;
  85. friend class LLTextureBar;
  86. protected:
  87. LOG_CLASS(LLViewerTexture);
  88. ~LLViewerTexture() override;
  89. void cleanup();
  90. void init(bool firstinit);
  91. void reorganizeFaceList();
  92. void reorganizeVolumeList();
  93. #if LL_FIX_MAT_TRANSPARENCY
  94. void notifyAboutMissingAsset();
  95. void notifyAboutCreatingTexture();
  96. #endif
  97. public:
  98. enum
  99. {
  100. LOCAL_TEXTURE,
  101. MEDIA_TEXTURE,
  102. DYNAMIC_TEXTURE,
  103. FETCHED_TEXTURE,
  104. LOD_TEXTURE,
  105. INVALID_TEXTURE_TYPE
  106. };
  107. typedef std::vector<LLFace*> ll_face_list_t;
  108. typedef std::vector<LLVOVolume*> ll_volume_list_t;
  109. static void initClass();
  110. static void updateClass();
  111. LLViewerTexture(bool usemipmaps = true);
  112. LLViewerTexture(const LLUUID& id, bool usemipmaps);
  113. LLViewerTexture(const LLImageRaw* rawp, bool usemipmaps);
  114. LLViewerTexture(U32 width, U32 height, U8 components, bool usemipmaps);
  115. void setNeedsAlphaAndPickMask(bool b);
  116. S8 getType() const override;
  117. LL_INLINE virtual bool isViewerMediaTexture() const { return false; }
  118. LL_INLINE virtual bool isMissingAsset() const { return false; }
  119. void dump() override; // Debug info to llinfos
  120. bool bindDefaultImage(S32 stage = 0) override;
  121. LL_INLINE void forceImmediateUpdate() override {}
  122. LL_INLINE const LLUUID& getID() const override { return mID; }
  123. void setBoostLevel(U32 level) override;
  124. void addTextureStats(F32 virtual_size,
  125. bool needs_gltexture = true) const;
  126. void resetTextureStats();
  127. LL_INLINE void setMaxVirtualSizeResetInterval(S32 interval) const
  128. {
  129. mMaxVirtualSizeResetInterval = interval;
  130. }
  131. LL_INLINE void resetMaxVirtualSizeResetCounter() const
  132. {
  133. mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;
  134. }
  135. LL_INLINE virtual F32 getMaxVirtualSize() { return mMaxVirtualSize; }
  136. void resetLastReferencedTime();
  137. F32 getElapsedLastReferenceTime();
  138. LL_INLINE void setKnownDrawSize(S32, S32) override {}
  139. virtual void addFace(U32 channel, LLFace* facep);
  140. virtual void removeFace(U32 channel, LLFace* facep);
  141. S32 getTotalNumFaces() const;
  142. S32 getNumFaces(U32 ch) const;
  143. LL_INLINE const ll_face_list_t* getFaceList(U32 ch) const
  144. {
  145. return ch < LLRender::NUM_TEXTURE_CHANNELS ? &mFaceList[ch] : NULL;
  146. }
  147. virtual void addVolume(U32 ch, LLVOVolume* volumep);
  148. virtual void removeVolume(U32 ch, LLVOVolume* volumep);
  149. LL_INLINE S32 getNumVolumes(U32 ch) const { return mNumVolumes[ch]; }
  150. LL_INLINE const ll_volume_list_t* getVolumeList(U32 ch) const
  151. {
  152. return &mVolumeList[ch];
  153. }
  154. LL_INLINE virtual void setCachedRawImage(S32 discard_level,
  155. LLImageRaw* rawp)
  156. {
  157. }
  158. LL_INLINE bool isLargeImage()
  159. {
  160. return mTexelsPerImage > sMinLargeImageSize;
  161. }
  162. LL_INLINE void setParcelMedia(LLViewerMediaTexture* m) { mParcelMedia = m; }
  163. LL_INLINE bool hasParcelMedia() const { return mParcelMedia != NULL; }
  164. LL_INLINE LLViewerMediaTexture* getParcelMedia() const { return mParcelMedia; }
  165. LL_INLINE static bool inLowMemCondition()
  166. {
  167. constexpr F32 LOW_MEM_COND_DURATION = 30.f;
  168. return sCurrentTime < sLastLowMemCondTime + LOW_MEM_COND_DURATION;
  169. }
  170. // Called on sim change, to start texture loading afresh. With 'reset_bias'
  171. // set to true (used on far TP arrival), the discard bias is reset below
  172. // the limit at which the texture boost is cancelled. HB
  173. static void resetLowMemCondition(bool reset_bias = false);
  174. private:
  175. LL_INLINE virtual void switchToCachedImage() {}
  176. // Returns false when enough VRAM (and discard unchanged), or true when
  177. // short on VRAM, with discard updated. can_decrease_bias is set to false
  178. // whenever the algorithm predicts too tight a memory conditions on next
  179. // check (even if this check passed and true is returned) and, of course,
  180. // whenever the method returns true. HB
  181. static bool isMemoryForTextureLow(F32& discard, bool& can_decrease_bias);
  182. protected:
  183. // Do not use LLPointer here.
  184. LLViewerMediaTexture* mParcelMedia;
  185. LLUUID mID;
  186. // The largest virtual size of the image, in pixels: how much data to we
  187. // need ?
  188. mutable F32 mMaxVirtualSize;
  189. mutable S32 mMaxVirtualSizeResetCounter;
  190. mutable S32 mMaxVirtualSizeResetInterval;
  191. // Priority adding to mDecodePriority.
  192. mutable F32 mAdditionalDecodePriority;
  193. F32 mLastReferencedTime;
  194. F32 mLastFaceListUpdate;
  195. F32 mLastVolumeListUpdate;
  196. U32 mNumFaces[LLRender::NUM_TEXTURE_CHANNELS];
  197. U32 mNumVolumes[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
  198. // Reverse pointer pointing to the faces using this image as texture
  199. ll_face_list_t mFaceList[LLRender::NUM_TEXTURE_CHANNELS];
  200. ll_volume_list_t mVolumeList[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
  201. public:
  202. // "Null" texture for non-textured objects.
  203. static LLPointer<LLViewerTexture> sNullImagep;
  204. // Texture for rezzing avatars particle cloud
  205. static LLPointer<LLViewerTexture> sCloudImagep;
  206. static S32 sImageCount;
  207. static S32 sRawCount;
  208. static S32 sAuxCount;
  209. static F32 sDesiredDiscardBias;
  210. static S32 sBoundTexMemoryMB;
  211. static S32 sLastBoundTexMemoryMB;
  212. static S32 sTotalTexMemoryMB;
  213. static S32 sLastTotalTexMemoryMB;
  214. static S32 sMaxBoundTexMemMB;
  215. static S32 sMaxTotalTexMemMB;
  216. static S32 sLastFreeVRAMMB;
  217. static S32 sMinLargeImageSize;
  218. static S32 sMaxSmallImageSize;
  219. static F32 sCurrentTime;
  220. static F32 sNextDiscardBiasUpdateTime;
  221. static F32 sLastDiscardDecreaseTime;
  222. static F32 sLastLowMemCondTime;
  223. static bool sALMTexPenalty;
  224. static bool sDontLoadVolumeTextures;
  225. };
  226. constexpr S32 MAX_SCULPT_REZ = 128; // Maximum sculpt image size
  227. enum FTType
  228. {
  229. FTT_UNKNOWN = -1,
  230. FTT_DEFAULT = 0, // Standard texture fetched by Id.
  231. FTT_SERVER_BAKE, // Texture fetched from the baking service.
  232. FTT_HOST_BAKE, // Baked tex uploaded by viewer and fetched from sim.
  233. FTT_MAP_TILE, // Tiles fetched from map server.
  234. FTT_LOCAL_FILE // Fetched directly from a local file.
  235. };
  236. const std::string& fttype_to_string(const FTType& fttype);
  237. //
  238. // Textures are managed in gTextureList. Raw image data is fetched from remote
  239. // or local cache but the raw image this texture pointing to is fixed.
  240. //
  241. class LLViewerFetchedTexture : public LLViewerTexture
  242. {
  243. friend class LLTextureBar; // Debug info only
  244. friend class LLTextureView; // Debug info only
  245. protected:
  246. LOG_CLASS(LLViewerFetchedTexture);
  247. ~LLViewerFetchedTexture() override;
  248. public:
  249. LLViewerFetchedTexture(const LLUUID& id, FTType f_type,
  250. const LLHost& host = LLHost(),
  251. bool usemipmaps = true);
  252. LLViewerFetchedTexture(const LLImageRaw* rawp, FTType f_type,
  253. bool usemipmaps);
  254. LLViewerFetchedTexture(const std::string& url, FTType f_type,
  255. const LLUUID& id, bool usemipmaps = true);
  256. LL_INLINE LLViewerFetchedTexture* asFetched() override
  257. {
  258. return this;
  259. }
  260. static F32 maxDecodePriority();
  261. struct Compare
  262. {
  263. // lhs < rhs
  264. LL_INLINE bool operator()(const LLPointer<LLViewerFetchedTexture>& lhs,
  265. const LLPointer<LLViewerFetchedTexture>& rhs) const
  266. {
  267. const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs;
  268. const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs;
  269. // Greater priority is "less"
  270. const F32 lpriority = lhsp->getDecodePriority();
  271. const F32 rpriority = rhsp->getDecodePriority();
  272. if (lpriority > rpriority) // Higher priority
  273. {
  274. return true;
  275. }
  276. if (lpriority < rpriority)
  277. {
  278. return false;
  279. }
  280. return lhsp < rhsp;
  281. }
  282. };
  283. S8 getType() const override;
  284. LL_INLINE FTType getFTType() const { return mFTType; }
  285. void forceImmediateUpdate() override;
  286. void dump() override;
  287. // Set callbacks to get called when the image gets updated with higher
  288. // resolution versions.
  289. void setLoadedCallback(loaded_callback_func cb, S32 discard_level,
  290. bool keep_imageraw, bool needs_aux, void* userdata,
  291. uuid_list_t* cbs, bool pause = false);
  292. LL_INLINE bool hasCallbacks() { return !mLoadedCallbackList.empty(); }
  293. void pauseLoadedCallbacks(const uuid_list_t* cb_list);
  294. void unpauseLoadedCallbacks(const uuid_list_t* cb_list);
  295. bool doLoadedCallbacks();
  296. void deleteCallbackEntry(const uuid_list_t* cb_list);
  297. void clearCallbackEntryList();
  298. void addToCreateTexture();
  299. // ONLY call from LLViewerTextureList to determine if a call to
  300. // createTexture() is necessary.
  301. bool preCreateTexture(S32 usename = 0);
  302. // ONLY call from LLViewerTextureList or ImageGL background thread
  303. bool createTexture(S32 usename = 0);
  304. void postCreateTexture();
  305. void scheduleCreateTexture();
  306. // Returns false when we cannot delete it, i.e. when mNeedsCreateTexture is
  307. // true. HB
  308. bool destroyTexture();
  309. virtual void processTextureStats();
  310. F32 calcDecodePriority();
  311. LL_INLINE bool needsAux() const { return mNeedsAux; }
  312. // Host we think might have this image, used for baked av textures.
  313. LL_INLINE void setTargetHost(LLHost host) { mTargetHost = host; }
  314. LL_INLINE LLHost getTargetHost() const { return mTargetHost; }
  315. // Set the decode priority for this image...
  316. // DON'T CALL THIS UNLESS YOU KNOW WHAT YOU'RE DOING, it can mess up
  317. // the priority list, and cause horrible things to happen.
  318. void setDecodePriority(F32 priority = -1.0f);
  319. LL_INLINE F32 getDecodePriority() const { return mDecodePriority; };
  320. void setAdditionalDecodePriority(F32 priority);
  321. void updateVirtualSize();
  322. LL_INLINE S32 getDesiredDiscardLevel() { return mDesiredDiscardLevel; }
  323. LL_INLINE void setMinDiscardLevel(S32 discard) { mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); }
  324. void setBoostLevel(U32 level) override;
  325. bool updateFetch();
  326. void clearFetchedResults(); // Clear all fetched results, for debug use.
  327. // Override the computation of discard levels if we know the exact output
  328. // size of the image. Used for UI textures to not decode, even if we have
  329. // more data.
  330. void setKnownDrawSize(S32 width, S32 height) override;
  331. void setIsMissingAsset(bool is_missing = true);
  332. LL_INLINE bool isMissingAsset() const override { return mIsMissingAsset; }
  333. // returns dimensions of original image for local files (before power of two scaling)
  334. // and returns 0 for all asset system images
  335. LL_INLINE S32 getOriginalWidth() { return mOrigWidth; }
  336. LL_INLINE S32 getOriginalHeight() { return mOrigHeight; }
  337. LL_INLINE bool isInImageList() const { return mInImageList; }
  338. LL_INLINE void setInImageList(bool flag) { mInImageList = flag; }
  339. LL_INLINE U32 getFetchPriority() const { return mFetchPriority; }
  340. LL_INLINE F32 getDownloadProgress() const { return mDownloadProgress; }
  341. LLImageRaw* reloadRawImage(S8 discard_level);
  342. void destroyRawImage();
  343. LL_INLINE bool needsToSaveRawImage() { return mForceToSaveRawImage || mSaveRawImage; }
  344. LL_INLINE const std::string& getUrl() const { return mUrl; }
  345. LL_INLINE void setUrl(const std::string& url) { mUrl = url; }
  346. void setDeletionCandidate();
  347. void setInactive();
  348. LL_INLINE bool isDeleted() { return mTextureState == DELETED; }
  349. LL_INLINE bool isInactive() { return mTextureState == INACTIVE; }
  350. LL_INLINE bool isDeletionCandidate() { return mTextureState == DELETION_CANDIDATE; }
  351. LL_INLINE bool getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
  352. void setForSculpt();
  353. LL_INLINE bool forSculpt() const { return mForSculpt; }
  354. LL_INLINE bool isForSculptOnly() const { return mForSculpt && !mNeedsGLTexture; }
  355. // Raw image management
  356. void checkCachedRawSculptImage();
  357. LL_INLINE LLImageRaw* getRawImage() const { return mRawImage; }
  358. LL_INLINE S32 getRawImageLevel() const { return mRawDiscardLevel; }
  359. LL_INLINE LLImageRaw* getCachedRawImage() const { return mCachedRawImage;}
  360. LL_INLINE S32 getCachedRawImageLevel() const { return mCachedRawDiscardLevel; }
  361. LL_INLINE bool isCachedRawImageReady() const { return mCachedRawImageReady; }
  362. LL_INLINE bool isRawImageValid() const { return mIsRawImageValid; }
  363. void forceToSaveRawImage(S32 desired_discard = 0, F32 kept_time = 0.f);
  364. void forceToRefetchTexture(S32 desired_discard = 0, F32 kept_time = 60.f);
  365. void setCachedRawImage(S32 discard_level, LLImageRaw* rawp) override;
  366. void destroySavedRawImage();
  367. LLImageRaw* getSavedRawImage();
  368. LL_INLINE bool hasSavedRawImage() const { return mSavedRawImage.notNull(); }
  369. F32 getElapsedLastReferencedSavedRawImageTime() const;
  370. bool isFullyLoaded() const;
  371. LL_INLINE bool hasFetcher() const { return mHasFetcher;}
  372. LL_INLINE void setCanUseHTTP(bool can_use_http) { mCanUseHTTP = can_use_http; }
  373. // Forces to re-fetch an image (for corrupted ones). HB
  374. void forceRefetch();
  375. // Mark request for fetch as deleted to avoid false missing asset issues.
  376. // HB
  377. void requestWasDeleted();
  378. protected:
  379. void switchToCachedImage() override;
  380. S32 getCurrentDiscardLevelForFetching();
  381. private:
  382. void init(bool firstinit);
  383. void cleanup();
  384. void saveRawImage();
  385. void setCachedRawImage();
  386. void setCachedRawImagePtr(LLImageRaw* rawp);
  387. public:
  388. // Texture to show NOTHING (whiteness)
  389. static LLPointer<LLViewerFetchedTexture> sWhiteImagep;
  390. // "Default" texture for error cases, the only case of fetched texture
  391. // which is generated in local.
  392. static LLPointer<LLViewerFetchedTexture> sDefaultImagep;
  393. // Old "Default" translucent texture
  394. static LLPointer<LLViewerFetchedTexture> sSmokeImagep;
  395. // Flat normal map denoting no bumpiness on a surface
  396. static LLPointer<LLViewerFetchedTexture> sFlatNormalImagep;
  397. // Default Sun image
  398. static LLPointer<LLViewerFetchedTexture> sDefaultSunImagep;
  399. // Default Moon image
  400. static LLPointer<LLViewerFetchedTexture> sDefaultMoonImagep;
  401. // Default Clouds image
  402. static LLPointer<LLViewerFetchedTexture> sDefaultCloudsImagep;
  403. // Cloud noise image
  404. static LLPointer<LLViewerFetchedTexture> sDefaultCloudNoiseImagep;
  405. // Bloom image
  406. static LLPointer<LLViewerFetchedTexture> sBloomImagep;
  407. // Opaque water image
  408. static LLPointer<LLViewerFetchedTexture> sOpaqueWaterImagep;
  409. // Transparent water image
  410. static LLPointer<LLViewerFetchedTexture> sWaterImagep;
  411. // Water normal map
  412. static LLPointer<LLViewerFetchedTexture> sWaterNormapMapImagep;
  413. // PBR irradiance
  414. static LLPointer<LLViewerFetchedTexture> sDefaultIrradiancePBRp;
  415. // Stats (used in lltextureview.cpp)
  416. static U32 sMainThreadCreations;
  417. static U32 sImageThreadCreations;
  418. static U32 sImageThreadQueueSize;
  419. static bool sImageThreadCreationsCapped;
  420. protected:
  421. S32 mOrigWidth;
  422. S32 mOrigHeight;
  423. // Override the computation of discard levels if we know the exact output
  424. // size of the image. Used for UI textures to not decode, even if we have
  425. // more data.
  426. S32 mKnownDrawWidth;
  427. S32 mKnownDrawHeight;
  428. S32 mRequestedDiscardLevel;
  429. F32 mRequestedDownloadPriority;
  430. S32 mFetchState;
  431. U32 mFetchPriority;
  432. F32 mDownloadProgress;
  433. F32 mFetchDeltaTime;
  434. F32 mRequestDeltaTime;
  435. // The priority for decoding this image.
  436. F32 mDecodePriority;
  437. S32 mMinDiscardLevel;
  438. // The discard level we'd LIKE to have - if we have it and there's space
  439. S8 mDesiredDiscardLevel;
  440. // The minimum discard level we would like to have
  441. S8 mMinDesiredDiscardLevel;
  442. // Result of the most recently completed http request for this texture.
  443. LLCore::HttpStatus mLastHttpGetStatus;
  444. // If invalid, just request from agent's simulator
  445. LLHost mTargetHost;
  446. FTType mFTType; // What category of image is this ?
  447. typedef std::list<LLLoadedCallbackEntry*> callback_list_t;
  448. callback_list_t mLoadedCallbackList;
  449. F32 mLastCallBackActiveTime;
  450. LLPointer<LLImageRaw> mRawImage;
  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. LLPointer<LLImageRaw> mSavedRawImage;
  455. // A small version of the copy of the raw image (<= 64 * 64)
  456. LLPointer<LLImageRaw> mCachedRawImage;
  457. S32 mCachedRawDiscardLevel;
  458. S32 mRawDiscardLevel;
  459. S32 mSavedRawDiscardLevel;
  460. S32 mDesiredSavedRawDiscardLevel;
  461. F32 mLastReferencedSavedRawImageTime;
  462. F32 mKeptSavedRawImageTime;
  463. // Timing
  464. // Last time a packet was received.
  465. F32 mLastPacketTime;
  466. // Last time mDecodePriority was zeroed.
  467. F32 mStopFetchingTime;
  468. S8 mLoadedCallbackDesiredDiscardLevel;
  469. // true if we know that there is no image asset with this image id in the
  470. // database.
  471. mutable bool mIsMissingAsset;
  472. // true if we deleted the fetch request in flight: used to avoid false
  473. // missing asset cases.
  474. mutable bool mWasDeleted;
  475. // We need to decode the auxiliary channels
  476. bool mNeedsAux;
  477. bool mHasAux; // We do have aux channels
  478. bool mIsRawImageValid;
  479. bool mHasFetcher; // We have made a fecth request
  480. bool mIsFetching; // Fetch request is active
  481. // This texture can be fetched through http if true.
  482. bool mCanUseHTTP;
  483. bool mKnownDrawSizeChanged;
  484. bool mPauseLoadedCallBacks;
  485. // Keep a copy of mRawImage for some special purposes when
  486. // mForceToSaveRawImage is set.
  487. bool mForceToSaveRawImage;
  488. bool mSaveRawImage;
  489. // The rez of the mCachedRawImage reaches the upper limit.
  490. bool mCachedRawImageReady;
  491. // A flag if the texture is used as sculpt data.
  492. bool mForSculpt;
  493. // true if image is in list (in which case do not reset priority !)
  494. bool mInImageList;
  495. // This needs to be atomic, since it is written both in the main thread
  496. // and in the GL image worker thread... HB
  497. LLAtomicBool mNeedsCreateTexture;
  498. std::string mLocalFileName;
  499. std::string mUrl;
  500. private:
  501. bool mFullyLoaded;
  502. bool mForceCallbackFetch;
  503. };
  504. //
  505. // The image data is fetched from remote or from local cache. The resolution of
  506. // the texture is adjustable: depends on the view-dependent parameters.
  507. //
  508. class LLViewerLODTexture final : public LLViewerFetchedTexture
  509. {
  510. protected:
  511. LOG_CLASS(LLViewerLODTexture);
  512. ~LLViewerLODTexture() override = default;
  513. public:
  514. LLViewerLODTexture(const LLUUID& id, FTType f_type,
  515. const LLHost& host = LLHost(),
  516. bool usemipmaps = true);
  517. LLViewerLODTexture(const std::string& url, FTType f_type,
  518. const LLUUID& id, bool usemipmaps = true);
  519. S8 getType() const override;
  520. // Process image stats to determine priority/quality requirements.
  521. void processTextureStats() override;
  522. bool isUpdateFrozen();
  523. private:
  524. void init(bool firstinit);
  525. bool scaleDown();
  526. private:
  527. // Virtual size used to calculate desired discard
  528. F32 mDiscardVirtualSize;
  529. // Last calculated discard level
  530. F32 mCalculatedDiscardLevel;
  531. };
  532. //
  533. // The image data is fetched from the media pipeline periodically; the
  534. // resolution of the texture is also adjusted by the media pipeline.
  535. //
  536. class LLViewerMediaTexture final : public LLViewerTexture
  537. {
  538. protected:
  539. LOG_CLASS(LLViewerMediaTexture);
  540. ~LLViewerMediaTexture() override;
  541. public:
  542. LLViewerMediaTexture(const LLUUID& id, bool usemipmaps = true,
  543. LLImageGL* gl_image = NULL);
  544. S8 getType() const override;
  545. void reinit(bool usemipmaps = true);
  546. LL_INLINE bool getUseMipMaps() { return mUseMipMaps; }
  547. void setUseMipMaps(bool mipmap);
  548. void setPlaying(bool playing);
  549. LL_INLINE bool isPlaying() const { return mIsPlaying; }
  550. void setMediaImpl();
  551. void initVirtualSize();
  552. void invalidateMediaImpl();
  553. void addMediaToFace(LLFace* facep);
  554. void removeMediaFromFace(LLFace* facep);
  555. LL_INLINE bool isViewerMediaTexture() const override { return true; }
  556. void addFace(U32 ch, LLFace* facep) override;
  557. void removeFace(U32 ch, LLFace* facep) override;
  558. F32 getMaxVirtualSize() override;
  559. static void updateClass();
  560. static void cleanUpClass();
  561. static LLViewerMediaTexture* findMediaTexture(const LLUUID& media_id);
  562. static void removeMediaImplFromTexture(const LLUUID& media_id);
  563. private:
  564. void switchTexture(U32 ch, LLFace* facep);
  565. bool findFaces();
  566. void stopPlaying();
  567. private:
  568. // An instant list, recording all faces referencing or can reference to
  569. // this media texture. NOTE: it is NOT thread safe.
  570. std::list<LLFace*> mMediaFaceList;
  571. // An instant list keeping all textures which are replaced by the current
  572. // media texture, is only used to avoid the removal of those textures from
  573. // memory.
  574. std::list<LLPointer<LLViewerTexture> > mTextureList;
  575. LLViewerMediaImpl* mMediaImplp;
  576. U32 mUpdateVirtualSizeTime;
  577. bool mIsPlaying;
  578. typedef fast_hmap<LLUUID, LLPointer<LLViewerMediaTexture> > media_map_t;
  579. static media_map_t sMediaMap;
  580. };
  581. // Purely static class
  582. class LLViewerTextureManager
  583. {
  584. LLViewerTextureManager() = delete;
  585. ~LLViewerTextureManager() = delete;
  586. protected:
  587. LOG_CLASS(LLViewerTextureManager);
  588. public:
  589. // Returns NULL if tex is not a LLViewerFetchedTexture nor derived from
  590. // LLViewerFetchedTexture.
  591. static LLViewerFetchedTexture* staticCast(LLGLTexture* tex,
  592. bool report_error = false);
  593. // "find-texture" just check if the texture exists, if yes, return it,
  594. // otherwise return null.
  595. static LLViewerTexture* findTexture(const LLUUID& id);
  596. static LLViewerMediaTexture* findMediaTexture(const LLUUID& id);
  597. static LLViewerMediaTexture* createMediaTexture(const LLUUID& id,
  598. bool usemipmaps = true,
  599. LLImageGL* gl_image = NULL);
  600. // get*Texture*() methods create a new texture when it does not exist.
  601. // NOTE: removed "usemipmaps" parameter since media texture always ended up
  602. // with mipmap generation turned off. *TODO: consider allowing it again and
  603. // actually using it in the future. HB
  604. static LLViewerMediaTexture* getMediaTexture(const LLUUID& id,
  605. LLImageGL* gl_image = NULL);
  606. static LLPointer<LLViewerTexture> getLocalTexture(bool usemipmaps = true,
  607. bool generate_gl_tex = true);
  608. static LLPointer<LLViewerTexture> getLocalTexture(const LLUUID& id,
  609. bool usemipmaps,
  610. bool generate_gl_tex = true);
  611. static LLPointer<LLViewerTexture> getLocalTexture(const LLImageRaw* rawp,
  612. bool usemipmaps);
  613. static LLPointer<LLViewerTexture> getLocalTexture(U32 width, U32 height,
  614. U8 components,
  615. bool usemipmaps,
  616. bool generate_gl_tex = true);
  617. static LLViewerFetchedTexture* getFetchedTexture(const LLImageRaw* rawp,
  618. FTType type = FTT_LOCAL_FILE,
  619. bool usemipmaps = true);
  620. static LLViewerFetchedTexture* getFetchedTexture(const LLUUID& image_id,
  621. FTType f_type = FTT_DEFAULT,
  622. bool usemipmap = true,
  623. // Get the requested level immediately upon creation.
  624. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  625. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  626. S32 internal_format = 0,
  627. U32 primary_format = 0,
  628. LLHost request_from_host = LLHost());
  629. static LLViewerFetchedTexture* getFetchedTextureFromFile(const std::string& filename,
  630. bool usemipmap = true,
  631. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_UI,
  632. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  633. S32 internal_format = 0,
  634. U32 primary_format = 0,
  635. const LLUUID& force_id = LLUUID::null);
  636. static LLViewerFetchedTexture* getFetchedTextureFromUrl(const std::string& url,
  637. FTType f_type,
  638. bool usemipmap = true,
  639. LLGLTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
  640. S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
  641. S32 internal_format = 0,
  642. U32 primary_format = 0,
  643. const LLUUID& force_id = LLUUID::null);
  644. static LLViewerFetchedTexture* getFetchedTextureFromHost(const LLUUID& image_id,
  645. FTType f_type,
  646. LLHost host);
  647. static void init();
  648. static void cleanup();
  649. };
  650. #endif