00001 
00032 #ifndef LL_LLSURFACE_H
00033 #define LL_LLSURFACE_H
00034 
00035 
00036 #include "v3math.h"
00037 #include "v3dmath.h"
00038 #include "v4math.h"
00039 #include "m3math.h"
00040 #include "m4math.h"
00041 #include "llquaternion.h"
00042 
00043 #include "v4coloru.h"
00044 #include "v4color.h"
00045 
00046 #include "llvowater.h"
00047 #include "llpatchvertexarray.h"
00048 #include "llviewerimage.h"
00049 
00050 class LLTimer;
00051 class LLUUID;
00052 class LLAgent;
00053 class LLStat;
00054 
00055 static const U8 NO_EDGE    = 0x00;
00056 static const U8 EAST_EDGE  = 0x01;
00057 static const U8 NORTH_EDGE = 0x02;
00058 static const U8 WEST_EDGE  = 0x04;
00059 static const U8 SOUTH_EDGE = 0x08;
00060 
00061 static const S32 ONE_MORE_THAN_NEIGHBOR = 1;
00062 static const S32 EQUAL_TO_NEIGHBOR              = 0;
00063 static const S32 ONE_LESS_THAN_NEIGHBOR = -1;
00064 
00065 const S32 ABOVE_WATERLINE_ALPHA = 32;  
00066 
00067 class LLViewerRegion;
00068 class LLSurfacePatch;
00069 class LLBitPack;
00070 class LLGroupHeader;
00071 
00072 class LLSurface 
00073 {
00074 public:
00075         LLSurface(U32 type, LLViewerRegion *regionp = NULL);
00076         virtual ~LLSurface();
00077 
00078         static void initClasses(); 
00079 
00080         void create(const S32 surface_grid_width,
00081                                 const S32 surface_patch_width,
00082                                 const LLVector3d &origin_global,
00083                                 const F32 width);       
00084 
00085         void setRegion(LLViewerRegion *regionp);
00086 
00087         void setOriginGlobal(const LLVector3d &origin_global);
00088 
00089         void connectNeighbor(LLSurface *neighborp, U32 direction);
00090         void disconnectNeighbor(LLSurface *neighborp);
00091         void disconnectAllNeighbors();
00092 
00093         virtual void decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch);
00094         virtual void updatePatchVisibilities(LLAgent &agent);
00095 
00096         inline F32 getZ(const U32 k) const                              { return mSurfaceZ[k]; }
00097         inline F32 getZ(const S32 i, const S32 j) const { return mSurfaceZ[i + j*mGridsPerEdge]; }
00098 
00099         LLVector3 getOriginAgent() const;
00100         const LLVector3d &getOriginGlobal() const;
00101         F32 getMetersPerGrid() const;
00102         S32 getGridsPerEdge() const; 
00103         S32 getPatchesPerEdge() const;
00104         S32 getGridsPerPatchEdge() const;
00105         U32 getRenderStride(const U32 render_level) const;
00106         U32 getRenderLevel(const U32 render_stride) const;
00107 
00108         
00109         
00110         F32 resolveHeightRegion(const F32 x, const F32 y) const;
00111         F32 resolveHeightRegion(const LLVector3 &location) const
00112                         { return resolveHeightRegion( location.mV[VX], location.mV[VY] ); }
00113         F32 resolveHeightGlobal(const LLVector3d &position_global) const;
00114         LLVector3 resolveNormalGlobal(const LLVector3d& v) const;                               
00115 
00116         LLSurfacePatch *resolvePatchRegion(const F32 x, const F32 y) const;
00117         LLSurfacePatch *resolvePatchRegion(const LLVector3 &position_region) const;
00118         LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
00119 
00120         
00121         BOOL idleUpdate(F32 max_update_time);
00122 
00123         void renderSurfaceBounds();
00124         
00125         BOOL containsPosition(const LLVector3 &position);
00126 
00127         void moveZ(const S32 x, const S32 y, const F32 delta);  
00128 
00129         LLViewerRegion *getRegion() const                               { return mRegionp; }
00130 
00131         F32 getMinZ() const                                                             { return mMinZ; }
00132         F32 getMaxZ() const                                                             { return mMaxZ; }
00133 
00134         void setWaterHeight(F32 height);
00135         F32 getWaterHeight() const;
00136 
00137         LLViewerImage *getSTexture();
00138         LLViewerImage *getWaterTexture();
00139         BOOL hasZData() const                                                   { return mHasZData; }
00140 
00141         void dirtyAllPatches(); 
00142 
00143         void dirtySurfacePatch(LLSurfacePatch *patchp);
00144         LLVOWater *getWaterObj()                                                { return mWaterObjp; }
00145 
00146         static void setTextureSize(const S32 texture_size);
00147 
00148         friend class LLSurfacePatch;
00149         friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
00150 public:
00151         
00152         
00153         S32 mGridsPerEdge;
00154 
00155         F32 mOOGridsPerEdge;                    
00156 
00157         S32 mPatchesPerEdge;                    
00158         S32 mNumberOfPatches;                   
00159 
00160 
00161         
00162         
00163         
00164         
00165         
00166         
00167         
00168         
00169         LLSurface *mNeighbors[8]; 
00170 
00171         U32 mType;                              
00172         
00173         F32 mDetailTextureScale;        
00174 
00175         static F32 sTextureUpdateTime;
00176         static S32 sTexelsUpdated;
00177         static LLStat sTexelsUpdatedPerSecStat;
00178 
00179 protected:
00180         void createSTexture();
00181         void createWaterTexture();
00182         void initTextures();
00183         void initWater();
00184 
00185 
00186         void createPatchData();         
00187         void destroyPatchData();    
00188 
00189         BOOL generateWaterTexture(const F32 x, const F32 y,
00190                                                 const F32 width, const F32 height);             
00191 
00192         
00193         
00194         LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
00195 
00196 protected:
00197         LLVector3d      mOriginGlobal;          
00198         LLSurfacePatch *mPatchList;             
00199 
00200         
00201         F32 *mSurfaceZ;
00202 
00203         
00204         LLVector3 *mNorm;
00205 
00206         std::set<LLSurfacePatch *> mDirtyPatchList;
00207 
00208 
00209         
00210         LLPointer<LLViewerImage> mSTexturep;            
00211         LLPointer<LLViewerImage> mWaterTexturep;        
00212 
00213         LLPointer<LLVOWater>    mWaterObjp;
00214 
00215         
00216         S32 mVisiblePatchCount;
00217 
00218         U32                     mGridsPerPatchEdge;                     
00219         F32                     mMetersPerGrid;                         
00220         F32                     mMetersPerEdge;                         
00221 
00222         F32                     mSurfaceTexScale;                       
00223         F32                     mDetailTexScale;
00224 
00225         LLPatchVertexArray mPVArray;
00226 
00227         BOOL            mHasZData;                              
00228         F32                     mMinZ;                                  
00229         F32                     mMaxZ;                                  
00230 
00231         S32                     mSurfacePatchUpdateCount;                                       
00232 
00233 private:
00234         LLViewerRegion *mRegionp; 
00235         static S32      sTextureSize;                           
00236 };
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 #endif