PageRenderTime 38ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lltexlayer.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 378 lines | 262 code | 38 blank | 78 comment | 0 complexity | 51639be21860531409f729c2e4e25a0b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltexlayer.h
  3. * @brief Texture layer classes. Used for avatars.
  4. *
  5. * $LicenseInfo:firstyear=2002&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_LLTEXLAYER_H
  27. #define LL_LLTEXLAYER_H
  28. #include <deque>
  29. #include "lldynamictexture.h"
  30. #include "llvoavatardefines.h"
  31. #include "lltexlayerparams.h"
  32. class LLVOAvatar;
  33. class LLVOAvatarSelf;
  34. class LLImageTGA;
  35. class LLImageRaw;
  36. class LLXmlTreeNode;
  37. class LLTexLayerSet;
  38. class LLTexLayerSetInfo;
  39. class LLTexLayerInfo;
  40. class LLTexLayerSetBuffer;
  41. class LLWearable;
  42. class LLViewerVisualParam;
  43. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. // LLTexLayerInterface
  45. //
  46. // Interface class to generalize functionality shared by LLTexLayer
  47. // and LLTexLayerTemplate.
  48. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. class LLTexLayerInterface
  50. {
  51. public:
  52. enum ERenderPass
  53. {
  54. RP_COLOR,
  55. RP_BUMP,
  56. RP_SHINE
  57. };
  58. LLTexLayerInterface(LLTexLayerSet* const layer_set);
  59. LLTexLayerInterface(const LLTexLayerInterface &layer, LLWearable *wearable);
  60. virtual ~LLTexLayerInterface() {}
  61. virtual BOOL render(S32 x, S32 y, S32 width, S32 height) = 0;
  62. virtual void deleteCaches() = 0;
  63. virtual BOOL blendAlphaTexture(S32 x, S32 y, S32 width, S32 height) = 0;
  64. virtual BOOL isInvisibleAlphaMask() const = 0;
  65. const LLTexLayerInfo* getInfo() const { return mInfo; }
  66. virtual BOOL setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // sets mInfo, calls initialization functions
  67. const std::string& getName() const;
  68. const LLTexLayerSet* const getTexLayerSet() const { return mTexLayerSet; }
  69. LLTexLayerSet* const getTexLayerSet() { return mTexLayerSet; }
  70. void invalidateMorphMasks();
  71. virtual void setHasMorph(BOOL newval) { mHasMorph = newval; }
  72. BOOL hasMorph() const { return mHasMorph; }
  73. BOOL isMorphValid() const { return mMorphMasksValid; }
  74. void requestUpdate();
  75. virtual void gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height) = 0;
  76. BOOL hasAlphaParams() const { return !mParamAlphaList.empty(); }
  77. ERenderPass getRenderPass() const;
  78. BOOL isVisibilityMask() const;
  79. protected:
  80. const std::string& getGlobalColor() const;
  81. LLViewerVisualParam* getVisualParamPtr(S32 index) const;
  82. protected:
  83. LLTexLayerSet* const mTexLayerSet;
  84. const LLTexLayerInfo* mInfo;
  85. BOOL mMorphMasksValid;
  86. BOOL mHasMorph;
  87. // Layers can have either mParamColorList, mGlobalColor, or mFixedColor. They are looked for in that order.
  88. param_color_list_t mParamColorList;
  89. param_alpha_list_t mParamAlphaList;
  90. // mGlobalColor name stored in mInfo
  91. // mFixedColor value stored in mInfo
  92. };
  93. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. // LLTexLayerTemplate
  95. //
  96. // Only exists for llvoavatarself.
  97. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. class LLTexLayerTemplate : public LLTexLayerInterface
  99. {
  100. public:
  101. LLTexLayerTemplate(LLTexLayerSet* const layer_set);
  102. LLTexLayerTemplate(const LLTexLayerTemplate &layer);
  103. /*virtual*/ ~LLTexLayerTemplate();
  104. /*virtual*/ BOOL render(S32 x, S32 y, S32 width, S32 height);
  105. /*virtual*/ BOOL setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // This sets mInfo and calls initialization functions
  106. /*virtual*/ BOOL blendAlphaTexture(S32 x, S32 y, S32 width, S32 height); // Multiplies a single alpha texture against the frame buffer
  107. /*virtual*/ void gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
  108. /*virtual*/ void setHasMorph(BOOL newval);
  109. /*virtual*/ void deleteCaches();
  110. /*virtual*/ BOOL isInvisibleAlphaMask() const;
  111. protected:
  112. U32 updateWearableCache() const;
  113. LLTexLayer* getLayer(U32 i) const;
  114. private:
  115. typedef std::vector<LLWearable*> wearable_cache_t;
  116. mutable wearable_cache_t mWearableCache; // mutable b/c most get- require updating this cache
  117. };
  118. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. // LLTexLayer
  120. //
  121. // A single texture layer. Only exists for llvoavatarself.
  122. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. class LLTexLayer : public LLTexLayerInterface
  124. {
  125. public:
  126. LLTexLayer(LLTexLayerSet* const layer_set);
  127. LLTexLayer(const LLTexLayer &layer, LLWearable *wearable);
  128. LLTexLayer(const LLTexLayerTemplate &layer_template, LLLocalTextureObject *lto, LLWearable *wearable);
  129. /*virtual*/ ~LLTexLayer();
  130. /*virtual*/ BOOL setInfo(const LLTexLayerInfo *info, LLWearable* wearable); // This sets mInfo and calls initialization functions
  131. /*virtual*/ BOOL render(S32 x, S32 y, S32 width, S32 height);
  132. /*virtual*/ void deleteCaches();
  133. const U8* getAlphaData() const;
  134. BOOL findNetColor(LLColor4* color) const;
  135. /*virtual*/ BOOL blendAlphaTexture(S32 x, S32 y, S32 width, S32 height); // Multiplies a single alpha texture against the frame buffer
  136. /*virtual*/ void gatherAlphaMasks(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
  137. BOOL renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLColor4 &layer_color);
  138. void addAlphaMask(U8 *data, S32 originX, S32 originY, S32 width, S32 height);
  139. /*virtual*/ BOOL isInvisibleAlphaMask() const;
  140. void setLTO(LLLocalTextureObject *lto) { mLocalTextureObject = lto; }
  141. LLLocalTextureObject* getLTO() { return mLocalTextureObject; }
  142. static void calculateTexLayerColor(const param_color_list_t &param_list, LLColor4 &net_color);
  143. protected:
  144. LLUUID getUUID() const;
  145. private:
  146. typedef std::map<U32, U8*> alpha_cache_t;
  147. alpha_cache_t mAlphaCache;
  148. LLLocalTextureObject* mLocalTextureObject;
  149. };
  150. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. // LLTexLayerSet
  152. //
  153. // An ordered set of texture layers that gets composited into a single texture.
  154. // Only exists for llvoavatarself.
  155. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. class LLTexLayerSet
  157. {
  158. friend class LLTexLayerSetBuffer;
  159. public:
  160. LLTexLayerSet(LLVOAvatarSelf* const avatar);
  161. ~LLTexLayerSet();
  162. const LLTexLayerSetInfo* getInfo() const { return mInfo; }
  163. BOOL setInfo(const LLTexLayerSetInfo *info); // This sets mInfo and calls initialization functions
  164. BOOL render(S32 x, S32 y, S32 width, S32 height);
  165. void renderAlphaMaskTextures(S32 x, S32 y, S32 width, S32 height, bool forceClear = false);
  166. BOOL isBodyRegion(const std::string& region) const;
  167. LLTexLayerSetBuffer* getComposite();
  168. const LLTexLayerSetBuffer* getComposite() const; // Do not create one if it doesn't exist.
  169. void requestUpdate();
  170. void requestUpload();
  171. void cancelUpload();
  172. void updateComposite();
  173. BOOL isLocalTextureDataAvailable() const;
  174. BOOL isLocalTextureDataFinal() const;
  175. void createComposite();
  176. void destroyComposite();
  177. void setUpdatesEnabled(BOOL b);
  178. BOOL getUpdatesEnabled() const { return mUpdatesEnabled; }
  179. void deleteCaches();
  180. void gatherMorphMaskAlpha(U8 *data, S32 width, S32 height);
  181. void applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components);
  182. BOOL isMorphValid() const;
  183. void invalidateMorphMasks();
  184. LLTexLayerInterface* findLayerByName(const std::string& name);
  185. void cloneTemplates(LLLocalTextureObject *lto, LLVOAvatarDefines::ETextureIndex tex_index, LLWearable* wearable);
  186. LLVOAvatarSelf* getAvatar() const { return mAvatar; }
  187. const std::string getBodyRegionName() const;
  188. BOOL hasComposite() const { return (mComposite.notNull()); }
  189. LLVOAvatarDefines::EBakedTextureIndex getBakedTexIndex() { return mBakedTexIndex; }
  190. void setBakedTexIndex(LLVOAvatarDefines::EBakedTextureIndex index) { mBakedTexIndex = index; }
  191. BOOL isVisible() const { return mIsVisible; }
  192. static BOOL sHasCaches;
  193. private:
  194. typedef std::vector<LLTexLayerInterface *> layer_list_t;
  195. layer_list_t mLayerList;
  196. layer_list_t mMaskLayerList;
  197. LLPointer<LLTexLayerSetBuffer> mComposite;
  198. LLVOAvatarSelf* const mAvatar; // note: backlink only; don't make this an LLPointer.
  199. BOOL mUpdatesEnabled;
  200. BOOL mIsVisible;
  201. LLVOAvatarDefines::EBakedTextureIndex mBakedTexIndex;
  202. const LLTexLayerSetInfo* mInfo;
  203. };
  204. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  205. // LLTexLayerSetInfo
  206. //
  207. // Contains shared layer set data.
  208. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. class LLTexLayerSetInfo
  210. {
  211. friend class LLTexLayerSet;
  212. public:
  213. LLTexLayerSetInfo();
  214. ~LLTexLayerSetInfo();
  215. BOOL parseXml(LLXmlTreeNode* node);
  216. void createVisualParams(LLVOAvatar *avatar);
  217. private:
  218. std::string mBodyRegion;
  219. S32 mWidth;
  220. S32 mHeight;
  221. std::string mStaticAlphaFileName;
  222. BOOL mClearAlpha; // Set alpha to 1 for this layerset (if there is no mStaticAlphaFileName)
  223. typedef std::vector<LLTexLayerInfo*> layer_info_list_t;
  224. layer_info_list_t mLayerInfoList;
  225. };
  226. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  227. // LLTexLayerSetBuffer
  228. //
  229. // The composite image that a LLTexLayerSet writes to. Each LLTexLayerSet has one.
  230. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. class LLTexLayerSetBuffer : public LLViewerDynamicTexture
  232. {
  233. public:
  234. LLTexLayerSetBuffer(LLTexLayerSet* const owner, S32 width, S32 height);
  235. virtual ~LLTexLayerSetBuffer();
  236. public:
  237. /*virtual*/ S8 getType() const;
  238. BOOL isInitialized(void) const;
  239. static void dumpTotalByteCount();
  240. const std::string dumpTextureInfo() const;
  241. virtual void restoreGLTexture();
  242. virtual void destroyGLTexture();
  243. protected:
  244. void pushProjection() const;
  245. void popProjection() const;
  246. private:
  247. LLTexLayerSet* const mTexLayerSet;
  248. static S32 sGLByteCount;
  249. //--------------------------------------------------------------------
  250. // Render
  251. //--------------------------------------------------------------------
  252. public:
  253. /*virtual*/ BOOL needsRender();
  254. protected:
  255. BOOL render(S32 x, S32 y, S32 width, S32 height);
  256. virtual void preRender(BOOL clear_depth);
  257. virtual void postRender(BOOL success);
  258. virtual BOOL render();
  259. //--------------------------------------------------------------------
  260. // Uploads
  261. //--------------------------------------------------------------------
  262. public:
  263. void requestUpload();
  264. void cancelUpload();
  265. BOOL uploadNeeded() const; // We need to upload a new texture
  266. BOOL uploadInProgress() const; // We have started uploading a new texture and are awaiting the result
  267. BOOL uploadPending() const; // We are expecting a new texture to be uploaded at some point
  268. static void onTextureUploadComplete(const LLUUID& uuid,
  269. void* userdata,
  270. S32 result, LLExtStat ext_status);
  271. protected:
  272. BOOL isReadyToUpload() const;
  273. void doUpload(); // Does a read back and upload.
  274. void conditionalRestartUploadTimer();
  275. private:
  276. BOOL mNeedsUpload; // Whether we need to send our baked textures to the server
  277. U32 mNumLowresUploads; // Number of times we've sent a lowres version of our baked textures to the server
  278. BOOL mUploadPending; // Whether we have received back the new baked textures
  279. LLUUID mUploadID; // The current upload process (null if none).
  280. LLFrameTimer mNeedsUploadTimer; // Tracks time since upload was requested and performed.
  281. S32 mUploadFailCount; // Number of consecutive upload failures
  282. LLFrameTimer mUploadRetryTimer; // Tracks time since last upload failure.
  283. //--------------------------------------------------------------------
  284. // Updates
  285. //--------------------------------------------------------------------
  286. public:
  287. void requestUpdate();
  288. BOOL requestUpdateImmediate();
  289. protected:
  290. BOOL isReadyToUpdate() const;
  291. void doUpdate();
  292. void restartUpdateTimer();
  293. private:
  294. BOOL mNeedsUpdate; // Whether we need to locally update our baked textures
  295. U32 mNumLowresUpdates; // Number of times we've locally updated with lowres version of our baked textures
  296. LLFrameTimer mNeedsUpdateTimer; // Tracks time since update was requested and performed.
  297. };
  298. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  299. // LLTexLayerStaticImageList
  300. //
  301. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. class LLTexLayerStaticImageList : public LLSingleton<LLTexLayerStaticImageList>
  303. {
  304. public:
  305. LLTexLayerStaticImageList();
  306. ~LLTexLayerStaticImageList();
  307. LLViewerTexture* getTexture(const std::string& file_name, BOOL is_mask);
  308. LLImageTGA* getImageTGA(const std::string& file_name);
  309. void deleteCachedImages();
  310. void dumpByteCount() const;
  311. protected:
  312. BOOL loadImageRaw(const std::string& file_name, LLImageRaw* image_raw);
  313. private:
  314. LLStringTable mImageNames;
  315. typedef std::map<const char*, LLPointer<LLViewerTexture> > texture_map_t;
  316. texture_map_t mStaticImageList;
  317. typedef std::map<const char*, LLPointer<LLImageTGA> > image_tga_map_t;
  318. image_tga_map_t mStaticImageListTGA;
  319. S32 mGLBytes;
  320. S32 mTGABytes;
  321. };
  322. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  323. // LLBakedUploadData
  324. //
  325. // Used by LLTexLayerSetBuffer for a callback.
  326. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. struct LLBakedUploadData
  328. {
  329. LLBakedUploadData(const LLVOAvatarSelf* avatar,
  330. LLTexLayerSet* layerset,
  331. const LLUUID& id,
  332. bool highest_res);
  333. ~LLBakedUploadData() {}
  334. const LLUUID mID;
  335. const LLVOAvatarSelf* mAvatar; // note: backlink only; don't LLPointer
  336. LLTexLayerSet* mTexLayerSet;
  337. const U64 mStartTime; // for measuring baked texture upload time
  338. const bool mIsHighestRes; // whether this is a "final" bake, or intermediate low res
  339. };
  340. #endif // LL_LLTEXLAYER_H