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 BOOL containsPosition(const LLVector3 &position);
00124
00125 void moveZ(const S32 x, const S32 y, const F32 delta);
00126
00127 LLViewerRegion *getRegion() const { return mRegionp; }
00128
00129 F32 getMinZ() const { return mMinZ; }
00130 F32 getMaxZ() const { return mMaxZ; }
00131
00132 void setWaterHeight(F32 height);
00133 F32 getWaterHeight() const;
00134
00135 LLViewerImage *getSTexture();
00136 LLViewerImage *getWaterTexture();
00137 BOOL hasZData() const { return mHasZData; }
00138
00139 void dirtyAllPatches();
00140
00141 void dirtySurfacePatch(LLSurfacePatch *patchp);
00142 LLVOWater *getWaterObj() { return mWaterObjp; }
00143
00144 static void setTextureSize(const S32 texture_size);
00145
00146 friend class LLSurfacePatch;
00147 friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
00148 public:
00149
00150
00151 S32 mGridsPerEdge;
00152
00153 F32 mOOGridsPerEdge;
00154
00155 S32 mPatchesPerEdge;
00156 S32 mNumberOfPatches;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 LLSurface *mNeighbors[8];
00168
00169 U32 mType;
00170
00171 F32 mDetailTextureScale;
00172
00173 static F32 sTextureUpdateTime;
00174 static S32 sTexelsUpdated;
00175 static LLStat sTexelsUpdatedPerSecStat;
00176
00177 protected:
00178 void createSTexture();
00179 void createWaterTexture();
00180 void initTextures();
00181 void initWater();
00182
00183
00184 void createPatchData();
00185 void destroyPatchData();
00186
00187 BOOL generateWaterTexture(const F32 x, const F32 y,
00188 const F32 width, const F32 height);
00189
00190
00191
00192 LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
00193
00194 protected:
00195 LLVector3d mOriginGlobal;
00196 LLSurfacePatch *mPatchList;
00197
00198
00199 F32 *mSurfaceZ;
00200
00201
00202 LLVector3 *mNorm;
00203
00204 std::set<LLSurfacePatch *> mDirtyPatchList;
00205
00206
00207
00208 LLPointer<LLViewerImage> mSTexturep;
00209 LLPointer<LLViewerImage> mWaterTexturep;
00210
00211 LLPointer<LLVOWater> mWaterObjp;
00212
00213
00214 S32 mVisiblePatchCount;
00215
00216 U32 mGridsPerPatchEdge;
00217 F32 mMetersPerGrid;
00218 F32 mMetersPerEdge;
00219
00220 F32 mSurfaceTexScale;
00221 F32 mDetailTexScale;
00222
00223 LLPatchVertexArray mPVArray;
00224
00225 BOOL mHasZData;
00226 F32 mMinZ;
00227 F32 mMaxZ;
00228
00229 S32 mSurfacePatchUpdateCount;
00230
00231 private:
00232 LLViewerRegion *mRegionp;
00233 static S32 sTextureSize;
00234 };
00235
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 #endif