OGRE 14.3
Object-Oriented Graphics Rendering Engine
Loading...
Searching...
No Matches
Ogre::TerrainQuadTreeNode Class Reference

A node in a quad tree used to store a patch of terrain. More...

#include <OgreTerrainQuadTreeNode.h>

+ Inheritance diagram for Ogre::TerrainQuadTreeNode:

Classes

struct  LodLevel
 

Public Types

typedef std::vector< LodLevel * > LodLevelList
 

Public Member Functions

 TerrainQuadTreeNode (Terrain *terrain, TerrainQuadTreeNode *parent, uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth)
 Constructor.
 
virtual ~TerrainQuadTreeNode ()
 
void assignVertexData (uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz)
 Assign vertex data to the tree, from a depth and at a given resolution.
 
bool calculateCurrentLod (const Camera *cam, Real cFactor)
 Calculate appropriate LOD for this node and children.
 
void finaliseDeltaValues (const Rect &rect)
 Promote the delta values calculated to the runtime ones (this must be called in the main thread).
 
uint16 getBaseLod () const
 Get the base LOD level this node starts at (the highest LOD it handles)
 
const AxisAlignedBoxgetBoundingBox (void) const override
 Get the AABB (local coords) of this node.
 
Real getBoundingRadius () const override
 Get the bounding radius of this node.
 
TerrainQuadTreeNodegetChild (unsigned short child) const
 Get child node.
 
int getCurrentLod () const
 Get the current LOD index (only valid after calculateCurrentLod)
 
const Vector3getLocalCentre () const
 Get the local centre of this node, relative to parent terrain centre.
 
uint16 getLodCount () const
 Get the number of LOD levels this node can represent itself (only > 1 for leaf nodes)
 
const LodLevelgetLodLevel (uint16 lod)
 Get the LodLevel information for a given lod.
 
float getLodTransition () const
 Get the transition state between the current LOD and the next lower one (only valid after calculateCurrentLod)
 
Real getMaxHeight () const
 Get the maximum height of the node.
 
Real getMinHeight () const
 Get the minimum height of the node.
 
TerrainQuadTreeNodegetParent () const
 Get parent node.
 
TerraingetTerrain () const
 Get ultimate parent terrain.
 
uint16 getXOffset () const
 Get the horizontal offset into the main terrain data of this node.
 
uint16 getYOffset () const
 Get the vertical offset into the main terrain data of this node.
 
bool isLeaf () const
 Is this a leaf node (no children)
 
bool isRenderedAtCurrentLod () const
 Returns whether this node is rendering itself at the current LOD level.
 
bool isSelfOrChildRenderedAtCurrentLod () const
 Returns whether this node or its children are being rendered at the current LOD level.
 
void load ()
 Load 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 loadSelf ()
 
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.
 
void notifyDelta (uint16 x, uint16 y, uint16 lod, Real delta)
 Notify the node (and children) of a height delta value.
 
bool pointIntersectsNode (long x, long y)
 Returns true if the given point is in the terrain area that this node references.
 
void postDeltaCalculation (const Rect &rect)
 Notify the node (and children) that deltas have finished being calculated.
 
void preDeltaCalculation (const Rect &rect)
 Notify the node (and children) that deltas are going to be calculated for a given range.
 
void prepare ()
 Prepare node and children (perform CPU tasks, may be background thread)
 
void prepare (StreamSerialiser &stream)
 Prepare node from a stream.
 
bool rectContainsNode (const Rect &rect)
 Returns true if the given rectangle completely contains the terrain area that this node references.
 
bool rectIntersectsNode (const Rect &rect)
 Returns true if the given rectangle overlaps the terrain area that this node references.
 
void resetBounds (const Rect &rect)
 Reset the bounds of this node and all its children for the region given.
 
void save (StreamSerialiser &stream)
 Save node to a stream.
 
void setCurrentLod (int lod)
 Manually set the current LOD, intended for internal use only.
 
void setLodTransition (float t)
 Manually set the current LOD transition state, intended for internal use only.
 
void unload ()
 Unload node and children (perform GPU tasks, will be render thread)
 
