Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Public Member Functions | Protected Attributes | List of all members
vl::Terrain Class Reference

The Terrain class implements a ActorKdTree-based terrain scene manager. More...

#include <Terrain.hpp>

+ Inheritance diagram for vl::Terrain:

Public Member Functions

 Terrain ()
 
void init ()
 
bool useGLSL () const
 
int detailRepetitionMode () const
 
double width () const
 
double depth () const
 
double height () const
 
const vec3origin () const
 
const StringdetailTexture () const
 
const StringterrainTexture () const
 
const StringheightmapTexture () const
 
ETextureFormat heightmapTextureFormat () const
 
ETextureFormat terrainTextureFormat () const
 
ETextureFormat detailTextureFormat () const
 
void setUseGLSL (bool enable)
 
void setDetailRepetitionCount (int count)
 
void setWidth (double w)
 
void setDepth (double d)
 
void setHeight (double h)
 
void setOrigin (const vec3 &origin)
 
void setHeightmapTextureFormat (ETextureFormat format)
 
void setTerrainTextureFormat (ETextureFormat format)
 
void setDetailTextureFormat (ETextureFormat format)
 
void setVertexShader (const String &vs_path)
 
const StringvertexShader () const
 
void setFragmentShader (const String &fs_path)
 
const StringfragmentShader () const
 
const ActorCollectionchunks () const
 
int chunkCount () const
 
Actorchunk (int i)
 
const Actorchunk (int i) const
 
void setDetailTexture (const String &texture)
 Sets the texture to be used as detail texture, it can be of any size. More...
 
void setTerrainTexture (const String &texture)
 Sets the texture to be used as the base terrain texture. More...
 
void setHeightmapTexture (const String &texture)
 Sets the texture to be used as the heightmap. More...
 
const ShaderNodeshaderNode () const
 
ShaderNodeshaderNode ()
 
- Public Member Functions inherited from vl::SceneManagerActorKdTree
 SceneManagerActorKdTree ()
 
- Public Member Functions inherited from vl::SceneManagerBVH< ActorKdTree >
void setTree (ActorKdTree *bbh)
 Sets the tree to be used by the scene manager. More...
 
const ActorKdTreetree () const
 Returns the tree used by the scene manager. More...
 
ActorKdTreetree ()
 Returns the tree used by the scene manager. More...
 
virtual void extractVisibleActors (ActorCollection &list, const Camera *camera)
 Extracts all the enabled and visible Actors contained in the ActorTree hierarchy and appends them to the given ActorCollection. More...
 
virtual void extractActors (ActorCollection &list)
 Appends all the Actors contained in the scene manager without performing frustum culling or checking enable masks. More...
 
- Public Member Functions inherited from vl::SceneManager
 SceneManager ()
 Constructor. More...
 
virtual void computeBounds ()
 Computes the bounding box and bounding sphere of the scene manager and of all the Actors contained in the SceneManager. More...
 
void setBoundingSphere (const Sphere &sphere)
 Explicitly set the scene manager's bounding sphere. See also computeBounds(). More...
 
const SphereboundingSphere () const
 Returns the scene manager's bounding sphere. More...
 
void setBoundingBox (const AABB &bbox)
 Explicitly set the scene manager's bounding sphere. See also computeBounds(). More...
 
const AABBboundingBox () const
 Returns the scene manager's bounding box. More...
 
void setBoundsDirty (bool dirty)
 Flags a scene manager's bounding box and bounding sphere as dirty. The bounds will be recomputed using computeBounds() at the next rendering frame. More...
 
bool boundsDirty () const
 Returns true if the scene manager's bounds should be recomputed at the next rendering frame. More...
 
void setCullingEnabled (bool enable)
 Used to enable or disable frustum culling or whichever culling system the scene manager implements. More...
 
bool cullingEnabled () const
 Used to enable or disable frustum culling or whichever culling system the scene manager implements. More...
 
