PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llsurface.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 263 lines | 126 code | 62 blank | 75 comment | 0 complexity | 2122db9bea03fdb8127ea68ce53e3662 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsurface.h
  3. * @brief Description of LLSurface class
  4. *
  5. * $LicenseInfo:firstyear=2000&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_LLSURFACE_H
  27. #define LL_LLSURFACE_H
  28. //#include "vmath.h"
  29. #include "v3math.h"
  30. #include "v3dmath.h"
  31. #include "v4math.h"
  32. #include "m3math.h"
  33. #include "m4math.h"
  34. #include "llquaternion.h"
  35. #include "v4coloru.h"
  36. #include "v4color.h"
  37. #include "llvowater.h"
  38. #include "llpatchvertexarray.h"
  39. #include "llviewertexture.h"
  40. class LLTimer;
  41. class LLUUID;
  42. class LLAgent;
  43. class LLStat;
  44. static const U8 NO_EDGE = 0x00;
  45. static const U8 EAST_EDGE = 0x01;
  46. static const U8 NORTH_EDGE = 0x02;
  47. static const U8 WEST_EDGE = 0x04;
  48. static const U8 SOUTH_EDGE = 0x08;
  49. static const S32 ONE_MORE_THAN_NEIGHBOR = 1;
  50. static const S32 EQUAL_TO_NEIGHBOR = 0;
  51. static const S32 ONE_LESS_THAN_NEIGHBOR = -1;
  52. const S32 ABOVE_WATERLINE_ALPHA = 32; // The alpha of water when the land elevation is above the waterline.
  53. class LLViewerRegion;
  54. class LLSurfacePatch;
  55. class LLBitPack;
  56. class LLGroupHeader;
  57. class LLSurface
  58. {
  59. public:
  60. LLSurface(U32 type, LLViewerRegion *regionp = NULL);
  61. virtual ~LLSurface();
  62. static void initClasses(); // Do class initialization for LLSurface and its child classes.
  63. void create(const S32 surface_grid_width,
  64. const S32 surface_patch_width,
  65. const LLVector3d &origin_global,
  66. const F32 width); // Allocates and initializes surface
  67. void setRegion(LLViewerRegion *regionp);
  68. void setOriginGlobal(const LLVector3d &origin_global);
  69. void connectNeighbor(LLSurface *neighborp, U32 direction);
  70. void disconnectNeighbor(LLSurface *neighborp);
  71. void disconnectAllNeighbors();
  72. virtual void decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch);
  73. virtual void updatePatchVisibilities(LLAgent &agent);
  74. inline F32 getZ(const U32 k) const { return mSurfaceZ[k]; }
  75. inline F32 getZ(const S32 i, const S32 j) const { return mSurfaceZ[i + j*mGridsPerEdge]; }
  76. LLVector3 getOriginAgent() const;
  77. const LLVector3d &getOriginGlobal() const;
  78. F32 getMetersPerGrid() const;
  79. S32 getGridsPerEdge() const;
  80. S32 getPatchesPerEdge() const;
  81. S32 getGridsPerPatchEdge() const;
  82. U32 getRenderStride(const U32 render_level) const;
  83. U32 getRenderLevel(const U32 render_stride) const;
  84. // Returns the height of the surface immediately above (or below) location,
  85. // or if location is not above surface returns zero.
  86. F32 resolveHeightRegion(const F32 x, const F32 y) const;
  87. F32 resolveHeightRegion(const LLVector3 &location) const
  88. { return resolveHeightRegion( location.mV[VX], location.mV[VY] ); }
  89. F32 resolveHeightGlobal(const LLVector3d &position_global) const;
  90. LLVector3 resolveNormalGlobal(const LLVector3d& v) const; // Returns normal to surface
  91. LLSurfacePatch *resolvePatchRegion(const F32 x, const F32 y) const;
  92. LLSurfacePatch *resolvePatchRegion(const LLVector3 &position_region) const;
  93. LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
  94. // Update methods (called during idle, normally)
  95. BOOL idleUpdate(F32 max_update_time);
  96. BOOL containsPosition(const LLVector3 &position);
  97. void moveZ(const S32 x, const S32 y, const F32 delta);
  98. LLViewerRegion *getRegion() const { return mRegionp; }
  99. F32 getMinZ() const { return mMinZ; }
  100. F32 getMaxZ() const { return mMaxZ; }
  101. void setWaterHeight(F32 height);
  102. F32 getWaterHeight() const;
  103. LLViewerTexture *getSTexture();
  104. LLViewerTexture *getWaterTexture();
  105. BOOL hasZData() const { return mHasZData; }
  106. void dirtyAllPatches(); // Use this to dirty all patches when changing terrain parameters
  107. void dirtySurfacePatch(LLSurfacePatch *patchp);
  108. LLVOWater *getWaterObj() { return mWaterObjp; }
  109. static void setTextureSize(const S32 texture_size);
  110. friend class LLSurfacePatch;
  111. friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
  112. void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
  113. public:
  114. // Number of grid points on one side of a region, including +1 buffer for
  115. // north and east edge.
  116. S32 mGridsPerEdge;
  117. F32 mOOGridsPerEdge; // Inverse of grids per edge
  118. S32 mPatchesPerEdge; // Number of patches on one side of a region
  119. S32 mNumberOfPatches; // Total number of patches
  120. // Each surface points at 8 neighbors (or NULL)
  121. // +---+---+---+
  122. // |NW | N | NE|
  123. // +---+---+---+
  124. // | W | 0 | E |
  125. // +---+---+---+
  126. // |SW | S | SE|
  127. // +---+---+---+
  128. LLSurface *mNeighbors[8]; // Adjacent patches
  129. U32 mType; // Useful for identifying derived classes
  130. F32 mDetailTextureScale; // Number of times to repeat detail texture across this surface
  131. static F32 sTextureUpdateTime;
  132. static S32 sTexelsUpdated;
  133. protected:
  134. void createSTexture();
  135. void createWaterTexture();
  136. void initTextures();
  137. void initWater();
  138. void createPatchData(); // Allocates memory for patches.
  139. void destroyPatchData(); // Deallocates memory for patches.
  140. BOOL generateWaterTexture(const F32 x, const F32 y,
  141. const F32 width, const F32 height); // Generate texture from composition values.
  142. //F32 updateTexture(LLSurfacePatch *ppatch);
  143. LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
  144. protected:
  145. LLVector3d mOriginGlobal; // In absolute frame
  146. LLSurfacePatch *mPatchList; // Array of all patches
  147. // Array of grid data, mGridsPerEdge * mGridsPerEdge
  148. F32 *mSurfaceZ;
  149. // Array of grid normals, mGridsPerEdge * mGridsPerEdge
  150. LLVector3 *mNorm;
  151. std::set<LLSurfacePatch *> mDirtyPatchList;
  152. // The textures should never be directly initialized - use the setter methods!
  153. LLPointer<LLViewerTexture> mSTexturep; // Texture for surface
  154. LLPointer<LLViewerTexture> mWaterTexturep; // Water texture
  155. LLPointer<LLVOWater> mWaterObjp;
  156. // When we want multiple cameras we'll need one of each these for each camera
  157. S32 mVisiblePatchCount;
  158. U32 mGridsPerPatchEdge; // Number of grid points on a side of a patch
  159. F32 mMetersPerGrid; // Converts (i,j) indecies to distance
  160. F32 mMetersPerEdge; // = mMetersPerGrid * (mGridsPerEdge-1)
  161. LLPatchVertexArray mPVArray;
  162. BOOL mHasZData; // We've received any patch data for this surface.
  163. F32 mMinZ; // min z for this region (during the session)
  164. F32 mMaxZ; // max z for this region (during the session)
  165. S32 mSurfacePatchUpdateCount; // Number of frames since last update.
  166. private:
  167. LLViewerRegion *mRegionp; // Patch whose coordinate system this surface is using.
  168. static S32 sTextureSize; // Size of the surface texture
  169. };
  170. // . __.
  171. // Z /|\ /| Y North
  172. // | /
  173. // | / |<----------------- mGridsPerSurfaceEdge --------------->|
  174. // | / __________________________________________________________
  175. // |/______\ X /_______________________________________________________ /
  176. // / / / / / / / /M*M-2 /M*M-1 / /
  177. // /______/______/______/______/______/______/______/______/ /
  178. // / / / / / / / / / /
  179. // /______/______/______/______/______/______/______/______/ /
  180. // / / / / / / / / / /
  181. // /______/______/______/______/______/______/______/______/ /
  182. // West / / / / / / / / / /
  183. // /______/______/______/______/______/______/______/______/ / East
  184. // /... / / / / / / / / /
  185. // /______/______/______/______/______/______/______/______/ /
  186. // _. / 2M / / / / / / / / /
  187. // /| /______/______/______/______/______/______/______/______/ /
  188. // / / M / M+1 / M+2 / ... / / / / 2M-1 / /
  189. // j /______/______/______/______/______/______/______/______/ /
  190. // / 0 / 1 / 2 / ... / / / / M-1 / /
  191. // /______/______/______/______/______/______/______/______/_/
  192. // South |<-L->|
  193. // i -->
  194. //
  195. // where M = mSurfPatchWidth
  196. // and L = mPatchGridWidth
  197. //
  198. // Notice that mGridsPerSurfaceEdge = a power of two + 1
  199. // This provides a buffer on the east and north edges that will allow us to
  200. // fill the cracks between adjacent surfaces when rendering.
  201. #endif