PageRenderTime 75ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llprimitive/lltextureentry.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 206 lines | 113 code | 34 blank | 59 comment | 0 complexity | ac42f3f5bfa509e65ec7f0aa0c0c616f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltextureentry.h
  3. * @brief LLTextureEntry base class
  4. *
  5. * $LicenseInfo:firstyear=2001&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_LLTEXTUREENTRY_H
  27. #define LL_LLTEXTUREENTRY_H
  28. #include "lluuid.h"
  29. #include "v4color.h"
  30. #include "llsd.h"
  31. // These bits are used while unpacking TEM messages to tell which aspects of
  32. // the texture entry changed.
  33. const S32 TEM_CHANGE_NONE = 0x0;
  34. const S32 TEM_CHANGE_COLOR = 0x1;
  35. const S32 TEM_CHANGE_TEXTURE = 0x2;
  36. const S32 TEM_CHANGE_MEDIA = 0x4;
  37. const S32 TEM_INVALID = 0x8;
  38. const S32 TEM_BUMPMAP_COUNT = 32;
  39. // The Bump Shiny Fullbright values are bits in an eight bit field:
  40. // +----------+
  41. // | SSFBBBBB | S = Shiny, F = Fullbright, B = Bumpmap
  42. // | 76543210 |
  43. // +----------+
  44. const S32 TEM_BUMP_MASK = 0x1f; // 5 bits
  45. const S32 TEM_FULLBRIGHT_MASK = 0x01; // 1 bit
  46. const S32 TEM_SHINY_MASK = 0x03; // 2 bits
  47. const S32 TEM_BUMP_SHINY_MASK = (0xc0 | 0x1f);
  48. const S32 TEM_FULLBRIGHT_SHIFT = 5;
  49. const S32 TEM_SHINY_SHIFT = 6;
  50. // The Media Tex Gen values are bits in a bit field:
  51. // +----------+
  52. // | .....TTM | M = Media Flags (web page), T = LLTextureEntry::eTexGen, . = unused
  53. // | 76543210 |
  54. // +----------+
  55. const S32 TEM_MEDIA_MASK = 0x01;
  56. const S32 TEM_TEX_GEN_MASK = 0x06;
  57. const S32 TEM_TEX_GEN_SHIFT = 1;
  58. // forward declarations
  59. class LLMediaEntry;
  60. class LLTextureEntry
  61. {
  62. public:
  63. static LLTextureEntry* newTextureEntry();
  64. typedef enum e_texgen
  65. {
  66. TEX_GEN_DEFAULT = 0x00,
  67. TEX_GEN_PLANAR = 0x02,
  68. TEX_GEN_SPHERICAL = 0x04,
  69. TEX_GEN_CYLINDRICAL = 0x06
  70. } eTexGen;
  71. LLTextureEntry();
  72. LLTextureEntry(const LLUUID& tex_id);
  73. LLTextureEntry(const LLTextureEntry &rhs);
  74. LLTextureEntry &operator=(const LLTextureEntry &rhs);
  75. virtual ~LLTextureEntry();
  76. bool operator==(const LLTextureEntry &rhs) const;
  77. bool operator!=(const LLTextureEntry &rhs) const;
  78. LLSD asLLSD() const;
  79. void asLLSD(LLSD& sd) const;
  80. operator LLSD() const { return asLLSD(); }
  81. bool fromLLSD(const LLSD& sd);
  82. virtual LLTextureEntry* newBlank() const;
  83. virtual LLTextureEntry* newCopy() const;
  84. void init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump);
  85. // These return a TEM_ flag from above to indicate if something changed.
  86. S32 setID (const LLUUID &tex_id);
  87. S32 setColor(const LLColor4 &color);
  88. S32 setColor(const LLColor3 &color);
  89. S32 setAlpha(const F32 alpha);
  90. S32 setScale(F32 s, F32 t);
  91. S32 setScaleS(F32 s);
  92. S32 setScaleT(F32 t);
  93. S32 setOffset(F32 s, F32 t);
  94. S32 setOffsetS(F32 s);
  95. S32 setOffsetT(F32 t);
  96. S32 setRotation(F32 theta);
  97. S32 setBumpmap(U8 bump);
  98. S32 setFullbright(U8 bump);
  99. S32 setShiny(U8 bump);
  100. S32 setBumpShiny(U8 bump);
  101. S32 setBumpShinyFullbright(U8 bump);
  102. S32 setMediaFlags(U8 media_flags);
  103. S32 setTexGen(U8 texGen);
  104. S32 setMediaTexGen(U8 media);
  105. S32 setGlow(F32 glow);
  106. virtual const LLUUID &getID() const { return mID; }
  107. const LLColor4 &getColor() const { return mColor; }
  108. void getScale(F32 *s, F32 *t) const { *s = mScaleS; *t = mScaleT; }
  109. void getOffset(F32 *s, F32 *t) const { *s = mOffsetS; *t = mOffsetT; }
  110. F32 getRotation() const { return mRotation; }
  111. void getRotation(F32 *theta) const { *theta = mRotation; }
  112. U8 getBumpmap() const { return mBump & TEM_BUMP_MASK; }
  113. U8 getFullbright() const { return (mBump>>TEM_FULLBRIGHT_SHIFT) & TEM_FULLBRIGHT_MASK; }
  114. U8 getShiny() const { return (mBump>>TEM_SHINY_SHIFT) & TEM_SHINY_MASK; }
  115. U8 getBumpShiny() const { return mBump & TEM_BUMP_SHINY_MASK; }
  116. U8 getBumpShinyFullbright() const { return mBump; }
  117. U8 getMediaFlags() const { return mMediaFlags & TEM_MEDIA_MASK; }
  118. U8 getTexGen() const { return mMediaFlags & TEM_TEX_GEN_MASK; }
  119. U8 getMediaTexGen() const { return mMediaFlags; }
  120. F32 getGlow() const { return mGlow; }
  121. // *NOTE: it is possible for hasMedia() to return true, but getMediaData() to return NULL.
  122. // CONVERSELY, it is also possible for hasMedia() to return false, but getMediaData()
  123. // to NOT return NULL.
  124. bool hasMedia() const { return (bool)(mMediaFlags & MF_HAS_MEDIA); }
  125. LLMediaEntry* getMediaData() const { return mMediaEntry; }
  126. // Completely change the media data on this texture entry.
  127. void setMediaData(const LLMediaEntry &media_entry);
  128. // Returns true if media data was updated, false if it was cleared
  129. bool updateMediaData(const LLSD& media_data);
  130. // Clears media data, and sets the media flags bit to 0
  131. void clearMediaData();
  132. // Merges the given LLSD of media fields with this media entry.
  133. // Only those fields that are set that match the keys in
  134. // LLMediaEntry will be affected. If no fields are set or if
  135. // the LLSD is undefined, this is a no-op.
  136. void mergeIntoMediaData(const LLSD& media_fields);
  137. // Takes a media version string (an empty string or a previously-returned string)
  138. // and returns a "touched" string, touched by agent_id
  139. static std::string touchMediaVersionString(const std::string &in_version, const LLUUID &agent_id);
  140. // Given a media version string, return the version
  141. static U32 getVersionFromMediaVersionString(const std::string &version_string);
  142. // Given a media version string, return the UUID of the agent
  143. static LLUUID getAgentIDFromMediaVersionString(const std::string &version_string);
  144. // Return whether or not the given string is actually a media version
  145. static bool isMediaVersionString(const std::string &version_string);
  146. // Media flags
  147. enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 };
  148. public:
  149. F32 mScaleS; // S, T offset
  150. F32 mScaleT; // S, T offset
  151. F32 mOffsetS; // S, T offset
  152. F32 mOffsetT; // S, T offset
  153. F32 mRotation; // anti-clockwise rotation in rad about the bottom left corner
  154. static const LLTextureEntry null;
  155. // LLSD key defines
  156. static const char* OBJECT_ID_KEY;
  157. static const char* OBJECT_MEDIA_DATA_KEY;
  158. static const char* MEDIA_VERSION_KEY;
  159. static const char* TEXTURE_INDEX_KEY;
  160. static const char* TEXTURE_MEDIA_DATA_KEY;
  161. protected:
  162. LLUUID mID; // Texture GUID
  163. LLColor4 mColor;
  164. U8 mBump; // Bump map, shiny, and fullbright
  165. U8 mMediaFlags; // replace with web page, movie, etc.
  166. F32 mGlow;
  167. // Note the media data is not sent via the same message structure as the rest of the TE
  168. LLMediaEntry* mMediaEntry; // The media data for the face
  169. // NOTE: when adding new data to this class, in addition to adding it to the serializers asLLSD/fromLLSD and the
  170. // message packers (e.g. LLPrimitive::packTEMessage) you must also implement its copy in LLPrimitive::copyTEs()
  171. };
  172. #endif