OpenMW
Public Types | Public Member Functions | Private Member Functions | Private Attributes
Terrain::World Class Reference

A quadtree-based terrain implementation suitable for large data sets.
Near cells are rendered with alpha splatting, distant cells are merged together in batches and have their layers pre-rendered onto a composite map.
Cracks at LOD transitions are avoided using stitching. More...

#include <world.hpp>

List of all members.

Public Types

enum  IndexBufferFlags { IBF_North = 1 << 0, IBF_East = 1 << 1, IBF_South = 1 << 2, IBF_West = 1 << 3 }

Public Member Functions

 World (Loading::Listener *loadingListener, Ogre::SceneManager *sceneMgr, Storage *storage, int visiblityFlags, bool distantLand, bool shaders)
 ~World ()
void setLoadingListener (Loading::Listener *loadingListener)
bool getDistantLandEnabled ()
bool getShadersEnabled ()
bool getShadowsEnabled ()
bool getSplitShadowsEnabled ()
float getHeightAt (const Ogre::Vector3 &worldPos)
void update (const Ogre::Vector3 &cameraPos)
Ogre::AxisAlignedBox getWorldBoundingBox (const Ogre::Vector2 &center)
 Get the world bounding box of a chunk of terrain centered at center.
Ogre::SceneManager * getSceneManager ()
Ogre::SceneNode * getRootSceneNode ()
StoragegetStorage ()
void setVisible (bool visible)
bool getVisible ()
void applyMaterials (bool shadows, bool splitShadows)
int getVisiblityFlags ()
int getMaxBatchSize ()
void enableSplattingShader (bool enabled)
Ogre::HardwareIndexBufferSharedPtr getIndexBuffer (int flags, size_t &numIndices)
Ogre::HardwareVertexBufferSharedPtr getVertexBuffer (int numVertsOneSide)
Ogre::SceneManager * getCompositeMapSceneManager ()
void clearCompositeMapSceneManager ()
void renderCompositeMap (Ogre::TexturePtr target)

Private Member Functions

void buildQuadTree (QuadTreeNode *node)

Private Attributes

bool mDistantLand
bool mShaders
bool mShadows
bool mSplitShadows
bool mVisible
Loading::ListenermLoadingListener
QuadTreeNodemRootNode
Ogre::SceneNode * mRootSceneNode
StoragemStorage
int mVisibilityFlags
Ogre::SceneManager * mSceneMgr
Ogre::SceneManager * mCompositeMapSceneMgr
Ogre::AxisAlignedBox mBounds
 Bounds in cell units.
float mMinBatchSize
 Minimum size of a terrain batch along one side (in cell units)
float mMaxBatchSize
 Maximum size of a terrain batch along one side (in cell units)
std::map< int,
Ogre::HardwareIndexBufferSharedPtr > 
mIndexBufferMap
std::map< int,
Ogre::HardwareVertexBufferSharedPtr > 
mUvBufferMap
Ogre::RenderTarget * mCompositeMapRenderTarget
Ogre::TexturePtr mCompositeMapRenderTexture

Detailed Description

A quadtree-based terrain implementation suitable for large data sets.
Near cells are rendered with alpha splatting, distant cells are merged together in batches and have their layers pre-rendered onto a composite map.
Cracks at LOD transitions are avoided using stitching.

Note:
Multiple cameras are not supported yet

Member Enumeration Documentation

Enumerator:
IBF_North 
IBF_East 
IBF_South 
IBF_West 

Constructor & Destructor Documentation

Terrain::World::World ( Loading::Listener loadingListener,
Ogre::SceneManager *  sceneMgr,
Storage storage,
int  visiblityFlags,
bool  distantLand,
bool  shaders 
)
Note:
takes ownership of storage
Parameters:
loadingListenerListener to update with progress
sceneMgrscene manager to use
storageStorage instance to get terrain data from (heights, normals, colors, textures..)
visbilityFlagsvisibility flags for the created meshes
distantLandWhether to draw all of the terrain, or only a 3x3 grid around the camera. This is a temporary option until it can be streamlined.
shadersWhether to use splatting shader, or multi-pass fixed function splatting. Shader is usually faster so this is just here for compatibility.

Member Function Documentation

void Terrain::World::applyMaterials ( bool  shadows,
bool  splitShadows 
)

Recreate materials used by terrain chunks. This should be called whenever settings of the material factory are changed. (Relying on the factory to update those materials is not enough, since turning a feature on/off can change the number of texture units available for layer/blend textures, and to properly respond to this we may need to change the structure of the material, such as adding or removing passes. This can only be achieved by a full rebuild.)

void Terrain::World::buildQuadTree ( QuadTreeNode node) [private]
void Terrain::World::enableSplattingShader ( bool  enabled)
Ogre::SceneManager* Terrain::World::getCompositeMapSceneManager ( ) [inline]
float Terrain::World::getHeightAt ( const Ogre::Vector3 &  worldPos)
Ogre::HardwareIndexBufferSharedPtr Terrain::World::getIndexBuffer ( int  flags,
size_t &  numIndices 
)
Parameters:
flagsfirst 4*4 bits are LOD deltas on each edge, respectively (4 bits each) next 4 bits are LOD level of the index buffer (LOD 0 = don't omit any vertices)
numIndicesnumber of indices that were used will be written here
Ogre::SceneNode* Terrain::World::getRootSceneNode ( ) [inline]
Ogre::SceneManager* Terrain::World::getSceneManager ( ) [inline]
Ogre::HardwareVertexBufferSharedPtr Terrain::World::getVertexBuffer ( int  numVertsOneSide)
Ogre::AxisAlignedBox Terrain::World::getWorldBoundingBox ( const Ogre::Vector2 &  center)

Get the world bounding box of a chunk of terrain centered at center.

void Terrain::World::renderCompositeMap ( Ogre::TexturePtr  target)
void Terrain::World::setLoadingListener ( Loading::Listener loadingListener) [inline]
void Terrain::World::setVisible ( bool  visible)

Show or hide the whole terrain

Note:
this setting will be invalidated once you call Terrain::update, so do not call it while the terrain should be hidden
void Terrain::World::update ( const Ogre::Vector3 &  cameraPos)

Update chunk LODs according to this camera position

Note:
Calling this method might lead to composite textures being rendered, so it is best not to call it when render commands are still queued, since that would cause a flush.

Member Data Documentation

Ogre::AxisAlignedBox Terrain::World::mBounds [private]

Bounds in cell units.

Ogre::RenderTarget* Terrain::World::mCompositeMapRenderTarget [private]
Ogre::TexturePtr Terrain::World::mCompositeMapRenderTexture [private]
Ogre::SceneManager* Terrain::World::mCompositeMapSceneMgr [private]
std::map<int, Ogre::HardwareIndexBufferSharedPtr> Terrain::World::mIndexBufferMap [private]

Maximum size of a terrain batch along one side (in cell units)

Minimum size of a terrain batch along one side (in cell units)

Ogre::SceneNode* Terrain::World::mRootSceneNode [private]
Ogre::SceneManager* Terrain::World::mSceneMgr [private]
bool Terrain::World::mShaders [private]
bool Terrain::World::mShadows [private]
std::map<int, Ogre::HardwareVertexBufferSharedPtr> Terrain::World::mUvBufferMap [private]
bool Terrain::World::mVisible [private]

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