OGRE  1.9
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"
35 #include "OgreMovableObject.h"
36 #include "OgreRenderable.h"
37 
38 
39 
40 namespace Ogre
41 {
42  class HardwareVertexBufferSharedPtr;
43 
86  {
87  public:
98  uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
99  virtual ~TerrainQuadTreeNode();
100 
102  uint16 getXOffset() const { return mOffsetX; }
104  uint16 getYOffset() const { return mOffsetY; }
106  bool isLeaf() const;
108  uint16 getBaseLod() const { return mBaseLod; }
110  uint16 getLodCount() const;
112  TerrainQuadTreeNode* getChild(unsigned short child) const;
114  TerrainQuadTreeNode* getParent() const;
116  Terrain* getTerrain() const;
117 
119  void prepare();
121  void prepare(StreamSerialiser& stream);
123  void load();
125  void load(uint16 depthStart, uint16 depthEnd);
126  void loadSelf();
128  void unload();
130  void unload(uint16 depthStart, uint16 depthEnd);
132  void unprepare();
134  void save(StreamSerialiser& stream);
135 
137  {
150 
151  LodLevel() : batchSize(0), gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
152  lastTransitionDist(0), lastCFactor(0) {}
153  };
155 
161  const LodLevel* getLodLevel(uint16 lod);
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;
284  unsigned short mMaterialLodIndex;
286  TerrainQuadTreeNode* mChildWithMaxHeightDelta;
289 
291  {
306 
308  : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
309  treeLevels(lvls), numSkirtRowsCols(0),
310  skirtRowColSkip(0), gpuVertexDataDirty(false) {}
311  };
312 
315 
336  {
337  protected:
339  public:
340  Movable(TerrainQuadTreeNode* parent);
341  virtual ~Movable();
342 
343  // necessary overrides
344  const String& getMovableType(void) const;
345  const AxisAlignedBox& getBoundingBox(void) const;
346  Real getBoundingRadius(void) const;
347  void _updateRenderQueue(RenderQueue* queue);
348  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
349  bool isVisible(void) const;
350  uint32 getVisibilityFlags(void) const;
351  uint32 getQueryFlags(void) const;
352  bool getCastShadows(void) const;
353 
354  };
356  friend class Movable;
358 
361  {
362  protected:
364  public:
365  Rend(TerrainQuadTreeNode* parent);
366  virtual ~Rend();
367 
368  const MaterialPtr& getMaterial(void) const;
369  Technique* getTechnique(void) const;
370  void getRenderOperation(RenderOperation& op);
371  void getWorldTransforms(Matrix4* xform) const;
372  Real getSquaredViewDepth(const Camera* cam) const;
373  const LightList& getLights(void) const;
374  bool getCastsShadows(void) const;
375 
376  };
378  friend class Rend;
379 
380  // actual implementation of MovableObject methods
381  void updateRenderQueue(RenderQueue* queue);
382  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
383  // actual implementations of Renderable methods
384  const MaterialPtr& getMaterial(void) const;
385  Technique* getTechnique(void) const;
386  void getRenderOperation(RenderOperation& op);
387  void getWorldTransforms(Matrix4* xform) const;
388  Real getSquaredViewDepth(const Camera* cam) const;
389  const LightList& getLights(void) const;
390  bool getCastsShadows(void) const;
391 
392 
393  const VertexDataRecord* getVertexDataRecord() const;
394  void createCpuVertexData();
395  /* Update the vertex buffers - the rect in question is relative to the whole terrain,
396  not the local vertex data (which may use a subset)
397  */
398  void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
399  void destroyCpuVertexData();
400 
401  void createGpuVertexData();
402  void destroyGpuVertexData();
403  void updateGpuVertexData();
404  void createGpuIndexData();
405  void destroyGpuIndexData();
406 
407  void populateIndexData(uint16 batchSize, IndexData* destData);
408  void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos);
409  void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta);
410 
411  uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
412 
413  };
414 
417 }
418 
419 #endif
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
uint16 batchSize
Number of vertices rendered down one side (not including skirts)
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:344
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:262
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:53
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
Abstract class defining the interface all renderable objects must implement.
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.
unsigned short mMaterialLodIndex
-1 = none (do not render)
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.
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:51
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
TerrainQuadTreeNode * mNodeWithVertexData
unsigned short uint16
Definition: OgrePlatform.h:345
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.