llviewertexlayer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * @file llviewertexlayer.h
  3. * @brief Viewer texture layer classes. Used for avatars.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, 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_VIEWER_TEXLAYER_H
  33. #define LL_VIEWER_TEXLAYER_H
  34. #include "llavatarappearance.h"
  35. #include "llextendedstatus.h"
  36. #include "lltexlayer.h"
  37. #include "lluuid.h"
  38. #include "lldynamictexture.h"
  39. class LLVOAvatarSelf;
  40. class LLViewerTexLayerSetBuffer;
  41. struct LLBakedUploadData;
  42. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // LLViewerTexLayerSet
  44. //
  45. // An ordered set of texture layers that gets composited into a single texture.
  46. // Only exists for llavatarappearanceself.
  47. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. class LLViewerTexLayerSet final : public LLTexLayerSet
  49. {
  50. public:
  51. LLViewerTexLayerSet(LLAvatarAppearance* const appearance);
  52. LL_INLINE LLViewerTexLayerSet* asViewerTexLayerSet() override
  53. {
  54. return this;
  55. }
  56. void requestUpdate() override;
  57. void requestUpload();
  58. void cancelUpload();
  59. bool isLocalTextureDataAvailable();
  60. bool isLocalTextureDataFinal();
  61. void updateComposite();
  62. void createComposite() override;
  63. LL_INLINE void setUpdatesEnabled(bool b) { mUpdatesEnabled = b; }
  64. LL_INLINE bool getUpdatesEnabled() const { return mUpdatesEnabled; }
  65. LLVOAvatarSelf* getAvatar();
  66. const LLVOAvatarSelf* getAvatar() const;
  67. LLViewerTexLayerSetBuffer* getViewerComposite();
  68. private:
  69. bool mUpdatesEnabled;
  70. };
  71. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. // LLViewerTexLayerSetBuffer
  73. //
  74. // The composite image that a LLViewerTexLayerSetBuffer writes to. Each
  75. // LLViewerTexLayerSetBuffer has one.
  76. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. class LLViewerTexLayerSetBuffer final : public LLTexLayerSetBuffer,
  78. public LLViewerDynamicTexture
  79. {
  80. protected:
  81. LOG_CLASS(LLViewerTexLayerSetBuffer);
  82. public:
  83. LLViewerTexLayerSetBuffer(LLTexLayerSet* const owner,
  84. S32 width, S32 height);
  85. ~LLViewerTexLayerSetBuffer() override;
  86. LL_INLINE LLViewerTexLayerSetBuffer* asViewerTexLayerSetBuffer() override
  87. {
  88. return this;
  89. }
  90. S8 getType() const override;
  91. bool isInitialized() const;
  92. static void dumpTotalByteCount();
  93. LL_INLINE LLViewerTexLayerSet* getViewerTexLayerSet()
  94. {
  95. return mTexLayerSet ? mTexLayerSet->asViewerTexLayerSet() : NULL;
  96. }
  97. static void uploadBakedTextureCoro(const std::string& url, LLUUID vfile_id,
  98. LLBakedUploadData* data);
  99. //--------------------------------------------------------------------
  100. // Dynamic Texture Interface
  101. //--------------------------------------------------------------------
  102. bool needsRender() override;
  103. //--------------------------------------------------------------------
  104. // Tex Layer Render
  105. //--------------------------------------------------------------------
  106. private:
  107. void preRenderTexLayerSet() override;
  108. void midRenderTexLayerSet(bool success) override;
  109. void postRenderTexLayerSet(bool success) override;
  110. LL_INLINE S32 getCompositeOriginX() const override { return getOriginX(); }
  111. LL_INLINE S32 getCompositeOriginY() const override { return getOriginY(); }
  112. LL_INLINE S32 getCompositeWidth() const override { return getFullWidth(); }
  113. LL_INLINE S32 getCompositeHeight() const override { return getFullHeight(); }
  114. protected:
  115. // Pass these along for tex layer rendering.
  116. LL_INLINE void preRender(bool) override { preRenderTexLayerSet(); }
  117. LL_INLINE void postRender(bool success) override { postRenderTexLayerSet(success); }
  118. LL_INLINE bool render() override { return renderTexLayerSet(); }
  119. //--------------------------------------------------------------------
  120. // Uploads
  121. //--------------------------------------------------------------------
  122. public:
  123. void requestUpload();
  124. void cancelUpload();
  125. // We need to upload a new texture:
  126. LL_INLINE bool uploadNeeded() const { return mNeedsUpload; }
  127. // We have started uploading a new texture and are awaiting the result
  128. LL_INLINE bool uploadInProgress() const { return mUploadID.notNull(); }
  129. // We are expecting a new texture to be uploaded at some point
  130. LL_INLINE bool uploadPending() const { return mUploadPending; }
  131. static void onTextureUploadComplete(const LLUUID& uuid, void* userdata,
  132. S32 result,
  133. LLExtStat s = LLExtStat::NONE);
  134. protected:
  135. bool isReadyToUpload();
  136. void doUpload(); // Does a read back and upload.
  137. void conditionalRestartUploadTimer();
  138. //--------------------------------------------------------------------
  139. // Updates
  140. //--------------------------------------------------------------------
  141. public:
  142. void requestUpdate();
  143. bool requestUpdateImmediate();
  144. protected:
  145. bool isReadyToUpdate();
  146. void doUpdate();
  147. void restartUpdateTimer();
  148. private:
  149. // The current upload process (null if none).
  150. LLUUID mUploadID;
  151. // Tracks time since upload was requested and performed.
  152. LLFrameTimer mNeedsUploadTimer;
  153. // Tracks time since last upload failure.
  154. LLFrameTimer mUploadRetryTimer;
  155. // Tracks time since update was requested and performed.
  156. LLFrameTimer mNeedsUpdateTimer;
  157. // Number of times we have locally updated with lowres version of our baked
  158. // textures
  159. U32 mNumLowresUpdates;
  160. // Number of times we have sent a lowres version of our baked textures to
  161. // the server
  162. U32 mNumLowresUploads;
  163. // Number of consecutive upload failures
  164. S32 mUploadFailCount;
  165. // Whether we have received back the new baked textures
  166. bool mUploadPending;
  167. // Whether we need to send our baked textures to the server
  168. bool mNeedsUpload;
  169. // Whether we need to locally update our baked textures
  170. bool mNeedsUpdate;
  171. static S32 sGLByteCount;
  172. };
  173. #endif // LL_VIEWER_TEXLAYER_H