lldrawpoolbump.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. * @file lldrawpoolbump.h
  3. * @brief LLDrawPoolBump class definition
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-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_LLDRAWPOOLBUMP_H
  33. #define LL_LLDRAWPOOLBUMP_H
  34. #include "hbfastmap.h"
  35. #include "llstring.h"
  36. #include "llrendertarget.h"
  37. #include "lltextureentry.h"
  38. #include "lluuid.h"
  39. #include "lldrawpool.h"
  40. class LLDrawInfo;
  41. class LLGLSLShader;
  42. class LLImageRaw;
  43. class LLSpatialGroup;
  44. class LLViewerFetchedTexture;
  45. class LLDrawPoolBump : public LLRenderPass
  46. {
  47. protected :
  48. LL_INLINE LLDrawPoolBump(U32 type)
  49. : LLRenderPass(type),
  50. mShiny(false),
  51. mRigged(false)
  52. {
  53. }
  54. public:
  55. LL_INLINE LLDrawPoolBump()
  56. : LLRenderPass(LLDrawPool::POOL_BUMP),
  57. mShiny(false),
  58. mRigged(false)
  59. {
  60. }
  61. // No more in use with the PBR renderer
  62. LL_INLINE U32 getVertexDataMask() override { return sVertexMask; }
  63. void prerender() override;
  64. // This method is only used by the EE renderer
  65. void render(S32 pass = 0) override;
  66. // Note: in these methods, 'mask' is ignored for the PBR renderer
  67. void pushBatch(LLDrawInfo& params, U32 mask, bool texture,
  68. bool batch_textures = false) override;
  69. void renderGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
  70. bool texture = true) override;
  71. LL_INLINE S32 getNumDeferredPasses() override { return 1; }
  72. void renderDeferred(S32 pass) override;
  73. LL_INLINE S32 getNumPostDeferredPasses() override { return 1; }
  74. void renderPostDeferred(S32 pass) override;
  75. private:
  76. // The three methods are only used by the EE renderer
  77. void beginShiny();
  78. void renderShiny();
  79. void endShiny();
  80. void beginFullbrightShiny();
  81. void renderFullbrightShiny();
  82. void endFullbrightShiny();
  83. void beginBump();
  84. void renderBump(U32 pass = PASS_BUMP);
  85. void endBump();
  86. // For the EE renderer only.
  87. void renderBump(U32 type, U32 mask);
  88. // For the PBR renderer only.
  89. void pushBumpBatches(U32 type);
  90. // Note: in this method, 'mask' is ignored for the PBR renderer
  91. void pushBumpBatch(LLDrawInfo& params, U32 mask, bool texture,
  92. bool batch_textures = false);
  93. static bool bindBumpMap(LLDrawInfo& params, S32 channel = -2);
  94. static bool bindBumpMap(LLFace* facep, S32 channel = -2);
  95. // For the EE renderer only
  96. static void bindCubeMap(LLGLSLShader* shaderp, S32 shader_level,
  97. S32& diffuse_channel, S32& cube_channel);
  98. // For the EE renderer only
  99. static void unbindCubeMap(LLGLSLShader* shaderp, S32 shader_level,
  100. S32& diffuse_channel);
  101. static bool bindBumpMap(U8 bump_code, LLViewerTexture* texp, F32 vsize,
  102. S32 channel);
  103. public:
  104. bool mShiny;
  105. bool mRigged; // When true, doing a rigged pass
  106. static U32 sVertexMask;
  107. };
  108. enum EBumpEffect
  109. {
  110. BE_NO_BUMP = 0,
  111. BE_BRIGHTNESS = 1,
  112. BE_DARKNESS = 2,
  113. BE_STANDARD_0 = 3, // Standard must always be the last one
  114. BE_COUNT = 4
  115. };
  116. ///////////////////////////////////////////////////////////////////////////////
  117. // List of standard bumpmaps that are specificed by LLTextureEntry::mBump's
  118. // lower bits
  119. class LLStandardBumpmap
  120. {
  121. protected:
  122. LOG_CLASS(LLStandardBumpmap);
  123. public:
  124. LLStandardBumpmap() = default;
  125. LL_INLINE LLStandardBumpmap(const std::string& label)
  126. : mLabel(label)
  127. {
  128. }
  129. LL_INLINE static void init() { add(); }
  130. LL_INLINE static void shutdown() { clear(); }
  131. private:
  132. static void clear();
  133. static void add();
  134. public:
  135. std::string mLabel;
  136. LLPointer<LLViewerFetchedTexture> mImage;
  137. // Number of valid values in gStandardBumpmapList[]
  138. static U32 sStandardBumpmapCount;
  139. };
  140. extern LLStandardBumpmap gStandardBumpmapList[TEM_BUMPMAP_COUNT];
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // List of one-component bump-maps created from other texures.
  143. struct LLBumpImageEntry;
  144. class LLBumpImageList
  145. {
  146. protected:
  147. LOG_CLASS(LLBumpImageList);
  148. public:
  149. LLBumpImageList() = default;
  150. void destroyGL();
  151. void restoreGL();
  152. void updateImages();
  153. LLViewerTexture* getBrightnessDarknessImage(LLViewerFetchedTexture* src_image,
  154. U8 bump_code);
  155. void addTextureStats(U8 bump, const LLUUID& base_image_id,
  156. F32 virtual_size);
  157. static void onSourceBrightnessLoaded(bool success,
  158. LLViewerFetchedTexture* src_vi,
  159. LLImageRaw* src, LLImageRaw* aux_src,
  160. S32 discard_level, bool is_final,
  161. void* userdata);
  162. static void onSourceDarknessLoaded(bool success,
  163. LLViewerFetchedTexture* src_vi,
  164. LLImageRaw* src, LLImageRaw* aux_src,
  165. S32 discard_level, bool is_final,
  166. void* userdata);
  167. static void onSourceStandardLoaded(bool success,
  168. LLViewerFetchedTexture* src_vi,
  169. LLImageRaw* src, LLImageRaw* aux_src,
  170. S32 discard_level, bool is_final,
  171. void* userdata);
  172. static void generateNormalMapFromAlpha(LLImageRaw* src,
  173. LLImageRaw* nrm_image);
  174. private:
  175. static void onSourceLoaded(bool success, LLViewerTexture* src_vi,
  176. LLImageRaw* src, LLUUID& source_asset_id,
  177. EBumpEffect bump);
  178. private:
  179. typedef fast_hmap<LLUUID, LLPointer<LLViewerTexture> > bump_image_map_t;
  180. bump_image_map_t mBrightnessEntries;
  181. bump_image_map_t mDarknessEntries;
  182. static LLRenderTarget sRenderTarget;
  183. };
  184. extern LLBumpImageList gBumpImageList;
  185. class LLDrawPoolInvisible final : public LLDrawPoolBump
  186. {
  187. public:
  188. LL_INLINE LLDrawPoolInvisible()
  189. : LLDrawPoolBump(LLDrawPool::POOL_INVISIBLE)
  190. {
  191. }
  192. enum
  193. {
  194. VERTEX_DATA_MASK = LLVertexBuffer::MAP_VERTEX
  195. };
  196. LL_INLINE U32 getVertexDataMask() override { return VERTEX_DATA_MASK; }
  197. void render(S32 pass = 0) override;
  198. LL_INLINE S32 getNumDeferredPasses() override { return 1; }
  199. void renderDeferred(S32 pass) override;
  200. };
  201. #endif // LL_LLDRAWPOOLBUMP_H