OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTerrainQuadTreeNode.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __Ogre_TerrainQuadTreeNode_H__
30 #define __Ogre_TerrainQuadTreeNode_H__
31 
33 #include "OgreCommon.h"
34 #include "OgreMovableObject.h"
35 #include "OgreRenderable.h"
36 
37 namespace Ogre
38 {
39  class HardwareVertexBufferSharedPtr;
40 
83  {
84  public:
94  TerrainQuadTreeNode(ObjectMemoryManager *objectMemoryManager, Terrain* terrain, TerrainQuadTreeNode* parent,
95  uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
96  virtual ~TerrainQuadTreeNode();
97 
99  uint16 getXOffset() const { return mOffsetX; }
101  uint16 getYOffset() const { return mOffsetY; }
103  bool isLeaf() const;
105  uint16 getBaseLod() const { return mBaseLod; }
107  uint16 getLodCount() const;
109  TerrainQuadTreeNode* getChild(unsigned short child) const;
111  TerrainQuadTreeNode* getParent() const;
113  Terrain* getTerrain() const;
114 
116  void prepare();
118  void prepare(StreamSerialiser& stream);
120  void load();
122  void load(uint16 depthStart, uint16 depthEnd);
123  void loadSelf();
125  void unload();
127  void unload(uint16 depthStart, uint16 depthEnd);
129  void unprepare();
131  void save(StreamSerialiser& stream);
132 
134  {
147 
148  LodLevel() : batchSize(0), gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
149  lastTransitionDist(0), lastCFactor(0) {}
150  };
152 
158  const LodLevel* getLodLevel(uint16 lod);
159 
161  void notifyMaterialChanged(void);
162 
167  void preDeltaCalculation(const Rect& rect);
168 
170  void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta);
171 
174  void postDeltaCalculation(const Rect& rect);
175 
179  void finaliseDeltaValues(const Rect& rect);
180 
187  void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz);
188 
193  void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution);
194 
197  void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData);
198 
199 
200 
207  void mergeIntoBounds(long x, long y, const Vector3& pos);
211  void resetBounds(const Rect& rect);
212 
217  bool rectIntersectsNode(const Rect& rect);
222  bool rectContainsNode(const Rect& rect);
227  bool pointIntersectsNode(long x, long y);
228 
230  const AxisAlignedBox& getAABB() const;
232  Real getBoundingRadius() const;
234  const Vector3& getLocalCentre() const { return mLocalCentre; }
236  Real getMinHeight() const;
238  Real getMaxHeight() const;
239 
245  bool calculateCurrentLod(const Camera* cam, Real cFactor);
246 
248  int getCurrentLod() const { return mCurrentLod; }
250  bool isRenderedAtCurrentLod() const;
252  bool isSelfOrChildRenderedAtCurrentLod() const;
254  void setCurrentLod(int lod);
256  float getLodTransition() const { return mLodTransition; }
258  void setLodTransition(float t);
259 
261  static unsigned short POSITION_BUFFER;
263  static unsigned short DELTA_BUFFER;
264 
266  Renderable *_getRenderable();
267  protected:
270  TerrainQuadTreeNode* mChildren[4];
272 
273  uint16 mOffsetX, mOffsetY;
274  uint16 mBoundaryX, mBoundaryY;
285  TerrainQuadTreeNode* mChildWithMaxHeightDelta;
288 
290  {
305 
307  : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
308  treeLevels(lvls), numSkirtRowsCols(0),
309  skirtRowColSkip(0), gpuVertexDataDirty(false) {}
310  };
311 
314 
335  {
336  protected:
338  public:
339  Movable(IdType id, ObjectMemoryManager *objectMemoryManager, TerrainQuadTreeNode* parent);
340  virtual ~Movable();
341 
342  // necessary overrides
343  const String& getMovableType(void) const;
344  const AxisAlignedBox& getBoundingBox(void) const;
345  Real getBoundingRadius(void) const;
346  void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
347  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
348  bool isVisible(void) const;
349  uint32 getVisibilityFlags(void) const;
350  uint32 getQueryFlags(void) const;
351 // bool getCastShadows(void) const;
352 
353  void setMaterialLodValues( const MaterialPtr &material );
354 
355  };
357  friend class Movable;
359 
362  {
363  protected:
365  public:
366  Rend(TerrainQuadTreeNode* parent);
367  virtual ~Rend();
368 
369  const MaterialPtr& getMaterial(void) const;
370  Technique* getTechnique(void) const;
371  void getRenderOperation(RenderOperation& op);
372  void getWorldTransforms(Matrix4* xform) const;
373  Real getSquaredViewDepth(const Camera* cam) const;
374  const LightList& getLights(void) const;
375  bool getCastsShadows(void) const;
376 
377  };
379  friend class Rend;
380 
381  // actual implementation of MovableObject methods
382  void updateRenderQueue(RenderQueue* queue);
383  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
384  // actual implementations of Renderable methods
385  const MaterialPtr& getMaterial(void) const;
386  Technique* getTechnique(void) const;
387  void getRenderOperation(RenderOperation& op);
388  void getWorldTransforms(Matrix4* xform) const;
389  Real getSquaredViewDepth(const Camera* cam) const;
390  const LightList& getLights(void) const;
391  bool getCastsShadows(void) const;
392 
393 
394  const VertexDataRecord* getVertexDataRecord() const;
395  void createCpuVertexData();
396  /* Update the vertex buffers - the rect in question is relative to the whole terrain,
397  not the local vertex data (which may use a subset)
398  */
399  void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
400  void destroyCpuVertexData();
401 
402  void createGpuVertexData();
403  void destroyGpuVertexData();
404  void updateGpuVertexData();
405  void createGpuIndexData();
406  void destroyGpuIndexData();
407 
408  void populateIndexData(uint16 batchSize, IndexData* destData);
409  void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos);
410  void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta);
411 
412  uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
413 
414  };
415 
418 }
419 
420 #endif
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
uint16 batchSize
Number of vertices rendered down one side (not including skirts)
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
uint16 getXOffset() const
Get the horizontal offset into the main terrain data of this node.
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:265
IndexData * gpuIndexData
Index data on the gpu.
Real mBoundingRadius
Relative to mLocalCentre.
uint16 skirtRowColSkip
The number of rows / cols to skip in between skirts.
Real calcMaxHeightDelta
Temp calc area for max height delta.
uint16 treeLevels
Number of quadtree levels (including this one) this data applies to.
Shared pointer implementation used to share vertex buffers.
A 3D box aligned with the x/y/z axes.
vector< LodLevel * >::type LodLevelList
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:50
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:53
Abstract class defining the interface all renderable objects must implement.
float mLodTransition
-1 = none (do not render)
uint16 resolution
Resolution of the data compared to the base terrain data (NOT number of vertices!) ...
AxisAlignedBox mAABB
Relative to terrain centre.
Real maxHeightDelta
Maximum delta height between this and the next lower lod.
uint16 getBaseLod() const
Get the base LOD level this node starts at (the highest LOD it handles)
static unsigned short DELTA_BUFFER
Buffer binding used for holding delta values.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
int getCurrentLod() const
Get the current LOD index (only valid after calculateCurrentLod)
float getLodTransition() const
Get the transition state between the current LOD and the next lower one (only valid after calculateCu...
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Summary class collecting together index data source information.
VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
#define _OgreTerrainExport
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
static unsigned short POSITION_BUFFER
Buffer binding used for holding positions.
uint16 getYOffset() const
Get the vertical offset into the main terrain data of this node.
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
uint16 size
Size of the data along one edge.
Real lastCFactor
The cFactor value used to calculate transitionDist.
uint16 numSkirtRowsCols
Number of rows and columns of skirts.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
Real lastTransitionDist
The most recently calculated transition distance.
Class to manage the scene object rendering queue.
const Vector3 & getLocalCentre() const
Get the local centre of this node, relative to parent terrain centre.
MovableObject implementation to provide the hook to the scene.
int mCurrentLod
Relative to mLocalCentre.
bool gpuVertexDataDirty
Is the GPU vertex data out of date?
_StringBase String
Definition: OgreCommon.h:53
TerrainQuadTreeNode * mNodeWithVertexData
unsigned short uint16
Definition: OgrePlatform.h:421
A node in a quad tree used to store a patch of terrain.
unsigned int uint
uint16 mSize
The number of vertices at the original terrain resolution this node encompasses.