osgEarth 2.1.1
|
Public Member Functions | |
Terrain (const MapFrame &update_mapf, const MapFrame &cull_mapf, OSGTileFactory *factory, bool quickReleaseGLObjects) | |
virtual const char * | libraryName () const |
virtual const char * | className () const |
OSGTileFactory * | getTileFactory () |
bool | getQuickReleaseGLObjects () const |
const MapFrame & | getUpdateThreadMapFrame () |
const MapFrame & | getCullThreadMapFrame () |
virtual Tile * | createTile (const TileKey &key, GeoLocator *locator) const |
void | setTechniquePrototype (TerrainTechnique *tech) |
TerrainTechnique * | cloneTechnique () const |
void | setSampleRatio (float value) |
float | getSampleRatio () const |
void | setVerticalScale (float value) |
float | getVerticalScale () const |
virtual void | traverse (osg::NodeVisitor &nv) |
void | releaseGLObjectsForTiles (osg::State *state) |
void | registerTile (Tile *newTile) |
void | getTiles (TileVector &out_tiles) |
template<typename T > | |
void | getTile (const osgTerrain::TileID &id, osg::ref_ptr< T > &out_tile, bool lock=true) const |
Protected Types | |
typedef std::map < osgTerrain::TileID, osg::ref_ptr< Tile > > | TileTable |
typedef std::queue < osg::ref_ptr< Tile > > | TileQueue |
typedef std::list < osg::ref_ptr< Tile > > | TileList |
typedef std::vector < osg::ref_ptr< Tile > > | TileVector |
typedef std::queue < osgTerrain::TileID > | TileIDQueue |
Protected Member Functions | |
virtual | ~Terrain () |
virtual unsigned | getNumActiveTasks () const |
virtual void | updateTraversal (osg::NodeVisitor &nv) |
void | setDelay (unsigned frames) |
void | decDelay () |
Protected Attributes | |
Threading::ReadWriteMutex | _tilesMutex |
TileTable | _tiles |
TileList | _tilesToShutDown |
TileVector | _tilesToRelease |
Threading::Mutex | _tilesToReleaseMutex |
float | _sampleRatio |
float | _verticalScale |
osg::ref_ptr< OSGTileFactory > | _tileFactory |
osg::ref_ptr< const Profile > | _profile |
bool | _alwaysUpdate |
int | _onDemandDelay |
bool | _registeredWithReleaseGLCallback |
const MapFrame & | _update_mapf |
const MapFrame & | _cull_mapf |
bool | _quickReleaseGLObjects |
bool | _quickReleaseCallbackInstalled |
osg::ref_ptr< TerrainTechnique > | _techPrototype |
typedef std::queue< osgTerrain::TileID > Terrain::TileIDQueue [protected] |
typedef std::list< osg::ref_ptr<Tile> > Terrain::TileList [protected] |
typedef std::queue< osg::ref_ptr<Tile> > Terrain::TileQueue [protected] |
typedef std::map< osgTerrain::TileID, osg::ref_ptr<Tile> > Terrain::TileTable [protected] |
typedef std::vector< osg::ref_ptr<Tile> > Terrain::TileVector [protected] |
Terrain::Terrain | ( | const MapFrame & | update_mapf, |
const MapFrame & | cull_mapf, | ||
OSGTileFactory * | factory, | ||
bool | quickReleaseGLObjects | ||
) |
Definition at line 89 of file Terrain.cpp.
: _tileFactory( tileFactory ), _registeredWithReleaseGLCallback( false ), _update_mapf( update_mapf ), _cull_mapf( cull_mapf ), _onDemandDelay( 2 ), _quickReleaseGLObjects( quickReleaseGLObjects ), _quickReleaseCallbackInstalled( false ), _alwaysUpdate( false ), _sampleRatio( 1.0f ), _verticalScale( 1.0f ) { this->setThreadSafeRefUnref( true ); // the EVENT_VISITOR will reset this to 0 once the "delay" is expired. _alwaysUpdate = false; setNumChildrenRequiringUpdateTraversal( 1 ); // register for events in order to support ON_DEMAND frame scheme setNumChildrenRequiringEventTraversal( 1 ); getOrCreateStateSet()->setMode(GL_BLEND , osg::StateAttribute::ON); }
Terrain::~Terrain | ( | ) | [protected, virtual] |
Definition at line 117 of file Terrain.cpp.
virtual const char* Terrain::className | ( | ) | const [inline, virtual] |
TerrainTechnique * Terrain::cloneTechnique | ( | ) | const |
Definition at line 135 of file Terrain.cpp.
{ return osg::clone( _techPrototype.get(), osg::CopyOp::DEEP_COPY_ALL ); }
Tile * Terrain::createTile | ( | const TileKey & | key, |
GeoLocator * | locator | ||
) | const [virtual] |
Reimplemented in StreamingTerrain.
Definition at line 141 of file Terrain.cpp.
{ return new Tile( key, keyLocator, this->getQuickReleaseGLObjects() ); }
void Terrain::decDelay | ( | ) | [protected] |
Definition at line 321 of file Terrain.cpp.
{ _onDemandDelay--; if ( _onDemandDelay == 0 && !_alwaysUpdate ) { ADJUST_UPDATE_TRAV_COUNT(this, -1); } }
const MapFrame& Terrain::getCullThreadMapFrame | ( | ) | [inline] |
Definition at line 62 of file Terrain.
{ return _cull_mapf; }
virtual unsigned Terrain::getNumActiveTasks | ( | ) | const [inline, protected, virtual] |
Reimplemented in StreamingTerrain.
Definition at line 85 of file Terrain.
{ return 0; }
bool Terrain::getQuickReleaseGLObjects | ( | ) | const [inline] |
Definition at line 58 of file Terrain.
{ return _quickReleaseGLObjects; }
float Terrain::getSampleRatio | ( | ) | const [inline] |
Definition at line 72 of file Terrain.
{ return _sampleRatio; }
void Terrain::getTile | ( | const osgTerrain::TileID & | id, |
osg::ref_ptr< T > & | out_tile, | ||
bool | lock = true |
||
) | const [inline] |
Fetches a tile from the repo
Definition at line 117 of file Terrain.
{ if ( lock ) { Threading::ScopedReadLock lock( const_cast<Terrain*>(this)->_tilesMutex ); TileTable::const_iterator i = _tiles.find( id ); out_tile = i != _tiles.end()? static_cast<T*>(i->second.get()) : 0L; } else { TileTable::const_iterator i = _tiles.find( id ); out_tile = i != _tiles.end()? static_cast<T*>(i->second.get()) : 0L; } }
OSGTileFactory* Terrain::getTileFactory | ( | ) | [inline] |
Definition at line 56 of file Terrain.
{ return _tileFactory.get(); }
void Terrain::getTiles | ( | TileVector & | out_tiles | ) |
Gets a thread-safe copy of the entire tile list
Definition at line 165 of file Terrain.cpp.
{ Threading::ScopedReadLock lock( _tilesMutex ); out.clear(); out.reserve( _tiles.size() ); for( TileTable::const_iterator i = _tiles.begin(); i != _tiles.end(); ++i ) out.push_back( i->second.get() ); }
const MapFrame& Terrain::getUpdateThreadMapFrame | ( | ) | [inline] |
Definition at line 60 of file Terrain.
{ return _update_mapf; }
float Terrain::getVerticalScale | ( | ) | const [inline] |
Definition at line 76 of file Terrain.
{ return _verticalScale; }
virtual const char* Terrain::libraryName | ( | ) | const [inline, virtual] |
void Terrain::registerTile | ( | Tile * | newTile | ) |
Definition at line 175 of file Terrain.cpp.
{ Threading::ScopedWriteLock exclusiveTileTableLock( _tilesMutex ); _tiles[ newTile->getTileId() ] = newTile; }
void Terrain::releaseGLObjectsForTiles | ( | osg::State * | state | ) |
Definition at line 184 of file Terrain.cpp.
{ OpenThreads::ScopedLock<Mutex> lock( _tilesToReleaseMutex ); for( TileVector::iterator i = _tilesToRelease.begin(); i != _tilesToRelease.end(); ++i ) { i->get()->releaseGLObjects( state ); } _tilesToRelease.clear(); //while( _tilesToRelease.size() > 0 ) //{ // _tilesToRelease.front()->releaseGLObjects( state ); // _tilesToRelease.pop(); //} }
void Terrain::setDelay | ( | unsigned | frames | ) | [protected] |
Definition at line 311 of file Terrain.cpp.
{ if ( _onDemandDelay == 0 && !_alwaysUpdate ) { ADJUST_UPDATE_TRAV_COUNT( this, 1 ); } _onDemandDelay = frames; }
void Terrain::setSampleRatio | ( | float | value | ) |
Definition at line 156 of file Terrain.cpp.
{ if ( value != _sampleRatio ) { _sampleRatio = value; } }
void Terrain::setTechniquePrototype | ( | TerrainTechnique * | tech | ) |
Definition at line 129 of file Terrain.cpp.
{ _techPrototype = value; }
void Terrain::setVerticalScale | ( | float | value | ) |
Definition at line 147 of file Terrain.cpp.
{ if ( value != _verticalScale ) { _verticalScale = value; } }
void Terrain::traverse | ( | osg::NodeVisitor & | nv | ) | [virtual] |
Definition at line 203 of file Terrain.cpp.
{ // UPDATE runs whenever a Tile runs its update traversal on the first pass. // i.e., only runs then a new Tile is born. if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR ) { // if the terrain engine requested "quick release", install the quick release // draw callback now. if ( _quickReleaseGLObjects && !_quickReleaseCallbackInstalled ) { osg::Camera* cam = findFirstParentOfType<osg::Camera>( this ); if ( cam ) { cam->setPostDrawCallback( new QuickReleaseGLCallback( this, cam->getPostDrawCallback() ) ); _quickReleaseCallbackInstalled = true; OE_INFO << LC << "Quick release enabled" << std::endl; } } // Collect any "dead" tiles and queue them for shutdown. Since UPDATE only runs // when new tiles arrive, this clears out old tiles from the queue at that time. // Another approach might be to use an observer_ptr instead...but then we may // not be able to use the quick-release. { Threading::ScopedWriteLock tileTableExclusiveLock( _tilesMutex ); for( TileTable::iterator i = _tiles.begin(); i != _tiles.end(); ) { Tile* tile = i->second.get(); if ( tile->getNumParents() == 0 && tile->getHasBeenTraversed() ) { _tilesToShutDown.push_back( tile ); // i is incremented prior to calling erase, but i's previous value goes to erase, // maintaining validity _tiles.erase( i++ ); } else ++i; } } // Remove any dead tiles from the main tile table, while at the same time queuing // any tiles that require quick-release. This criticial section requires an exclusive // lock on the main tile table. if ( _tilesToShutDown.size() > 0 ) // quick no-lock check.. { Threading::ScopedMutexLock tilesToReleaseExclusiveLock( _tilesToReleaseMutex ); // Shut down any dead tiles once there tasks are complete. for( TileList::iterator i = _tilesToShutDown.begin(); i != _tilesToShutDown.end(); ) { Tile* tile = i->get(); if ( tile && tile->cancelActiveTasks() ) { if ( _quickReleaseGLObjects && _quickReleaseCallbackInstalled ) { _tilesToRelease.push_back( tile ); } i = _tilesToShutDown.erase( i ); } else ++i; } } // call subclass to continue update.. updateTraversal( nv ); } else if ( nv.getVisitorType() == osg::NodeVisitor::EVENT_VISITOR ) { // in OSG's "ON_DEMAND" frame scheme, OSG runs the event visitor as part of the // test to see if a frame is needed. In sequential/preemptive mode, we need to // check whether there are any pending tasks running. // In addition, once the tasks run out, we continue to delay on-demand rendering // for another full frame so that the event dispatchers can catch up. if ( _tilesToShutDown.size() > 0 ) { setDelay( 2 ); } else if ( _onDemandDelay <= 0 ) { unsigned numActiveTasks = getNumActiveTasks(); if ( numActiveTasks > 0 ) { setDelay( 2 ); } } //OE_INFO << "Tasks = " << numTasks << std::endl; if ( _onDemandDelay > 0 ) { osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>( &nv ); ev->getActionAdapter()->requestRedraw(); decDelay(); } } osg::Group::traverse( nv ); }
virtual void Terrain::updateTraversal | ( | osg::NodeVisitor & | nv | ) | [inline, protected, virtual] |
Reimplemented in StreamingTerrain.
Definition at line 88 of file Terrain.
{ }
bool Terrain::_alwaysUpdate [protected] |
const MapFrame& Terrain::_cull_mapf [protected] |
int Terrain::_onDemandDelay [protected] |
osg::ref_ptr<const Profile> Terrain::_profile [protected] |
bool Terrain::_quickReleaseCallbackInstalled [protected] |
bool Terrain::_quickReleaseGLObjects [protected] |
bool Terrain::_registeredWithReleaseGLCallback [protected] |
float Terrain::_sampleRatio [protected] |
osg::ref_ptr<TerrainTechnique> Terrain::_techPrototype [protected] |
osg::ref_ptr<OSGTileFactory> Terrain::_tileFactory [protected] |
TileTable Terrain::_tiles [protected] |
Threading::ReadWriteMutex Terrain::_tilesMutex [protected] |
TileVector Terrain::_tilesToRelease [protected] |
Threading::Mutex Terrain::_tilesToReleaseMutex [protected] |
TileList Terrain::_tilesToShutDown [protected] |
const MapFrame& Terrain::_update_mapf [protected] |
float Terrain::_verticalScale [protected] |