00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __Ogre_TerrainQuadTreeNode_H__ 00030 #define __Ogre_TerrainQuadTreeNode_H__ 00031 00032 #include "OgreTerrainPrerequisites.h" 00033 #include "OgreCommon.h" 00034 #include "OgreHardwareIndexBuffer.h" 00035 #include "OgreMovableObject.h" 00036 #include "OgreRenderable.h" 00037 00038 00039 00040 namespace Ogre 00041 { 00042 class HardwareVertexBufferSharedPtr; 00043 00085 class _OgreTerrainExport TerrainQuadTreeNode : public TerrainAlloc 00086 { 00087 public: 00097 TerrainQuadTreeNode(Terrain* terrain, TerrainQuadTreeNode* parent, 00098 uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant); 00099 virtual ~TerrainQuadTreeNode(); 00100 00102 uint16 getXOffset() const { return mOffsetX; } 00104 uint16 getYOffset() const { return mOffsetY; } 00106 bool isLeaf() const; 00108 uint16 getBaseLod() const { return mBaseLod; } 00110 uint16 getLodCount() const; 00112 TerrainQuadTreeNode* getChild(unsigned short child) const; 00114 TerrainQuadTreeNode* getParent() const; 00116 Terrain* getTerrain() const; 00117 00119 void prepare(); 00121 void prepare(StreamSerialiser& stream); 00123 void load(); 00125 void load(uint16 depthStart, uint16 depthEnd); 00126 void loadSelf(); 00128 void unload(); 00130 void unload(uint16 depthStart, uint16 depthEnd); 00132 void unprepare(); 00134 void save(StreamSerialiser& stream); 00135 00136 struct _OgreTerrainExport LodLevel : public TerrainAlloc 00137 { 00139 uint16 batchSize; 00141 IndexData* gpuIndexData; 00143 Real maxHeightDelta; 00145 Real calcMaxHeightDelta; 00147 Real lastTransitionDist; 00149 Real lastCFactor; 00150 00151 LodLevel() : batchSize(0), gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0), 00152 lastTransitionDist(0), lastCFactor(0) {} 00153 }; 00154 typedef vector<LodLevel*>::type LodLevelList; 00155 00161 const LodLevel* getLodLevel(uint16 lod); 00162 00167 void preDeltaCalculation(const Rect& rect); 00168 00170 void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta); 00171 00174 void postDeltaCalculation(const Rect& rect); 00175 00179 void finaliseDeltaValues(const Rect& rect); 00180 00187 void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz); 00188 00193 void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution); 00194 00197 void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData); 00198 00199 00200 00207 void mergeIntoBounds(long x, long y, const Vector3& pos); 00211 void resetBounds(const Rect& rect); 00212 00217 bool rectIntersectsNode(const Rect& rect); 00222 bool rectContainsNode(const Rect& rect); 00227 bool pointIntersectsNode(long x, long y); 00228 00230 const AxisAlignedBox& getAABB() const; 00232 Real getBoundingRadius() const; 00234 const Vector3& getLocalCentre() const { return mLocalCentre; } 00236 Real getMinHeight() const; 00238 Real getMaxHeight() const; 00239 00245 bool calculateCurrentLod(const Camera* cam, Real cFactor); 00246 00248 int getCurrentLod() const { return mCurrentLod; } 00250 bool isRenderedAtCurrentLod() const; 00252 bool isSelfOrChildRenderedAtCurrentLod() const; 00254 void setCurrentLod(int lod); 00256 float getLodTransition() const { return mLodTransition; } 00258 void setLodTransition(float t); 00259 00261 static unsigned short POSITION_BUFFER; 00263 static unsigned short DELTA_BUFFER; 00264 00266 Renderable *_getRenderable(); 00267 protected: 00268 Terrain* mTerrain; 00269 TerrainQuadTreeNode* mParent; 00270 TerrainQuadTreeNode* mChildren[4]; 00271 LodLevelList mLodLevels; 00272 00273 uint16 mOffsetX, mOffsetY; 00274 uint16 mBoundaryX, mBoundaryY; 00276 uint16 mSize; 00277 uint16 mBaseLod; 00278 uint16 mDepth; 00279 uint16 mQuadrant; 00280 Vector3 mLocalCentre; 00281 AxisAlignedBox mAABB; 00282 Real mBoundingRadius; 00283 int mCurrentLod; 00284 unsigned short mMaterialLodIndex; 00285 float mLodTransition; 00286 00287 TerrainQuadTreeNode* mChildWithMaxHeightDelta; 00288 bool mSelfOrChildRendered; 00289 00290 struct VertexDataRecord : public TerrainAlloc 00291 { 00292 VertexData* cpuVertexData; 00293 VertexData* gpuVertexData; 00295 uint16 resolution; 00297 uint16 size; 00299 uint16 treeLevels; 00301 uint16 numSkirtRowsCols; 00303 uint16 skirtRowColSkip; 00305 bool gpuVertexDataDirty; 00306 00307 VertexDataRecord(uint16 res, uint16 sz, uint16 lvls) 00308 : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz), 00309 treeLevels(lvls), numSkirtRowsCols(0), 00310 skirtRowColSkip(0), gpuVertexDataDirty(false) {} 00311 }; 00312 00313 TerrainQuadTreeNode* mNodeWithVertexData; 00314 VertexDataRecord* mVertexDataRecord; 00315 00335 class _OgreTerrainExport Movable : public MovableObject 00336 { 00337 protected: 00338 TerrainQuadTreeNode* mParent; 00339 public: 00340 Movable(TerrainQuadTreeNode* parent); 00341 virtual ~Movable(); 00342 00343 // necessary overrides 00344 const String& getMovableType(void) const; 00345 const AxisAlignedBox& getBoundingBox(void) const; 00346 Real getBoundingRadius(void) const; 00347 void _updateRenderQueue(RenderQueue* queue); 00348 void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false); 00349 bool isVisible(void) const; 00350 uint32 getVisibilityFlags(void) const; 00351 uint32 getQueryFlags(void) const; 00352 bool getCastShadows(void) const; 00353 00354 }; 00355 Movable* mMovable; 00356 friend class Movable; 00357 SceneNode* mLocalNode; 00358 00360 class _OgreTerrainExport Rend : public Renderable, public TerrainAlloc 00361 { 00362 protected: 00363 TerrainQuadTreeNode* mParent; 00364 public: 00365 Rend(TerrainQuadTreeNode* parent); 00366 virtual ~Rend(); 00367 00368 const MaterialPtr& getMaterial(void) const; 00369 Technique* getTechnique(void) const; 00370 void getRenderOperation(RenderOperation& op); 00371 void getWorldTransforms(Matrix4* xform) const; 00372 Real getSquaredViewDepth(const Camera* cam) const; 00373 const LightList& getLights(void) const; 00374 bool getCastsShadows(void) const; 00375 00376 }; 00377 Rend* mRend; 00378 friend class Rend; 00379 00380 // actual implementation of MovableObject methods 00381 void updateRenderQueue(RenderQueue* queue); 00382 void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false); 00383 // actual implementations of Renderable methods 00384 const MaterialPtr& getMaterial(void) const; 00385 Technique* getTechnique(void) const; 00386 void getRenderOperation(RenderOperation& op); 00387 void getWorldTransforms(Matrix4* xform) const; 00388 Real getSquaredViewDepth(const Camera* cam) const; 00389 const LightList& getLights(void) const; 00390 bool getCastsShadows(void) const; 00391 00392 00393 const VertexDataRecord* getVertexDataRecord() const; 00394 void createCpuVertexData(); 00395 /* Update the vertex buffers - the rect in question is relative to the whole terrain, 00396 not the local vertex data (which may use a subset) 00397 */ 00398 void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect); 00399 void destroyCpuVertexData(); 00400 00401 void createGpuVertexData(); 00402 void destroyGpuVertexData(); 00403 void updateGpuVertexData(); 00404 void createGpuIndexData(); 00405 void destroyGpuIndexData(); 00406 00407 void populateIndexData(uint16 batchSize, IndexData* destData); 00408 void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos); 00409 void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta); 00410 00411 uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol); 00412 00413 }; 00414 00417 } 00418 00419 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48