OGRE  1.9.0
OgreTerrainQuadTreeNode.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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
40namespace Ogre
41{
42 class HardwareVertexBufferSharedPtr;
43
86 {
87 public:
98 uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
100
102 uint16 getXOffset() const { return mOffsetX; }
104 uint16 getYOffset() const { return mOffsetY; }
106 bool isLeaf() const;
108 uint16 getBaseLod() const { return mBaseLod; }
112 TerrainQuadTreeNode* getChild(unsigned short child) const;
117
119 void prepare();
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
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;
234 const Vector3& getLocalCentre() const { return mLocalCentre; }
239
245 bool calculateCurrentLod(const Camera* cam, Real cFactor);
246
248 int getCurrentLod() const { return mCurrentLod; }
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
267 protected:
270 TerrainQuadTreeNode* mChildren[4];
272
273 uint16 mOffsetX, mOffsetY;
274 uint16 mBoundaryX, mBoundaryY;
284 unsigned short mMaterialLodIndex;
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:
341 virtual ~Movable();
342
343 // necessary overrides
344 const String& getMovableType(void) const;
345 const AxisAlignedBox& getBoundingBox(void) const;
348 void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
349 bool isVisible(void) const;
352 bool getCastShadows(void) const;
353
354 };
356 friend class Movable;
358
361 {
362 protected:
364 public:
366 virtual ~Rend();
367
368 const MaterialPtr& getMaterial(void) const;
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
382 void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
383 // actual implementations of Renderable methods
384 const MaterialPtr& getMaterial(void) const;
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
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 */
400
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
#define _OgreTerrainExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
A 3D box aligned with the x/y/z axes.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Shared pointer implementation used to share vertex buffers.
Summary class collecting together index data source information.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Abstract class defining a movable object in a scene.
'New' rendering operation using vertex buffers.
Class to manage the scene object rendering queue.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
Abstract class defining the interface all renderable objects must implement.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:59
Utility class providing helper methods for reading / writing structured data held in a DataStream.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:54
MovableObject implementation to provide the hook to the scene.
Real getBoundingRadius(void) const
Retrieves the radius of the origin-centered bounding sphere for this object.
bool getCastShadows(void) const
Returns whether shadow casting is enabled for this object.
const String & getMovableType(void) const
Returns the type name of this object.
bool isVisible(void) const
Returns whether or not this object is supposed to be visible or not.
Movable(TerrainQuadTreeNode *parent)
uint32 getVisibilityFlags(void) const
Returns the visibility flags relevant for this object.
uint32 getQueryFlags(void) const
Returns the query flags relevant for this object.
void _updateRenderQueue(RenderQueue *queue)
Internal method by which the movable object must add Renderable subclass instances to the rendering q...
const AxisAlignedBox & getBoundingBox(void) const
Retrieves the local axis-aligned bounding box for this object.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
Rend(TerrainQuadTreeNode *parent)
void getWorldTransforms(Matrix4 *xform) const
Gets the world transform matrix / matrices for this renderable object.
Real getSquaredViewDepth(const Camera *cam) const
Returns the camera-relative squared depth of this renderable.
void getRenderOperation(RenderOperation &op)
Gets the render operation required to send this object to the frame buffer.
const MaterialPtr & getMaterial(void) const
Retrieves a weak reference to the material this renderable object uses.
const LightList & getLights(void) const
Gets a list of lights, ordered relative to how close they are to this renderable.
Technique * getTechnique(void) const
Retrieves a pointer to the Material Technique this renderable object uses.
bool getCastsShadows(void) const
Method which reports whether this renderable would normally cast a shadow.
A node in a quad tree used to store a patch of terrain.
void unload()
Unload node and children (perform GPU tasks, will be render thread)
void load(uint16 depthStart, uint16 depthEnd)
Load node and children in a depth range (perform GPU tasks, will be render thread)
void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float **ppDelta)
TerrainQuadTreeNode(Terrain *terrain, TerrainQuadTreeNode *parent, uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant)
Constructor.
bool isSelfOrChildRenderedAtCurrentLod() const
Returns whether this node or its children are being rendered at the current LOD level.
TerrainQuadTreeNode * getParent() const
Get parent node.
void preDeltaCalculation(const Rect &rect)
Notify the node (and children) that deltas are going to be calculated for a given range.
Technique * getTechnique(void) const
Real getMaxHeight() const
Get the maximum height of the node.
void useAncestorVertexData(TerrainQuadTreeNode *owner, uint16 treeDepthEnd, uint16 resolution)
Tell a node that it should use an anscestor's vertex data.
uint16 getXOffset() const
Get the horizontal offset into the main terrain data of this node.
void postDeltaCalculation(const Rect &rect)
Notify the node (and children) that deltas have finished being calculated.
TerrainQuadTreeNode * mNodeWithVertexData
TerrainQuadTreeNode * mChildWithMaxHeightDelta
0-1 transition to lower LOD
void populateIndexData(uint16 batchSize, IndexData *destData)
bool isRenderedAtCurrentLod() const
Returns whether this node is rendering itself at the current LOD level.
const VertexDataRecord * getVertexDataRecord() const
void prepare()
Prepare node and children (perform CPU tasks, may be background thread)
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
vector< LodLevel * >::type LodLevelList
const Vector3 & getLocalCentre() const
Get the local centre of this node, relative to parent terrain centre.
const MaterialPtr & getMaterial(void) const
bool getCastsShadows(void) const
static unsigned short DELTA_BUFFER
Buffer binding used for holding delta values.
unsigned short mMaterialLodIndex
-1 = none (do not render)
void updateRenderQueue(RenderQueue *queue)
void getRenderOperation(RenderOperation &op)
int mCurrentLod
Relative to mLocalCentre.
const LightList & getLights(void) const
bool calculateCurrentLod(const Camera *cam, Real cFactor)
Calculate appropriate LOD for this node and children.
void setCurrentLod(int lod)
Manually set the current LOD, intended for internal use only.
void load()
Load node and children (perform GPU tasks, will be render thread)
uint16 getLodCount() const
Get the number of LOD levels this node can represent itself (only > 1 for leaf nodes)
bool pointIntersectsNode(long x, long y)
Returns true if the given point is in the terrain area that this node references.
void prepare(StreamSerialiser &stream)
Prepare node from a stream.
Real getSquaredViewDepth(const Camera *cam) const
int getCurrentLod() const
Get the current LOD index (only valid after calculateCurrentLod)
void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3 &pos, float uvScale, float **ppPos)
AxisAlignedBox mAABB
Relative to terrain centre.
Renderable * _getRenderable()
Returns the internal renderable object for this node.
void updateVertexData(bool positions, bool deltas, const Rect &rect, bool cpuData)
Tell the node to update its vertex data for a given region.
Terrain * getTerrain() const
Get ultimate parent terrain.
uint16 mSize
The number of vertices at the original terrain resolution this node encompasses.
void mergeIntoBounds(long x, long y, const Vector3 &pos)
Merge a point (relative to terrain node) into the local bounds, and that of children if applicable.
Real getMinHeight() const
Get the minimum height of the node.
bool isLeaf() const
Is this a leaf node (no children)
void resetBounds(const Rect &rect)
Reset the bounds of this node and all its children for the region given.
const AxisAlignedBox & getAABB() const
Get the AABB (local coords) of this node.
bool rectContainsNode(const Rect &rect)
Returns true if the given rectangle completely contains the terrain area that this node references.
uint16 getBaseLod() const
Get the base LOD level this node starts at (the highest LOD it handles)
void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz)
Assign vertex data to the tree, from a depth and at a given resolution.
void finaliseDeltaValues(const Rect &rect)
Promote the delta values calculated to the runtime ones (this must be called in the main thread).
const LodLevel * getLodLevel(uint16 lod)
Get the LodLevel information for a given lod.
void save(StreamSerialiser &stream)
Save node to a stream.
void updateVertexBuffer(HardwareVertexBufferSharedPtr &posbuf, HardwareVertexBufferSharedPtr &deltabuf, const Rect &rect)
uint16 getYOffset() const
Get the vertical offset into the main terrain data of this node.
uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol)
static unsigned short POSITION_BUFFER
Buffer binding used for holding positions.
void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta)
Notify the node (and children) of a height delta value.
void unprepare()
Unprepare node and children (perform CPU tasks, may be background thread)
TerrainQuadTreeNode * getChild(unsigned short child) const
Get child node.
Real mBoundingRadius
Relative to mLocalCentre.
float getLodTransition() const
Get the transition state between the current LOD and the next lower one (only valid after calculateCu...
void unload(uint16 depthStart, uint16 depthEnd)
Unload node and children in a depth range (perform GPU tasks, will be render thread)
void setLodTransition(float t)
Manually set the current LOD transition state, intended for internal use only.
bool rectIntersectsNode(const Rect &rect)
Returns true if the given rectangle overlaps the terrain area that this node references.
Real getBoundingRadius() const
Get the bounding radius of this node.
void getWorldTransforms(Matrix4 *xform) const
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:264
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
Summary class collecting together vertex source information.
float Real
Software floating point type.
unsigned short uint16
Definition: OgrePlatform.h:345
unsigned int uint
unsigned int uint32
Definition: OgrePlatform.h:344
_StringBase String
Real maxHeightDelta
Maximum delta height between this and the next lower lod.
uint16 batchSize
Number of vertices rendered down one side (not including skirts)
Real calcMaxHeightDelta
Temp calc area for max height delta.
IndexData * gpuIndexData
Index data on the gpu.
Real lastTransitionDist
The most recently calculated transition distance.
Real lastCFactor
The cFactor value used to calculate transitionDist.
VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
uint16 resolution
Resolution of the data compared to the base terrain data (NOT number of vertices!)
uint16 numSkirtRowsCols
Number of rows and columns of skirts.
bool gpuVertexDataDirty
Is the GPU vertex data out of date?
uint16 treeLevels
Number of quadtree levels (including this one) this data applies to.
uint16 skirtRowColSkip
The number of rows / cols to skip in between skirts.
uint16 size
Size of the data along one edge.
std::vector< T, A > type