llvlcomposition.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @file llvlcomposition.h
  3. * @brief Viewer-side representation of a composition layer...
  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_LLVLCOMPOSITION_H
  33. #define LL_LLVLCOMPOSITION_H
  34. #include "llviewertexture.h"
  35. class LLFetchedGLTFMaterial;
  36. class LLGLTFMaterial;
  37. class LLSurface;
  38. // Viewer-side representation of a layer...
  39. class LLViewerLayer
  40. {
  41. public:
  42. LLViewerLayer(S32 width, F32 scale = 1.f);
  43. virtual ~LLViewerLayer();
  44. F32 getValueScaled(F32 x, F32 y) const;
  45. protected:
  46. LL_INLINE F32 getValue(S32 x, S32 y) const
  47. {
  48. return *(mDatap + x + y * mWidth);
  49. }
  50. protected:
  51. F32* mDatap;
  52. S32 mWidth;
  53. F32 mScale;
  54. F32 mScaleInv;
  55. };
  56. class LLTerrain
  57. {
  58. protected:
  59. LOG_CLASS(LLTerrain);
  60. public:
  61. LLTerrain();
  62. virtual ~LLTerrain();
  63. enum EAssetCount : U32
  64. {
  65. ASSET_COUNT = 4
  66. };
  67. virtual void setDetailAssetID(U32 asset, const LLUUID& id);
  68. LL_INLINE const LLUUID& getDetailAssetID(U32 asset) const
  69. {
  70. return asset < ASSET_COUNT ? mAssetIds[asset] : LLUUID::null;
  71. }
  72. bool isPBR();
  73. bool texturesReady(bool boost_it, bool strict);
  74. // strict = true -> all materials must be sufficiently loaded
  75. // strict = false -> at least one material must be loaded
  76. bool materialsReady(bool boost_it, bool strict);
  77. LL_INLINE bool generateMaterials()
  78. {
  79. return texturesReady(true, true) || materialsReady(true, true);
  80. }
  81. void getTextures(std::vector<LLViewerTexture*>& textures);
  82. LL_INLINE LLViewerFetchedTexture* getFetchedTexture(U32 asset) const
  83. {
  84. return asset < ASSET_COUNT ? mDetailTextures[asset].get() : NULL;
  85. }
  86. void getGLTFMaterials(std::vector<LLGLTFMaterial*>& materials);
  87. LL_INLINE LLFetchedGLTFMaterial* getFetchedMaterial(U32 asset) const
  88. {
  89. return asset < ASSET_COUNT ? mDetailMaterials[asset].get() : NULL;
  90. }
  91. void boostTextures();
  92. // *HACK: for PBR terrain support, these allow to avoid to log warnings
  93. // when it is "normal" that a texture or material corresponding to a
  94. // terrain asset Id is not found (since for each of our assets, either
  95. // a texture fetch or a PBR material asset fetch will invariably fail). HB
  96. static bool isAsset(const LLUUID& id);
  97. protected:
  98. static bool textureReady(LLViewerFetchedTexture* texp, bool boost_it);
  99. static bool materialReady(LLFetchedGLTFMaterial* matp, bool& textures_set,
  100. bool boost_it, bool strict);
  101. private:
  102. static void addGlobalAsset(const LLUUID& id);
  103. static void removeGlobalAsset(const LLUUID& id);
  104. protected:
  105. LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
  106. LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
  107. LLUUID mAssetIds[ASSET_COUNT];
  108. bool mMaterialTexturesSet[ASSET_COUNT];
  109. U32 mTerrainType;
  110. };
  111. class LLVLComposition final : public LLTerrain, public LLViewerLayer
  112. {
  113. friend class LLVOSurfacePatch;
  114. protected:
  115. LOG_CLASS(LLVLComposition);
  116. public:
  117. LLVLComposition(LLSurface* surfacep, U32 width, F32 scale);
  118. LL_INLINE void setSurface(LLSurface* s) { mSurfacep = s; }
  119. void forceRebuild();
  120. // Viewer side hack to generate composition values
  121. bool generateHeights(F32 x, F32 y, F32 width, F32 height);
  122. bool generateComposition();
  123. // GenerateS texture from composition values.
  124. bool generateLandTile(F32 x, F32 y, F32 width, F32 height);
  125. LL_INLINE LLViewerFetchedTexture* getDetailTexture(U32 terrain)
  126. {
  127. return mDetailTextures[terrain];
  128. }
  129. void setDetailAssetID(U32 asset, const LLUUID& id) override;
  130. LL_INLINE void setParamsReady() { mParamsReady = true; }
  131. LL_INLINE bool getParamsReady() const { return mParamsReady; }
  132. // Use these as indices into the get/setters below
  133. enum ECorner : U32
  134. {
  135. SOUTHWEST = 0,
  136. SOUTHEAST = 1,
  137. NORTHWEST = 2,
  138. NORTHEAST = 3,
  139. CORNER_COUNT = 4
  140. };
  141. LL_INLINE F32 getStartHeight(U32 c) { return mStartHeight[c]; }
  142. LL_INLINE void setStartHeight(U32 c, F32 h) { mStartHeight[c] = h; }
  143. LL_INLINE F32 getHeightRange(U32 c) { return mHeightRange[c]; }
  144. LL_INLINE void setHeightRange(U32 c, F32 r) { mHeightRange[c] = r; }
  145. protected:
  146. LLSurface* mSurfacep;
  147. LLPointer<LLImageRaw> mRawImages[ASSET_COUNT];
  148. F32 mStartHeight[CORNER_COUNT];
  149. F32 mHeightRange[CORNER_COUNT];
  150. F32 mTexScaleX;
  151. F32 mTexScaleY;
  152. bool mParamsReady;
  153. bool mTexturesLoaded;
  154. };
  155. #endif //LL_LLVLCOMPOSITION_H