lltextureentry.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /**
  2. * @file lltextureentry.h
  3. * @brief LLTextureEntry base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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_LLTEXTUREENTRY_H
  33. #define LL_LLTEXTUREENTRY_H
  34. #include "llgltfmaterial.h"
  35. #include "llmaterial.h"
  36. #include "llmaterialid.h"
  37. class LLMediaEntry;
  38. // These bits are used while unpacking TEM messages to tell which aspects of
  39. // the texture entry changed.
  40. constexpr S32 TEM_CHANGE_NONE = 0x0;
  41. constexpr S32 TEM_CHANGE_COLOR = 0x1;
  42. constexpr S32 TEM_CHANGE_TEXTURE = 0x2;
  43. constexpr S32 TEM_CHANGE_MEDIA = 0x4;
  44. constexpr S32 TEM_INVALID = 0x8;
  45. constexpr S32 TEM_BUMPMAP_COUNT = 32;
  46. // The Bump Shiny Fullbright values are bits in an eight bit field:
  47. // +----------+
  48. // | SSFBBBBB | S = Shiny, F = Fullbright, B = Bumpmap
  49. // | 76543210 |
  50. // +----------+
  51. constexpr S32 TEM_BUMP_MASK = 0x1f; // 5 bits
  52. constexpr S32 TEM_FULLBRIGHT_MASK = 0x01; // 1 bit
  53. constexpr S32 TEM_SHINY_MASK = 0x03; // 2 bits
  54. constexpr S32 TEM_BUMP_SHINY_MASK = (0xc0 | 0x1f);
  55. constexpr S32 TEM_FULLBRIGHT_SHIFT = 5;
  56. constexpr S32 TEM_SHINY_SHIFT = 6;
  57. // The Media Tex Gen values are bits in a bit field:
  58. // +----------+
  59. // | .....TTM | M = Media Flags (web page), T = LLTextureEntry::eTexGen, . = unused
  60. // | 76543210 |
  61. // +----------+
  62. constexpr S32 TEM_MEDIA_MASK = 0x01;
  63. constexpr S32 TEM_TEX_GEN_MASK = 0x06;
  64. constexpr S32 TEM_TEX_GEN_SHIFT = 1;
  65. constexpr F32 ONE255TH = 1.f / 255.f;
  66. class LLTextureEntry final
  67. {
  68. protected:
  69. LOG_CLASS(LLTextureEntry);
  70. public:
  71. static LLTextureEntry* newTextureEntry();
  72. typedef enum e_texgen
  73. {
  74. TEX_GEN_DEFAULT = 0x00,
  75. TEX_GEN_PLANAR = 0x02,
  76. #if 0 // Not used
  77. TEX_GEN_SPHERICAL = 0x04,
  78. TEX_GEN_CYLINDRICAL = 0x06,
  79. #endif
  80. } eTexGen;
  81. LLTextureEntry();
  82. LLTextureEntry(const LLUUID& tex_id);
  83. LLTextureEntry(const LLTextureEntry& rhs);
  84. ~LLTextureEntry();
  85. LLTextureEntry& operator=(const LLTextureEntry& rhs);
  86. bool operator==(const LLTextureEntry& rhs) const;
  87. bool operator!=(const LLTextureEntry& rhs) const;
  88. LLSD asLLSD() const;
  89. void asLLSD(LLSD& sd) const;
  90. LL_INLINE operator LLSD() const { return asLLSD(); }
  91. bool fromLLSD(const LLSD& sd);
  92. LL_INLINE LLTextureEntry* newCopy() const { return new LLTextureEntry(*this); }
  93. LL_INLINE bool hasPendingMaterialUpdate() const { return mMaterialUpdatePending; }
  94. LL_INLINE bool isSelected() const { return mSelected; }
  95. LL_INLINE bool setSelected(bool sel)
  96. {
  97. bool prev_sel = mSelected;
  98. mSelected = sel;
  99. return prev_sel;
  100. }
  101. // These return a TEM_ flag from above to indicate if something changed.
  102. S32 setID(const LLUUID& tex_id);
  103. S32 setColor(const LLColor4& color);
  104. S32 setColor(const LLColor3& color);
  105. S32 setAlpha(F32 alpha);
  106. S32 setScale(F32 s, F32 t);
  107. S32 setScaleS(F32 s);
  108. S32 setScaleT(F32 t);
  109. S32 setOffset(F32 s, F32 t);
  110. S32 setOffsetS(F32 s);
  111. S32 setOffsetT(F32 t);
  112. S32 setRotation(F32 theta);
  113. S32 setBumpmap(U8 bump);
  114. S32 setFullbright(U8 bump);
  115. S32 setShiny(U8 bump);
  116. S32 setBumpShiny(U8 bump);
  117. S32 setBumpShinyFullbright(U8 bump);
  118. S32 setGlow(F32 glow);
  119. S32 setTexGen(U8 tex_gen);
  120. S32 setMediaTexGen(U8 media);
  121. S32 setMediaFlags(U8 media_flags);
  122. S32 setMaterialID(const LLMaterialID& mat_id);
  123. S32 setMaterialParams(const LLMaterialPtr mat_parms);
  124. LL_INLINE const LLUUID& getID() const { return mID; }
  125. LL_INLINE bool isBlank() const { return mIsBlankTexture; }
  126. LL_INLINE bool isDefault() const { return mIsDefaultTexture; }
  127. LL_INLINE const LLColor4& getColor() const { return mColor; }
  128. LL_INLINE F32 getAlpha() const { return mColor.mV[VALPHA]; }
  129. LL_INLINE F32 isTransparent() const { return mColor.mV[VALPHA] < 0.001f; }
  130. LL_INLINE F32 isOpaque() const { return mColor.mV[VALPHA] >= 0.999f; }
  131. LL_INLINE void getScale(F32* s, F32* t) const { *s = mScaleS; *t = mScaleT; }
  132. LL_INLINE F32 getScaleS() const { return mScaleS; }
  133. LL_INLINE F32 getScaleT() const { return mScaleT; }
  134. LL_INLINE void getOffset(F32* s, F32* t) const { *s = mOffsetS; *t = mOffsetT; }
  135. LL_INLINE F32 getOffsetS() const { return mOffsetS; }
  136. LL_INLINE F32 getOffsetT() const { return mOffsetT; }
  137. LL_INLINE F32 getRotation() const { return mRotation; }
  138. LL_INLINE void getRotation(F32* theta) const { *theta = mRotation; }
  139. LL_INLINE U8 getBumpmap() const { return mBump & TEM_BUMP_MASK; }
  140. LL_INLINE U8 getFullbright() const { return (mBump >> TEM_FULLBRIGHT_SHIFT) & TEM_FULLBRIGHT_MASK; }
  141. LL_INLINE U8 getShiny() const { return (mBump >> TEM_SHINY_SHIFT) & TEM_SHINY_MASK; }
  142. LL_INLINE U8 getBumpShiny() const { return mBump & TEM_BUMP_SHINY_MASK; }
  143. LL_INLINE U8 getBumpShinyFullbright() const { return mBump; }
  144. LL_INLINE F32 getGlow() const { return mGlow; }
  145. LL_INLINE bool hasGlow() const { return mGlow >= ONE255TH; }
  146. LL_INLINE U8 getMediaFlags() const { return mMediaFlags & TEM_MEDIA_MASK; }
  147. LL_INLINE LLTextureEntry::e_texgen getTexGen() const
  148. {
  149. return LLTextureEntry::e_texgen(mMediaFlags & TEM_TEX_GEN_MASK);
  150. }
  151. LL_INLINE U8 getMediaTexGen() const { return mMediaFlags; }
  152. LL_INLINE const LLMaterialID& getMaterialID() const
  153. {
  154. return mMaterialID;
  155. }
  156. LL_INLINE const LLMaterialPtr& getMaterialParams() const
  157. {
  158. return mMaterial;
  159. }
  160. // *NOTE: it is possible for hasMedia() to return true, but getMediaData()
  161. // to return NULL. CONVERSELY, it is also possible for hasMedia() to return
  162. // false, but getMediaData() to NOT return NULL.
  163. LL_INLINE bool hasMedia() const { return (mMediaFlags & MF_HAS_MEDIA) != 0; }
  164. LL_INLINE LLMediaEntry* getMediaData() const { return mMediaEntry; }
  165. // Completely change the media data on this texture entry.
  166. void setMediaData(const LLMediaEntry& media_entry);
  167. // Returns true if media data was updated, false if it was cleared
  168. bool updateMediaData(const LLSD& media_data);
  169. // Clears media data, and sets the media flags bit to 0
  170. void clearMediaData();
  171. // Merges the given LLSD of media fields with this media entry. Only those
  172. // fields that are set that match the keys in LLMediaEntry will be
  173. // affected. If no fields are set or if the LLSD is undefined, this is a
  174. // no-op.
  175. void mergeIntoMediaData(const LLSD& media_fields);
  176. // Takes a media version string (an empty string or a previously-returned string)
  177. // and returns a "touched" string, touched by agent_id
  178. static std::string touchMediaVersionString(const std::string& in_version,
  179. const LLUUID& agent_id);
  180. // Given a media version string, return the version
  181. static U32 getVersionFromMediaVersionString(const std::string& version_string);
  182. // Given a media version string, return the UUID of the agent
  183. static LLUUID getAgentIDFromMediaVersionString(const std::string& version_string);
  184. // Return whether or not the given string is actually a media version
  185. static bool isMediaVersionString(const std::string& version_string);
  186. // Media flags
  187. enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 };
  188. // GLTF support
  189. void setGLTFMaterial(LLGLTFMaterial* matp, bool local_origin = true);
  190. LL_INLINE LLGLTFMaterial* getGLTFMaterial() const
  191. {
  192. return mGLTFMaterial.get();
  193. }
  194. S32 setGLTFMaterialOverride(LLGLTFMaterial* matp);
  195. LL_INLINE LLGLTFMaterial* getGLTFMaterialOverride() const
  196. {
  197. return mGLTFMaterialOverrides.get();
  198. }
  199. // Clears most overrides so the render material better matches the material
  200. // Id (preserves transforms). If the overrides become passthrough, sets the
  201. // overrides to NULL.
  202. S32 setBaseMaterial();
  203. S32 setGLTFRenderMaterial(LLGLTFMaterial* matp);
  204. // Nuanced behavior here: if there is no render material, fall back to
  205. // getGLTFMaterial().
  206. LLGLTFMaterial* getGLTFRenderMaterial() const;
  207. private:
  208. void init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s,
  209. F32 offset_t, F32 rotation, U8 bump);
  210. public:
  211. static const LLTextureEntry null;
  212. // LLSD key defines
  213. static const char* OBJECT_ID_KEY;
  214. static const char* OBJECT_MEDIA_DATA_KEY;
  215. static const char* MEDIA_VERSION_KEY;
  216. static const char* TEXTURE_INDEX_KEY;
  217. static const char* TEXTURE_MEDIA_DATA_KEY;
  218. private:
  219. // Note the media data is not sent via the same message structure as the
  220. // rest of the TE.
  221. LLMediaEntry* mMediaEntry; // The media data for the face
  222. // NOTE: when adding new data to this class, in addition to adding it to
  223. // the serializers asLLSD/fromLLSD and the message packers (e.g.
  224. // LLPrimitive::packTEMessage) you must also implement its copy in
  225. // LLPrimitive::copyTEs()
  226. LLUUID mID; // Texture UUID
  227. LLColor4 mColor;
  228. LLMaterialID mMaterialID;
  229. LLMaterialPtr mMaterial;
  230. typedef LLPointer<LLGLTFMaterial> gltf_ptr_t;
  231. // Reference to GLTF material asset state; this should be the same
  232. // LLGLTFMaterial instance that exists in LLGLTFMaterialList.
  233. gltf_ptr_t mGLTFMaterial;
  234. // GLTF material parameter overrides: the viewer will use this data to
  235. // override material parameters.
  236. gltf_ptr_t mGLTFMaterialOverrides;
  237. // GLTF material to use for rendering: always an LLFetchedGLTFMaterial
  238. gltf_ptr_t mGLTFRenderMaterial;
  239. F32 mScaleS; // S, T offset
  240. F32 mScaleT; // S, T offset
  241. F32 mOffsetS; // S, T offset
  242. F32 mOffsetT; // S, T offset
  243. // Anti-clockwise rotation in rad about the bottom left corner
  244. F32 mRotation;
  245. F32 mGlow;
  246. U8 mBump; // Bump map, shiny, and fullbright
  247. U8 mMediaFlags; // replace with web page, movie, etc.
  248. bool mMaterialUpdatePending;
  249. // Set to true when mID is null or equal to either the plywood or the blank
  250. // default textures. Used to decide whether to override the diffuse texture
  251. // with the base color texture when we have a GLTF material set. HB
  252. bool mIsDefaultTexture;
  253. // Set to true when mID is equal to the blank default texture Id. Used to
  254. // avoid bothering with settings offsets, scales and rotation at render
  255. // time. HB
  256. bool mIsBlankTexture;
  257. bool mSelected;
  258. };
  259. #endif