void setEnableMask (unsigned int enabled)
 The enable mask to be used by extractVisibleActors() More...
 
unsigned int enableMask () const
 The enable mask to be used by extractVisibleActors() More...
 
bool isEnabled (Actor *a) const
 Returns true if "a->enableMask() & enableMask()) != 0". More...
 
- Public Member Functions inherited from vl::Object
 Object ()
 Constructor. More...
 
 Object (const Object &other)
 Copy constructor: copies the name, ref count mutex and user data. More...
 
Objectoperator= (const Object &other)
 Copy operator: copies the object's name, ref count mutex and user data. More...
 
const std::string & objectName () const
 The name of the object, by default set to the object's class name. More...
 
void setObjectName (const char *name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setObjectName (const std::string &name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setRefCountMutex (IMutex *mutex)
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
IMutexrefCountMutex ()
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
const IMutexrefCountMutex () const
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
int referenceCount () const
 Returns the number of references of an object. More...
 
void incReference () const
 Increments the reference count of an object. More...
 
void decReference ()
 Decrements the reference count of an object and deletes it if both automaticDelete() is true the count reaches 0. More...
 
void setAutomaticDelete (bool autodel_on)
 If set to true the Object is deleted when its reference count reaches 0. More...
 
bool automaticDelete () const
 If set to true the Object is deleted when its reference count reaches 0. More...
 
template<class T >
T * as ()
 Casts an Object to the specified class. More...
 
template<class T >
const T * as () const
 Casts an Object to the specified class. More...
 

Protected Attributes

ref< ShaderNodemShaderNode
 
ActorCollection mChunks
 
double mWidth
 
double mHeight
 
double mDepth
 
vec3 mOrigin
 
String mDetailTexture
 
String mTerrainTexture
 
String mHeightmapTexture
 
String mVertexShader
 
String mFragmentShader
 
int mDetailRepetitionCount
 
ETextureFormat mHeightmapTextureFormat
 
ETextureFormat mTerrainTextureFormat
 
ETextureFormat mDetailTextureFormat
 
bool mUseGLSL
 
- Protected Attributes inherited from vl::SceneManagerBVH< ActorKdTree >
ref< ActorKdTreemBoundingVolumeTree
 
- Protected Attributes inherited from vl::SceneManager
Sphere mSphere
 
AABB mAABB
 
unsigned int mEnableMask
 
bool mBoundsDirty
 
bool mCullingEnabled
 
- Protected Attributes inherited from vl::Object
std::string mObjectName
 
IMutexmRefCountMutex
 
int mReferenceCount
 
bool mAutomaticDelete
 

Additional Inherited Members

- Protected Member Functions inherited from vl::Object
virtual ~Object ()
 

Detailed Description

The Terrain class implements a ActorKdTree-based terrain scene manager.

Some applications do not need complex LOD or CLOD management algorithms to display height fields or terrains, either because the data displayed has a limited size or because particular constraints are applied to the camera (like in RTS games for example) for which only a limited portion of the terrain is visible at a given time.

This applications can greatly benefit from the vl::Terrain scene manager which implements a fool-proof, high-precision (8, 16 and 32 bits heightmaps are supported) and efficient terrain/heightfield generation and management system. All the user has to provide is a texture for the terrain, a heightfield image and a detail texture following very simple and precise guidelines.

The vl::Terrain class takes care of all the rest, like dividing the provided images into chunks, generating the geometry, generating the kd-tree, computing the appropriate texture coordinates in order to prevent seams and so on.

If the OpenGL Shading Language is available, the vl::Terrain class can also store the heightmap directly on the GPU and can generate the geometry on the fly using a technique called "vertex texture fetch" (http://developer.nvidia.com/object/using_vertex_textures.html). This technique allows the application to save GPU memory and to manage even greater terrain databases at a higher speed.

See also
setTerrainTexture(), setHeightmapTexture(), setDetailTexture()

Definition at line 63 of file Terrain.hpp.

Constructor & Destructor Documentation

◆ Terrain()

vl::Terrain::Terrain ( )
inline

Definition at line 68 of file Terrain.hpp.

Member Function Documentation

◆ chunk() [1/2]

Actor* vl::Terrain::chunk ( int  i)
inline

Definition at line 109 of file Terrain.hpp.

◆ chunk() [2/2]

const Actor* vl::Terrain::chunk ( int  i) const
inline

Definition at line 110 of file Terrain.hpp.

◆ chunkCount()

int vl::Terrain::chunkCount ( ) const
inline

Definition at line 108 of file Terrain.hpp.

◆ chunks()

const ActorCollection& vl::Terrain::chunks ( ) const
inline

Definition at line 107 of file Terrain.hpp.

◆ depth()

double vl::Terrain::depth ( ) const
inline

Definition at line 81 of file Terrain.hpp.

Referenced by init().

◆ detailRepetitionMode()

int vl::Terrain::detailRepetitionMode ( ) const
inline

Definition at line 79 of file Terrain.hpp.

◆ detailTexture()

const String& vl::Terrain::detailTexture ( ) const
inline

Definition at line 84 of file Terrain.hpp.

Referenced by init().

◆ detailTextureFormat()

ETextureFormat vl::Terrain::detailTextureFormat ( ) const
inline

Definition at line 89 of file Terrain.hpp.

Referenced by init().

◆ fragmentShader()

const String& vl::Terrain::fragmentShader ( ) const
inline

Definition at line 105 of file Terrain.hpp.

Referenced by init().

◆ height()

double vl::Terrain::height ( ) const
inline

Definition at line 82 of file Terrain.hpp.

Referenced by init().

◆ heightmapTexture()

const String& vl::Terrain::heightmapTexture ( ) const
inline

Definition at line 86 of file Terrain.hpp.

Referenced by init().

◆ heightmapTextureFormat()

ETextureFormat vl::Terrain::heightmapTextureFormat ( ) const
inline

Definition at line 87 of file Terrain.hpp.

Referenced by init().

◆ init()

void Terrain::init ( )

Definition at line 43 of file Terrain.cpp.

References vl::ShaderNode::addChild(), vl::Object::as(), vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::at(), vl::GLSLProgram::attachShader(), vl::ActorKdTree::buildKdTree(), vl::Collection< T >::clear(), depth(), detailTexture(), detailTextureFormat(), vl::String::empty(), vl::EN_CULL_FACE, vl::EN_DEPTH_TEST, vl::Log::error(), fragmentShader(), vl::ref< T >::get(), vl::Texture::getTexParameter(), height(), vl::Image::height(), heightmapTexture(), heightmapTextureFormat(), vl::IN_Propagate, vl::loadImage(), vl::String::loadText(), vl::makeGrid(), vl::max(), mChunks, mDepth, mDetailRepetitionCount, mHeight, mOrigin, mWidth, NULL, vl::Collection< T >::push_back(), vl::Vector4< T_Scalar >::r(), vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::resize(), vl::Vector2< T_Scalar >::s(), vl::Image::sample(), vl::Matrix4< T_Scalar >::scale(), vl::TexParameter::setAnisotropy(), vl::Renderable::setBoundingBox(), vl::Renderable::setBoundingSphere(), vl::Renderable::setBoundsDirty(), vl::Geometry::setColorArray(), vl::ShaderNode::setEnable(), vl::Transform::setLocalAndWorldMatrix(), vl::TexParameter::setMagFilter(), vl::AABB::setMaxCorner(), vl::AABB::setMinCorner(), vl::TexParameter::setMinFilter(), vl::TexEnv::setMode(), vl::ShaderNode::setRenderState(), vl::ShaderNode::setShader(), vl::Geometry::setTexCoordArray(), vl::TextureImageUnit::setTexture(), vl::Uniform::setUniform(), vl::Actor::setUniform(), vl::GLSLProgram::setUniform(), vl::Shader::setUniform(), vl::Uniform::setUniformF(), vl::Uniform::setUniformI(), vl::Actor::setUniformSet(), vl::TexParameter::setWrapS(), vl::TexParameter::setWrapT(), vl::Effect::shader(), shaderNode(), vl::Image::subImage(), vl::Vector2< T_Scalar >::t(), vl::TEM_MODULATE, terrainTexture(), terrainTextureFormat(), vl::TextureImageUnit::texture(), vl::TPF_LINEAR, vl::TPF_LINEAR_MIPMAP_LINEAR, vl::TPF_NEAREST, vl::TPW_REPEAT, vl::Matrix4< T_Scalar >::translate(), vl::SceneManagerBVH< ActorKdTree >::tree(), vl::ShaderNode::updateHierarchy(), useGLSL(), vl::Geometry::vertexArray(), vertexShader(), VL_CHECK, width(), vl::Image::width(), and vl::Vector3< T_Scalar >::y().

◆ origin()

const vec3& vl::Terrain::origin ( ) const
inline

Definition at line 83 of file Terrain.hpp.

◆ setDepth()

void vl::Terrain::setDepth ( double  d)
inline

Definition at line 94 of file Terrain.hpp.

◆ setDetailRepetitionCount()

void vl::Terrain::setDetailRepetitionCount ( int  count)
inline

Definition at line 92 of file Terrain.hpp.

◆ setDetailTexture()

void vl::Terrain::setDetailTexture ( const String texture)
inline

Sets the texture to be used as detail texture, it can be of any size.

Definition at line 115 of file Terrain.hpp.

◆ setDetailTextureFormat()

void vl::Terrain::setDetailTextureFormat ( ETextureFormat  format)
inline

Definition at line 99 of file Terrain.hpp.

◆ setFragmentShader()

void vl::Terrain::setFragmentShader ( const String fs_path)
inline

Definition at line 104 of file Terrain.hpp.

◆ setHeight()

void vl::Terrain::setHeight ( double  h)
inline

Definition at line 95 of file Terrain.hpp.

◆ setHeightmapTexture()

void vl::Terrain::setHeightmapTexture ( const String texture)
inline

Sets the texture to be used as the heightmap.

Its size must be of the form: n * d - n + 1 where:

  • 'n' is any positive integer. 'n' is the value passed to setChunkSubdivision().
  • 'd' is a power of 2 and defines the dimension of the heightmap portion used to build each terrain chunk. For example: for a terrain with 8x8 chunks each of which with a 256x256 heightmap we have: 8*256-8+1 = 2041 = x and y size of the heightmap image.

Definition at line 131 of file Terrain.hpp.

◆ setHeightmapTextureFormat()

void vl::Terrain::setHeightmapTextureFormat ( ETextureFormat  format)
inline

Definition at line 97 of file Terrain.hpp.

◆ setOrigin()

void vl::Terrain::setOrigin ( const vec3 origin)
inline

Definition at line 96 of file Terrain.hpp.

◆ setTerrainTexture()

void vl::Terrain::setTerrainTexture ( const String texture)
inline

Sets the texture to be used as the base terrain texture.

Its size must be of the form: n * d - n + 1 where:

  • 'n' is any positive integer. 'n' is the value passed to setChunkSubdivision().
  • 'd' is a power of 2 and defines the dimension of the texture applied to each terrain chunk. For example: for a terrain with 8x8 chunks each of which with a 256x256 texture we have: 8*256-8+1 = 2041 = x and y size of the texture image.

Definition at line 123 of file Terrain.hpp.

◆ setTerrainTextureFormat()

void vl::Terrain::setTerrainTextureFormat ( ETextureFormat  format)
inline

Definition at line 98 of file Terrain.hpp.

◆ setUseGLSL()

void vl::Terrain::setUseGLSL ( bool  enable)
inline

Definition at line 91 of file Terrain.hpp.

◆ setVertexShader()

void vl::Terrain::setVertexShader ( const String vs_path)
inline

Definition at line 101 of file Terrain.hpp.

◆ setWidth()

void vl::Terrain::setWidth ( double  w)
inline

Definition at line 93 of file Terrain.hpp.

◆ shaderNode() [1/2]

const ShaderNode* vl::Terrain::shaderNode ( ) const
inline

Definition at line 133 of file Terrain.hpp.

Referenced by init().

◆ shaderNode() [2/2]

ShaderNode* vl::Terrain::shaderNode ( )
inline

Definition at line 134 of file Terrain.hpp.

◆ terrainTexture()

const String& vl::Terrain::terrainTexture ( ) const
inline

Definition at line 85 of file Terrain.hpp.

Referenced by init().

◆ terrainTextureFormat()

ETextureFormat vl::Terrain::terrainTextureFormat ( ) const
inline

Definition at line 88 of file Terrain.hpp.

Referenced by init().

◆ useGLSL()

bool vl::Terrain::useGLSL ( ) const
inline

Definition at line 78 of file Terrain.hpp.

Referenced by init().

◆ vertexShader()

const String& vl::Terrain::vertexShader ( ) const
inline

Definition at line 102 of file Terrain.hpp.

Referenced by init().

◆ width()

double vl::Terrain::width ( ) const
inline

Definition at line 80 of file Terrain.hpp.

Referenced by init().

Member Data Documentation

◆ mChunks

ActorCollection vl::Terrain::mChunks
protected

Definition at line 138 of file Terrain.hpp.

Referenced by init().

◆ mDepth

double vl::Terrain::mDepth
protected

Definition at line 141 of file Terrain.hpp.

Referenced by init().

◆ mDetailRepetitionCount

int vl::Terrain::mDetailRepetitionCount
protected

Definition at line 148 of file Terrain.hpp.

Referenced by init().

◆ mDetailTexture

String vl::Terrain::mDetailTexture
protected

Definition at line 143 of file Terrain.hpp.

◆ mDetailTextureFormat

ETextureFormat vl::Terrain::mDetailTextureFormat
protected

Definition at line 151 of file Terrain.hpp.

◆ mFragmentShader

String vl::Terrain::mFragmentShader
protected

Definition at line 147 of file Terrain.hpp.

◆ mHeight

double vl::Terrain::mHeight
protected

Definition at line 140 of file Terrain.hpp.

Referenced by init().

◆ mHeightmapTexture

String vl::Terrain::mHeightmapTexture
protected

Definition at line 145 of file Terrain.hpp.

◆ mHeightmapTextureFormat

ETextureFormat vl::Terrain::mHeightmapTextureFormat
protected

Definition at line 149 of file Terrain.hpp.

◆ mOrigin

vec3 vl::Terrain::mOrigin
protected

Definition at line 142 of file Terrain.hpp.

Referenced by init().

◆ mShaderNode

ref<ShaderNode> vl::Terrain::mShaderNode
protected

Definition at line 137 of file Terrain.hpp.

◆ mTerrainTexture

String vl::Terrain::mTerrainTexture
protected

Definition at line 144 of file Terrain.hpp.

◆ mTerrainTextureFormat

ETextureFormat vl::Terrain::mTerrainTextureFormat
protected

Definition at line 150 of file Terrain.hpp.

◆ mUseGLSL

bool vl::Terrain::mUseGLSL
protected

Definition at line 152 of file Terrain.hpp.

◆ mVertexShader

String vl::Terrain::mVertexShader
protected

Definition at line 146 of file Terrain.hpp.

◆ mWidth

double vl::Terrain::mWidth
protected

Definition at line 139 of file Terrain.hpp.

Referenced by init().


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