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