lltexlayer.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /**
  2. * @file lltexlayer.h
  3. * @brief 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_LLTEXLAYER_H
  33. #define LL_LLTEXLAYER_H
  34. #include <deque>
  35. #include <map>
  36. #include "llavatarappearancedefines.h"
  37. #include "hbfastmap.h"
  38. #include "llgl.h"
  39. #include "llgltexture.h"
  40. #include "llpreprocessor.h"
  41. #include "lltexlayerparams.h"
  42. class LLAvatarAppearance;
  43. class LLImageTGA;
  44. class LLImageRaw;
  45. class LLLocalTextureObject;
  46. class LLTexLayerInfo;
  47. class LLTexLayerSet;
  48. class LLTexLayerSetBuffer;
  49. class LLTexLayerSetInfo;
  50. class LLViewerTexLayerSet;
  51. class LLViewerTexLayerSetBuffer;
  52. class LLViewerVisualParam;
  53. class LLWearable;
  54. class LLXmlTreeNode;
  55. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. // LLTexLayerInterface
  57. // Interface class to generalize functionality shared by LLTexLayer and
  58. // LLTexLayerTemplate.
  59. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. class LLTexLayerInterface
  61. {
  62. public:
  63. enum ERenderPass
  64. {
  65. RP_COLOR,
  66. RP_BUMP,
  67. RP_SHINE
  68. };
  69. LLTexLayerInterface(LLTexLayerSet* const layer_set);
  70. LLTexLayerInterface(const LLTexLayerInterface& layer,
  71. LLWearable* wearable);
  72. virtual ~LLTexLayerInterface() = default;
  73. virtual bool render(S32 x, S32 y, S32 width, S32 height) = 0;
  74. virtual void deleteCaches() = 0;
  75. virtual bool blendAlphaTexture(S32 x, S32 y, S32 width, S32 height) = 0;
  76. virtual bool isInvisibleAlphaMask() const = 0;
  77. LL_INLINE const LLTexLayerInfo* getInfo() const { return mInfo; }
  78. // sets mInfo, calls initialization functions:
  79. virtual bool setInfo(const LLTexLayerInfo* info, LLWearable* wearable);
  80. LLWearableType::EType getWearableType() const;
  81. LLAvatarAppearanceDefines::ETextureIndex getLocalTextureIndex() const;
  82. const std::string& getName() const;
  83. LL_INLINE const LLTexLayerSet* const getTexLayerSet() const
  84. {
  85. return mTexLayerSet;
  86. }
  87. LL_INLINE LLTexLayerSet* const getTexLayerSet() { return mTexLayerSet; }
  88. void invalidateMorphMasks();
  89. LL_INLINE virtual void setHasMorph(bool newval) { mHasMorph = newval; }
  90. LL_INLINE bool hasMorph() const { return mHasMorph; }
  91. LL_INLINE bool isMorphValid() const { return mMorphMasksValid; }
  92. void requestUpdate();
  93. virtual void gatherAlphaMasks(U8* datap, S32 origin_x, S32 origin_y,
  94. S32 width, S32 height) = 0;
  95. LL_INLINE bool hasAlphaParams() const { return !mParamAlphaList.empty(); }
  96. ERenderPass getRenderPass() const;
  97. bool isVisibilityMask() const;
  98. LL_INLINE virtual void asLLSD(LLSD& sd) const {}
  99. protected:
  100. const std::string& getGlobalColor() const;
  101. LLViewerVisualParam* getVisualParamPtr(S32 index) const;
  102. protected:
  103. LLTexLayerSet* const mTexLayerSet;
  104. const LLTexLayerInfo* mInfo;
  105. bool mMorphMasksValid;
  106. bool mHasMorph;
  107. // Layers can have either mParamColorList, mGlobalColor, or mFixedColor.
  108. // They are looked for in that order.
  109. param_color_list_t mParamColorList;
  110. param_alpha_list_t mParamAlphaList;
  111. // mGlobalColor name stored in mInfo
  112. // mFixedColor value stored in mInfo
  113. };
  114. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. // LLTexLayerTemplate
  116. // Only exists for LLVOAvatarSelf.
  117. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. class LLTexLayerTemplate : public LLTexLayerInterface
  119. {
  120. public:
  121. LLTexLayerTemplate(LLTexLayerSet* const layer_setp,
  122. LLAvatarAppearance* const appearance);
  123. LLTexLayerTemplate(const LLTexLayerTemplate& layer);
  124. bool render(S32 x, S32 y, S32 width, S32 height) override;
  125. // This sets mInfo and calls initialization functions:
  126. bool setInfo(const LLTexLayerInfo* info, LLWearable* wearable) override;
  127. // Multiplies a single alpha texture against the frame buffer:
  128. bool blendAlphaTexture(S32 x, S32 y, S32 width, S32 height) override;
  129. void gatherAlphaMasks(U8* datap, S32 origin_x, S32 origin_y, S32 width,
  130. S32 height) override;
  131. void setHasMorph(bool newval) override;
  132. void deleteCaches() override;
  133. bool isInvisibleAlphaMask() const override;
  134. protected:
  135. U32 updateWearableCache() const;
  136. LLTexLayer* getLayer(U32 i) const;
  137. LL_INLINE LLAvatarAppearance* getAvatarAppearance() const
  138. {
  139. return mAvatarAppearance;
  140. }
  141. private:
  142. // Note: backlink only; do not make this an LLPointer.
  143. LLAvatarAppearance* const mAvatarAppearance;
  144. typedef std::vector<LLWearable*> wearable_cache_t;
  145. // mutable b/c most get- require updating this cache
  146. mutable wearable_cache_t mWearableCache;
  147. };
  148. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. // LLTexLayer
  150. // A single texture layer. Only exists for LLVOAvatarSelf.
  151. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152. class LLTexLayer : public LLTexLayerInterface
  153. {
  154. public:
  155. LLTexLayer(LLTexLayerSet* const layer_setp);
  156. LLTexLayer(const LLTexLayer& layer, LLWearable* wearablep);
  157. LLTexLayer(const LLTexLayerTemplate& layer_template,
  158. LLLocalTextureObject* ltop, LLWearable* wearablep);
  159. ~LLTexLayer() override;
  160. // This sets mInfo and calls initialization functions:
  161. bool setInfo(const LLTexLayerInfo* info, LLWearable* wearable) override;
  162. bool render(S32 x, S32 y, S32 width, S32 height) override;
  163. void deleteCaches() override;
  164. const U8* getAlphaData() const;
  165. bool findNetColor(LLColor4* color) const;
  166. // Multiplies a single alpha texture against the frame buffer
  167. bool blendAlphaTexture(S32 x, S32 y, S32 width, S32 height) override;
  168. void gatherAlphaMasks(U8* datap, S32 origin_x, S32 origin_y, S32 width,
  169. S32 height) override;
  170. void renderMorphMasks(S32 x, S32 y, S32 width, S32 height,
  171. const LLColor4& layer_color, bool force_render);
  172. void addAlphaMask(U8* datap, S32 origin_x, S32 origin_y, S32 width,
  173. S32 height);
  174. bool isInvisibleAlphaMask() const override;
  175. LL_INLINE void setLTO(LLLocalTextureObject* ltop) { mLocalTextureObject = ltop; }
  176. LL_INLINE LLLocalTextureObject* getLTO() { return mLocalTextureObject; }
  177. void asLLSD(LLSD& sd) const override;
  178. static void calculateTexLayerColor(const param_color_list_t& param_list,
  179. LLColor4& net_color);
  180. protected:
  181. LLUUID getUUID() const;
  182. protected:
  183. typedef fast_hmap<U32, U8*> alpha_cache_t;
  184. alpha_cache_t mAlphaCache;
  185. LLLocalTextureObject* mLocalTextureObject;
  186. };
  187. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. // LLTexLayerSet
  189. // An ordered set of texture layers that gets composited into a single texture.
  190. // Only exists for LLVOAvatarSelf.
  191. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192. class LLTexLayerSet
  193. {
  194. friend class LLTexLayerSetBuffer;
  195. public:
  196. LLTexLayerSet(LLAvatarAppearance* const appearance);
  197. virtual ~LLTexLayerSet();
  198. LL_INLINE virtual LLViewerTexLayerSet* asViewerTexLayerSet()
  199. {
  200. return NULL;
  201. }
  202. LLTexLayerSetBuffer* getComposite();
  203. // Does not create one if it does not exist:
  204. const LLTexLayerSetBuffer* getComposite() const;
  205. virtual void createComposite() = 0;
  206. void destroyComposite();
  207. void gatherMorphMaskAlpha(U8* datap, S32 origin_x, S32 origin_y, S32 width,
  208. S32 height);
  209. LL_INLINE const LLTexLayerSetInfo* getInfo() const { return mInfo; }
  210. // This sets mInfo and calls initialization functions:
  211. bool setInfo(const LLTexLayerSetInfo* info);
  212. bool render(S32 x, S32 y, S32 width, S32 height);
  213. void renderAlphaMaskTextures(S32 x, S32 y, S32 width, S32 height,
  214. bool force_Clear = false);
  215. bool isBodyRegion(const std::string& region) const;
  216. void applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_comps);
  217. bool isMorphValid() const;
  218. virtual void requestUpdate() = 0;
  219. void invalidateMorphMasks();
  220. void deleteCaches();
  221. LLTexLayerInterface* findLayerByName(const std::string& name);
  222. void cloneTemplates(LLLocalTextureObject* ltop,
  223. LLAvatarAppearanceDefines::ETextureIndex tex_index,
  224. LLWearable* wearablep);
  225. LL_INLINE LLAvatarAppearance* getAvatarAppearance() const
  226. {
  227. return mAvatarAppearance;
  228. }
  229. const std::string getBodyRegionName() const;
  230. LL_INLINE bool hasComposite() const { return mComposite.notNull(); }
  231. LL_INLINE LLAvatarAppearanceDefines::EBakedTextureIndex getBakedTexIndex() const
  232. {
  233. return mBakedTexIndex;
  234. }
  235. LL_INLINE void setBakedTexIndex(LLAvatarAppearanceDefines::EBakedTextureIndex index)
  236. {
  237. mBakedTexIndex = index;
  238. }
  239. LL_INLINE bool isVisible() const { return mIsVisible; }
  240. public:
  241. static bool sHasCaches;
  242. static bool sAllowFaceWrinkles;
  243. protected:
  244. typedef std::vector<LLTexLayerInterface*> layer_list_t;
  245. layer_list_t mLayerList;
  246. layer_list_t mMaskLayerList;
  247. LLPointer<LLTexLayerSetBuffer> mComposite;
  248. // Note: backlink only; do not make this a LLPointer:
  249. LLAvatarAppearance* const mAvatarAppearance;
  250. LLAvatarAppearanceDefines::EBakedTextureIndex mBakedTexIndex;
  251. const LLTexLayerSetInfo* mInfo;
  252. bool mIsVisible;
  253. };
  254. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  255. // LLTexLayerSetInfo
  256. // Contains shared layer set data.
  257. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258. class LLTexLayerSetInfo final
  259. {
  260. friend class LLTexLayerSet;
  261. public:
  262. LLTexLayerSetInfo();
  263. ~LLTexLayerSetInfo();
  264. bool parseXml(LLXmlTreeNode* node);
  265. void createVisualParams(LLAvatarAppearance* appearance);
  266. LL_INLINE S32 getWidth() const { return mWidth; }
  267. LL_INLINE S32 getHeight() const { return mHeight; }
  268. protected:
  269. S32 mWidth;
  270. S32 mHeight;
  271. std::string mBodyRegion;
  272. std::string mStaticAlphaFileName;
  273. // Set alpha to 1 for this layerset (if there is no mStaticAlphaFileName):
  274. bool mClearAlpha;
  275. typedef std::vector<LLTexLayerInfo*> layer_info_list_t;
  276. layer_info_list_t mLayerInfoList;
  277. public:
  278. static bool sUseLargeBakes;
  279. };
  280. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  281. // LLTexLayerSetBuffer
  282. // The composite image that a LLTexLayerSet writes to.
  283. // Each LLTexLayerSet has one.
  284. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  285. class LLTexLayerSetBuffer : public virtual LLThreadSafeRefCount
  286. {
  287. protected:
  288. LOG_CLASS(LLTexLayerSetBuffer);
  289. public:
  290. LLTexLayerSetBuffer(LLTexLayerSet* const owner);
  291. LL_INLINE virtual LLViewerTexLayerSetBuffer* asViewerTexLayerSetBuffer()
  292. {
  293. return NULL;
  294. }
  295. protected:
  296. void pushProjection() const;
  297. void popProjection() const;
  298. virtual void preRenderTexLayerSet();
  299. LL_INLINE virtual void midRenderTexLayerSet(bool) {}
  300. virtual void postRenderTexLayerSet(bool success);
  301. virtual S32 getCompositeOriginX() const = 0;
  302. virtual S32 getCompositeOriginY() const = 0;
  303. virtual S32 getCompositeWidth() const = 0;
  304. virtual S32 getCompositeHeight() const = 0;
  305. bool renderTexLayerSet();
  306. protected:
  307. LLTexLayerSet* const mTexLayerSet;
  308. };
  309. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310. // LLTexLayerStaticImageList
  311. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  312. class LLTexLayerStaticImageList final
  313. {
  314. protected:
  315. LOG_CLASS(LLTexLayerStaticImageList);
  316. public:
  317. LLTexLayerStaticImageList();
  318. ~LLTexLayerStaticImageList();
  319. LLGLTexture* getTexture(const std::string& file_name, bool is_mask);
  320. LLImageTGA* getImageTGA(const std::string& file_name);
  321. void deleteCachedImages();
  322. void dumpByteCount() const;
  323. protected:
  324. bool loadImageRaw(const std::string& file_name, LLImageRaw* img_raw);
  325. private:
  326. LLStringTable mImageNames;
  327. typedef std::map<const char*, LLPointer<LLGLTexture> > texture_map_t;
  328. texture_map_t mStaticImageList;
  329. typedef std::map<const char*, LLPointer<LLImageTGA> > image_tga_map_t;
  330. image_tga_map_t mStaticImageListTGA;
  331. S32 mGLBytes;
  332. S32 mTGABytes;
  333. };
  334. extern LLTexLayerStaticImageList gTexLayerStaticImageList;
  335. #endif // LL_LLTEXLAYER_H