llsurfacepatch.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * @file llsurfacepatch.h
  3. * @brief LLSurfacePatch class definition
  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_LLSURFACEPATCH_H
  33. #define LL_LLSURFACEPATCH_H
  34. #include "llpointer.h"
  35. #include "llvector3.h"
  36. #include "llvector3d.h"
  37. #include "llagent.h"
  38. #include "llvosurfacepatch.h"
  39. class LLColor4U;
  40. class LLSurface;
  41. class LLVector2;
  42. class LLViewerRegion;
  43. // A patch should not know about its visibility since that really depends on
  44. // the camera that is looking (or not looking) at it. So, anything about a
  45. // patch that is specific to a camera should be in the class below.
  46. struct LLPatchVisibilityInfo
  47. {
  48. LLPatchVisibilityInfo()
  49. : mIsVisible(false),
  50. mDistance(0.f),
  51. mRenderLevel(0),
  52. mRenderStride(0)
  53. {
  54. }
  55. F32 mDistance; // Distance from camera
  56. S32 mRenderLevel;
  57. U32 mRenderStride;
  58. bool mIsVisible;
  59. };
  60. class LLSurfacePatch
  61. {
  62. friend class LLSurface;
  63. protected:
  64. LOG_CLASS(LLSurfacePatch);
  65. public:
  66. LLSurfacePatch();
  67. ~LLSurfacePatch();
  68. void connectNeighbor(LLSurfacePatch* neighborp, U32 direction);
  69. void disconnectNeighbor(LLSurface* surfacep);
  70. void setNeighborPatch(U32 direction, LLSurfacePatch* neighborp);
  71. LL_INLINE LLSurfacePatch* getNeighborPatch(U32 direction) const
  72. {
  73. return mNeighborPatches[direction];
  74. }
  75. bool updateTexture();
  76. void updateVerticalStats();
  77. void updateNormals();
  78. void updateEastEdge();
  79. void updateNorthEdge();
  80. void updateCameraDistanceRegion(const LLVector3& pos_region);
  81. void updateVisibility();
  82. void updateGL();
  83. void dirtyZ(); // Dirty the z values of this patch
  84. LL_INLINE void setHasReceivedData() { mHasReceivedData = true; }
  85. LL_INLINE bool getHasReceivedData() const { return mHasReceivedData; }
  86. F32 getDistance() const;
  87. LL_INLINE F32 getMaxZ() const { return mMaxZ; }
  88. LL_INLINE F32 getMinZ() const { return mMinZ; }
  89. LL_INLINE F32 getMeanComposition() const { return mMeanComposition; }
  90. LL_INLINE F32 getMinComposition() const { return mMinComposition; }
  91. LL_INLINE F32 getMaxComposition() const { return mMaxComposition; }
  92. LL_INLINE const LLVector3& getCenterRegion() const { return mCenterRegion; }
  93. LL_INLINE const U64& getLastUpdateTime() const { return mLastUpdateTime; }
  94. LL_INLINE LLSurface* getSurface() const { return mSurfacep; }
  95. // get the point at the offset.
  96. LLVector3 getPointAgent(U32 x, U32 y) const;
  97. LLVector2 getTexCoords(U32 x, U32 y) const;
  98. void calcNormal(U32 x, U32 y, U32 stride);
  99. const LLVector3& getNormal(U32 x, U32 y) const;
  100. void eval(U32 x, U32 y, U32 stride, LLVector3* vertex, LLVector3* normal,
  101. LLVector2* tex0, LLVector2* tex1);
  102. LL_INLINE LLVector3 getOriginAgent() const { return gAgent.getPosAgentFromGlobal(mOriginGlobal); }
  103. LL_INLINE const LLVector3d& getOriginGlobal() const { return mOriginGlobal; }
  104. void setOriginGlobal(const LLVector3d& origin_global);
  105. // connectivity -- each LLPatch points at 5 neighbors (or NULL)
  106. // +---+---+---+
  107. // | | 2 | 5 |
  108. // +---+---+---+
  109. // | 3 | 0 | 1 |
  110. // +---+---+---+
  111. // | 6 | 4 | |
  112. // +---+---+---+
  113. LL_INLINE bool getVisible() const { return mVisInfo.mIsVisible; }
  114. LL_INLINE U32 getRenderStride() const { return mVisInfo.mRenderStride; }
  115. LL_INLINE S32 getRenderLevel() const { return mVisInfo.mRenderLevel; }
  116. void setSurface(LLSurface* surfacep);
  117. LL_INLINE void setDataZ(F32* data_z) { mDataZ = data_z; }
  118. LL_INLINE void setDataNorm(LLVector3* data_norm) { mDataNorm = data_norm; }
  119. LL_INLINE F32* getDataZ() const { return mDataZ; }
  120. void dirty(); // Mark this surface patch as dirty...
  121. LL_INLINE void clearDirty() { mDirty = false; }
  122. LL_INLINE void clearVObj() { mVObjp = NULL; }
  123. // *HACK: used to signal that the patches have all been reloaded, and that
  124. // a minium delay should be insreted before any other attempt. HB
  125. static void allPatchesReloaded();
  126. // Use to set the auto-reload delay, clamp it and cache it, when the
  127. // corresponding debug setting is changed or the viewer started. HB
  128. static void setAutoReloadDelay(U32 delay);
  129. static bool needsPatchesReload() { return sNeedsPatchesReload; }
  130. private:
  131. void updateCompositionStats(LLViewerRegion* regionp);
  132. protected:
  133. // Pointer to the LLVOSurfacePatch object which is used in the new renderer.
  134. LLPointer<LLVOSurfacePatch> mVObjp;
  135. LLSurface* mSurfacep; // Pointer to "parent" surface
  136. // Time patch was last updated
  137. U64 mLastUpdateTime;
  138. // Pointers to beginnings of patch data fields
  139. LLVector3d mOriginGlobal;
  140. LLVector3 mOriginRegion;
  141. U32 mDataOffset;
  142. LLVector3* mDataNorm;
  143. F32* mDataZ;
  144. // Height field stats
  145. LLVector3 mCenterRegion; // Center in region-local coords
  146. F32 mMinZ;
  147. F32 mMaxZ;
  148. F32 mMeanZ;
  149. F32 mRadius;
  150. F32 mMinComposition;
  151. F32 mMaxComposition;
  152. F32 mMeanComposition;
  153. F32 mFirstFailureTime;
  154. LLSurfacePatch* mNeighborPatches[8];
  155. // Which normals are invalid
  156. bool mNormalsInvalid[9];
  157. // This bitmap is non-zero if patch is on at least one edge of LLSurface
  158. // that is "connected" to another LLSurface.
  159. U8 mConnectedEdge;
  160. // All of the camera-dependent stuff should be in its own class...
  161. LLPatchVisibilityInfo mVisInfo;
  162. bool mDirty;
  163. bool mDirtyZStats;
  164. bool mHeightsGenerated;
  165. // Has the patch EVER received height data ?
  166. bool mHasReceivedData;
  167. // Does the surface texture need to be updated ?
  168. bool mSTexUpdate;
  169. // *HACK: used to ask auto-reload of failed patch textures.
  170. static F32 sAutoReloadDelay;
  171. static F32 sNextAllowedReloadTime;
  172. static bool sNeedsPatchesReload;
  173. };
  174. extern const U32 gDirOpposite[];
  175. #endif // LL_LLSURFACEPATCH_H