void unload (uint16 depthStart, uint16 depthEnd)
 Unload node and children in a depth range (perform GPU tasks, will be render thread)
 
void unprepare ()
 Unprepare node and children (perform CPU tasks, may be background thread)
 
void updateVertexData (bool positions, bool deltas, const Rect &rect, bool cpuData)
 Tell the node to update its vertex data for a given region.
 
void useAncestorVertexData (TerrainQuadTreeNode *owner, uint16 treeDepthEnd, uint16 resolution)
 Tell a node that it should use an anscestor's vertex data.
 

Static Public Attributes

static unsigned short DELTA_BUFFER
 Buffer binding used for holding delta values.
 
static unsigned short POSITION_BUFFER
 Buffer binding used for holding positions.
 

Detailed Description

A node in a quad tree used to store a patch of terrain.

Algorithm overview:

Our goal is to perform traditional chunked LOD with geomorphing. But, instead of just dividing the terrain into tiles, we will divide them into a hierarchy of tiles, a quadtree, where any level of the quadtree can be a rendered tile (to the exclusion of its children). The idea is to collect together children into a larger batch with their siblings as LOD decreases, to improve performance.
The minBatchSize and maxBatchSize parameters on Terrain a key to defining this behaviour. Both values are expressed in vertices down one axis. maxBatchSize determines the number of tiles on one side of the terrain, which is numTiles = (terrainSize-1) / (maxBatchSize-1). This in turn determines the depth of the quad tree, which is sqrt(numTiles). The minBatchSize determines the 'floor' of how low the number of vertices can go in a tile before it has to be grouped together with its siblings to drop any lower. We also do not group a tile with its siblings unless all of them are at this minimum batch size, rather than trying to group them when they all end up on the same 'middle' LOD; this is for several reasons; firstly, tiles hitting the same 'middle' LOD is less likely and more transient if they have different levels of 'roughness', and secondly since we're sharing a vertex / index pool between all tiles, only grouping at the min level means that the number of combinations of buffer sizes for any one tile is greatly simplified, making it easier to pool data. To be more specific, any tile / quadtree node can only have log2(maxBatchSize-1) - log2(minBatchSize-1) + 1 LOD levels (and if you set them to the same value, LOD can only change by going up/down the quadtree). The numbers of vertices / indices in each of these levels is constant for the same (relative) LOD index no matter where you are in the tree, therefore buffers can potentially be reused more easily.

Member Typedef Documentation

◆ LodLevelList

Constructor & Destructor Documentation

◆ TerrainQuadTreeNode()

Ogre::TerrainQuadTreeNode::TerrainQuadTreeNode ( Terrain terrain,
TerrainQuadTreeNode parent,
uint16  xoff,
uint16  yoff,
uint16  size,
uint16  lod,
uint16  depth 
)

Constructor.

Parameters
terrainThe ultimate parent terrain
parentOptional parent node (in which case xoff, yoff are 0 and size must be entire terrain)
xoff,yoffOffsets from the start of the terrain data in 2D
sizeThe size of the node in vertices at the highest LOD
lodThe base LOD level
depthThe depth that this node is at in the tree (or convenience)

◆ ~TerrainQuadTreeNode()

virtual Ogre::TerrainQuadTreeNode::~TerrainQuadTreeNode ( )
virtual

Member Function Documentation

◆ getXOffset()

uint16 Ogre::TerrainQuadTreeNode::getXOffset ( ) const
inline

Get the horizontal offset into the main terrain data of this node.

◆ getYOffset()

uint16 Ogre::TerrainQuadTreeNode::getYOffset ( ) const
inline

Get the vertical offset into the main terrain data of this node.

◆ isLeaf()

bool Ogre::TerrainQuadTreeNode::isLeaf ( ) const

Is this a leaf node (no children)

◆ getBaseLod()

uint16 Ogre::TerrainQuadTreeNode::getBaseLod ( ) const
inline

Get the base LOD level this node starts at (the highest LOD it handles)

◆ getLodCount()

uint16 Ogre::TerrainQuadTreeNode::getLodCount ( ) const

Get the number of LOD levels this node can represent itself (only > 1 for leaf nodes)

