llmaterial.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * @file llmaterial.h
  3. * @brief Material definition
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewergpl$
  6. *
  7. * Copyright (c) 2012, 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_LLMATERIAL_H
  33. #define LL_LLMATERIAL_H
  34. #include "llmaterialid.h"
  35. #include "llpointer.h"
  36. #include "llrefcount.h"
  37. #include "llsd.h"
  38. #include "llcolor4u.h"
  39. class LLMaterial : public LLRefCount
  40. {
  41. public:
  42. typedef enum
  43. {
  44. DIFFUSE_ALPHA_MODE_NONE = 0,
  45. DIFFUSE_ALPHA_MODE_BLEND = 1,
  46. DIFFUSE_ALPHA_MODE_MASK = 2,
  47. DIFFUSE_ALPHA_MODE_EMISSIVE = 3,
  48. DIFFUSE_ALPHA_MODE_DEFAULT = 4,
  49. } eDiffuseAlphaMode;
  50. enum eShaderCount : U32
  51. {
  52. SHADER_COUNT = 16,
  53. ALPHA_SHADER_COUNT = 4
  54. };
  55. static const LLColor4U DEFAULT_SPECULAR_LIGHT_COLOR;
  56. static constexpr U8 DEFAULT_SPECULAR_LIGHT_EXPONENT = (U8)(0.2f * 255);
  57. static constexpr U8 DEFAULT_ENV_INTENSITY = 0;
  58. LLMaterial();
  59. LLMaterial(const LLSD& material_data);
  60. LLSD asLLSD() const;
  61. void fromLLSD(const LLSD& material_data);
  62. LL_INLINE const LLUUID& getNormalID() const { return mNormalID; }
  63. LL_INLINE void setNormalID(const LLUUID& id) { mNormalID = id; }
  64. LL_INLINE void getNormalOffset(F32& offset_x, F32& offset_y) const
  65. {
  66. offset_x = mNormalOffsetX;
  67. offset_y = mNormalOffsetY;
  68. }
  69. LL_INLINE F32 getNormalOffsetX() const { return mNormalOffsetX; }
  70. LL_INLINE F32 getNormalOffsetY() const { return mNormalOffsetY; }
  71. LL_INLINE void setNormalOffset(F32 offset_x, F32 offset_y)
  72. {
  73. mNormalOffsetX = offset_x;
  74. mNormalOffsetY = offset_y;
  75. }
  76. LL_INLINE void setNormalOffsetX(F32 offset_x) { mNormalOffsetX = offset_x; }
  77. LL_INLINE void setNormalOffsetY(F32 offset_y) { mNormalOffsetY = offset_y; }
  78. LL_INLINE void getNormalRepeat(F32& repeat_x, F32& repeat_y) const
  79. {
  80. repeat_x = mNormalRepeatX;
  81. repeat_y = mNormalRepeatY;
  82. }
  83. LL_INLINE F32 getNormalRepeatX() const { return mNormalRepeatX; }
  84. LL_INLINE F32 getNormalRepeatY() const { return mNormalRepeatY; }
  85. LL_INLINE void setNormalRepeat(F32 repeat_x, F32 repeat_y)
  86. {
  87. mNormalRepeatX = repeat_x;
  88. mNormalRepeatY = repeat_y;
  89. }
  90. LL_INLINE void setNormalRepeatX(F32 repeat_x) { mNormalRepeatX = repeat_x; }
  91. LL_INLINE void setNormalRepeatY(F32 repeat_y) { mNormalRepeatY = repeat_y; }
  92. LL_INLINE F32 getNormalRotation() const { return mNormalRotation; }
  93. LL_INLINE void setNormalRotation(F32 rot) { mNormalRotation = rot; }
  94. LL_INLINE const LLUUID& getSpecularID() const { return mSpecularID; }
  95. LL_INLINE void setSpecularID(const LLUUID& id) { mSpecularID = id; }
  96. LL_INLINE void getSpecularOffset(F32& offset_x, F32& offset_y) const
  97. {
  98. offset_x = mSpecularOffsetX;
  99. offset_y = mSpecularOffsetY;
  100. }
  101. LL_INLINE F32 getSpecularOffsetX() const { return mSpecularOffsetX; }
  102. LL_INLINE F32 getSpecularOffsetY() const { return mSpecularOffsetY; }
  103. LL_INLINE void setSpecularOffset(F32 offset_x, F32 offset_y)
  104. {
  105. mSpecularOffsetX = offset_x;
  106. mSpecularOffsetY = offset_y;
  107. }
  108. LL_INLINE void setSpecularOffsetX(F32 offset_x) { mSpecularOffsetX = offset_x; }
  109. LL_INLINE void setSpecularOffsetY(F32 offset_y) { mSpecularOffsetY = offset_y; }
  110. LL_INLINE void getSpecularRepeat(F32& repeat_x, F32& repeat_y) const
  111. {
  112. repeat_x = mSpecularRepeatX;
  113. repeat_y = mSpecularRepeatY;
  114. }
  115. LL_INLINE F32 getSpecularRepeatX() const { return mSpecularRepeatX; }
  116. LL_INLINE F32 getSpecularRepeatY() const { return mSpecularRepeatY; }
  117. LL_INLINE void setSpecularRepeat(F32 repeat_x, F32 repeat_y)
  118. {
  119. mSpecularRepeatX = repeat_x;
  120. mSpecularRepeatY = repeat_y;
  121. }
  122. LL_INLINE void setSpecularRepeatX(F32 repeat_x) { mSpecularRepeatX = repeat_x; }
  123. LL_INLINE void setSpecularRepeatY(F32 repeat_y) { mSpecularRepeatY = repeat_y; }
  124. LL_INLINE F32 getSpecularRotation() const { return mSpecularRotation; }
  125. LL_INLINE void setSpecularRotation(F32 rot) { mSpecularRotation = rot; }
  126. LL_INLINE const LLColor4U& getSpecularLightColor() const
  127. {
  128. return mSpecularLightColor;
  129. }
  130. LL_INLINE void setSpecularLightColor(const LLColor4U& color)
  131. {
  132. mSpecularLightColor = color;
  133. }
  134. LL_INLINE U8 getSpecularLightExponent() const { return mSpecularLightExponent; }
  135. LL_INLINE void setSpecularLightExponent(U8 e) { mSpecularLightExponent = e; }
  136. LL_INLINE U8 getEnvironmentIntensity() const { return mEnvironmentIntensity; }
  137. LL_INLINE void setEnvironmentIntensity(U8 i) { mEnvironmentIntensity = i; }
  138. LL_INLINE U8 getDiffuseAlphaMode() const { return mDiffuseAlphaMode; }
  139. LL_INLINE void setDiffuseAlphaMode(U8 mode) { mDiffuseAlphaMode = mode; }
  140. LL_INLINE U8 getAlphaMaskCutoff() const { return mAlphaMaskCutoff; }
  141. LL_INLINE void setAlphaMaskCutoff(U8 cutoff) { mAlphaMaskCutoff = cutoff; }
  142. bool isNull() const;
  143. bool operator ==(const LLMaterial& rhs) const;
  144. bool operator !=(const LLMaterial& rhs) const;
  145. U32 getShaderMask(U32 alpha_mode, bool is_alpha);
  146. LLUUID getHash() const;
  147. public:
  148. static const LLMaterial null;
  149. protected:
  150. // Note: before these variables, we find the 32 bits counter from
  151. // LLRefCount... Placing five 32 bits floats first ensures the UUIDs
  152. // are aligned on 64 bits (where they are faster). HB
  153. F32 mNormalOffsetX;
  154. F32 mNormalOffsetY;
  155. F32 mNormalRepeatX;
  156. F32 mNormalRepeatY;
  157. F32 mNormalRotation;
  158. LLUUID mNormalID;
  159. LLUUID mSpecularID;
  160. F32 mSpecularOffsetX;
  161. F32 mSpecularOffsetY;
  162. F32 mSpecularRepeatX;
  163. F32 mSpecularRepeatY;
  164. F32 mSpecularRotation;
  165. LLColor4U mSpecularLightColor;
  166. U8 mSpecularLightExponent;
  167. U8 mEnvironmentIntensity;
  168. U8 mDiffuseAlphaMode;
  169. U8 mAlphaMaskCutoff;
  170. };
  171. typedef LLPointer<LLMaterial> LLMaterialPtr;
  172. #endif // LL_LLMATERIAL_H