◆ getChild()

TerrainQuadTreeNode * Ogre::TerrainQuadTreeNode::getChild ( unsigned short  child) const

Get child node.

◆ getParent()

TerrainQuadTreeNode * Ogre::TerrainQuadTreeNode::getParent ( ) const

Get parent node.

◆ getTerrain()

Terrain * Ogre::TerrainQuadTreeNode::getTerrain ( ) const

Get ultimate parent terrain.

◆ prepare() [1/2]

void Ogre::TerrainQuadTreeNode::prepare ( )

Prepare node and children (perform CPU tasks, may be background thread)

◆ prepare() [2/2]

void Ogre::TerrainQuadTreeNode::prepare ( StreamSerialiser stream)

Prepare node from a stream.

◆ load() [1/2]

void Ogre::TerrainQuadTreeNode::load ( )

Load node and children (perform GPU tasks, will be render thread)

◆ load() [2/2]

void Ogre::TerrainQuadTreeNode::load ( uint16  depthStart,
uint16  depthEnd 
)

Load node and children in a depth range (perform GPU tasks, will be render thread)

◆ loadSelf()

void Ogre::TerrainQuadTreeNode::loadSelf ( )

◆ unload() [1/2]

void Ogre::TerrainQuadTreeNode::unload ( )

Unload node and children (perform GPU tasks, will be render thread)

◆ unload() [2/2]

void Ogre::TerrainQuadTreeNode::unload ( uint16  depthStart,
uint16  depthEnd 
)

Unload node and children in a depth range (perform GPU tasks, will be render thread)

◆ unprepare()

void Ogre::TerrainQuadTreeNode::unprepare ( )

Unprepare node and children (perform CPU tasks, may be background thread)

◆ save()

void Ogre::TerrainQuadTreeNode::save ( StreamSerialiser stream)

Save node to a stream.

◆ getLodLevel()

const LodLevel * Ogre::TerrainQuadTreeNode::getLodLevel ( uint16  lod)

Get the LodLevel information for a given lod.

Parameters
lodThe lod level index relative to this classes own list; if you want to use a global lod level, subtract getBaseLod() first. Higher LOD levels are lower detail.

◆ preDeltaCalculation()

void Ogre::TerrainQuadTreeNode::preDeltaCalculation ( const Rect rect)

Notify the node (and children) that deltas are going to be calculated for a given range.

Based on this call, we can know whether or not to reset the max height.

◆ notifyDelta()

void Ogre::TerrainQuadTreeNode::notifyDelta ( uint16  x,
uint16  y,
uint16  lod,
Real  delta 
)

Notify the node (and children) of a height delta value.

◆ postDeltaCalculation()

void Ogre::TerrainQuadTreeNode::postDeltaCalculation ( const Rect rect)

Notify the node (and children) that deltas have finished being calculated.

◆ finaliseDeltaValues()

void Ogre::TerrainQuadTreeNode::finaliseDeltaValues ( const Rect rect)

Promote the delta values calculated to the runtime ones (this must be called in the main thread).

◆ assignVertexData()

void Ogre::TerrainQuadTreeNode::assignVertexData ( uint16  treeDepthStart,
uint16  treeDepthEnd,
uint16  resolution,
uint  sz 
)

Assign vertex data to the tree, from a depth and at a given resolution.

Parameters
treeDepthStartThe first depth of tree that should use this data, owns the data
treeDepthEndThe end of the depth that should use this data (exclusive)
resolutionThe resolution of the data to use (compared to full terrain)
szThe size of the data along one edge

◆ useAncestorVertexData()

void Ogre::TerrainQuadTreeNode::useAncestorVertexData ( TerrainQuadTreeNode owner,
uint16  treeDepthEnd,
uint16  resolution 
)

Tell a node that it should use an anscestor's vertex data.

Parameters
owner
treeDepthEndThe end of the depth that should use this data (exclusive)
resolutionThe resolution of the data to use

◆ updateVertexData()

void Ogre::TerrainQuadTreeNode::updateVertexData ( bool  positions,
bool  deltas,
const Rect rect,
bool  cpuData 
)

Tell the node to update its vertex data for a given region.

◆ mergeIntoBounds()

void Ogre::TerrainQuadTreeNode::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.

Parameters
x,yThe point on the terrain to which this position corresponds (affects which nodes update their bounds)
posThe position relative to the terrain centre

◆ resetBounds()

void Ogre::TerrainQuadTreeNode::resetBounds ( const Rect rect)

Reset the bounds of this node and all its children for the region given.

Parameters
rectThe region for which bounds should be reset, in top-level terrain coords

◆ rectIntersectsNode()

bool Ogre::TerrainQuadTreeNode::rectIntersectsNode ( const Rect rect)

Returns true if the given rectangle overlaps the terrain area that this node references.

Parameters
rectThe region in top-level terrain coords

◆ rectContainsNode()

bool Ogre::TerrainQuadTreeNode::rectContainsNode ( const Rect rect)

Returns true if the given rectangle completely contains the terrain area that this node references.

Parameters
rectThe region in top-level terrain coords

◆ pointIntersectsNode()

bool Ogre::TerrainQuadTreeNode::pointIntersectsNode ( long  x,
long  y 
)

Returns true if the given point is in the terrain area that this node references.

Parameters
x,yThe point in top-level terrain coords

◆ getBoundingBox()

const AxisAlignedBox & Ogre::TerrainQuadTreeNode::getBoundingBox ( void  ) const
inlineoverridevirtual

Get the AABB (local coords) of this node.

Implements Ogre::MovableObject.

◆ getBoundingRadius()

Real Ogre::TerrainQuadTreeNode::getBoundingRadius ( ) const
overridevirtual

Get the bounding radius of this node.

Implements Ogre::MovableObject.

◆ getLocalCentre()

const Vector3 & Ogre::TerrainQuadTreeNode::getLocalCentre ( ) const
inline

Get the local centre of this node, relative to parent terrain centre.

◆ getMinHeight()

Real Ogre::TerrainQuadTreeNode::getMinHeight ( ) const

Get the minimum height of the node.

◆ getMaxHeight()

Real Ogre::TerrainQuadTreeNode::getMaxHeight ( ) const

Get the maximum height of the node.

◆ calculateCurrentLod()

bool Ogre::TerrainQuadTreeNode::calculateCurrentLod ( const Camera cam,
Real  cFactor 
)

Calculate appropriate LOD for this node and children.

Parameters
camThe camera to be used (this should already be the LOD camera)
cFactorThe cFactor which incorporates the viewport size, max pixel error and lod bias
Returns
true if this node or any of its children were selected for rendering

◆ getCurrentLod()

int Ogre::TerrainQuadTreeNode::getCurrentLod ( ) const
inline

Get the current LOD index (only valid after calculateCurrentLod)

◆ isRenderedAtCurrentLod()

bool Ogre::TerrainQuadTreeNode::isRenderedAtCurrentLod ( ) const

Returns whether this node is rendering itself at the current LOD level.

◆ isSelfOrChildRenderedAtCurrentLod()

bool Ogre::TerrainQuadTreeNode::isSelfOrChildRenderedAtCurrentLod ( ) const

Returns whether this node or its children are being rendered at the current LOD level.

◆ setCurrentLod()

void Ogre::TerrainQuadTreeNode::setCurrentLod ( int  lod)

Manually set the current LOD, intended for internal use only.

◆ getLodTransition()

float Ogre::TerrainQuadTreeNode::getLodTransition ( ) const
inline

Get the transition state between the current LOD and the next lower one (only valid after calculateCurrentLod)

◆ setLodTransition()

void Ogre::TerrainQuadTreeNode::setLodTransition ( float  t)

Manually set the current LOD transition state, intended for internal use only.

Member Data Documentation

◆ POSITION_BUFFER

unsigned short Ogre::TerrainQuadTreeNode::POSITION_BUFFER
static

Buffer binding used for holding positions.

◆ DELTA_BUFFER

unsigned short Ogre::TerrainQuadTreeNode::DELTA_BUFFER
static

Buffer binding used for holding delta values.


The documentation for this class was generated from the following file: