2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-11-26 03:42:35 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-11-26 03:42:35 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-11-26 03:42:35 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-11-26 03:42:35 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2008-03-28 23:31:46 +08:00
|
|
|
#ifndef OSGTERRAIN_TERRAINTECHNIQUE
|
|
|
|
#define OSGTERRAIN_TERRAINTECHNIQUE 1
|
2003-11-26 03:42:35 +08:00
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
|
|
|
|
#include <osgUtil/UpdateVisitor>
|
|
|
|
#include <osgUtil/CullVisitor>
|
|
|
|
|
|
|
|
#include <osgTerrain/Export>
|
|
|
|
|
|
|
|
namespace osgTerrain {
|
|
|
|
|
2008-03-27 18:55:39 +08:00
|
|
|
class TerrainTile;
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2010-04-02 05:06:56 +08:00
|
|
|
class OSGTERRAIN_EXPORT TerrainNeighbours
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TerrainNeighbours();
|
|
|
|
~TerrainNeighbours();
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
void addNeighbour(TerrainTile* tile);
|
|
|
|
void removeNeighbour(TerrainTile* tile);
|
|
|
|
bool containsNeighbour(TerrainTile* tile) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2010-11-25 20:07:59 +08:00
|
|
|
TerrainNeighbours(const TerrainNeighbours& /*tn*/) {}
|
|
|
|
TerrainNeighbours& operator = (const TerrainNeighbours& /*rhs*/) { return *this; }
|
2010-04-02 05:06:56 +08:00
|
|
|
|
|
|
|
typedef std::set<TerrainTile*> Neighbours;
|
|
|
|
|
|
|
|
mutable OpenThreads::Mutex _neighboursMutex;
|
|
|
|
Neighbours _neighbours;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object, public osg::Observer
|
2003-11-26 03:42:35 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2007-03-14 19:24:04 +08:00
|
|
|
TerrainTechnique();
|
2003-11-26 03:42:35 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2007-03-14 19:24:04 +08:00
|
|
|
TerrainTechnique(const TerrainTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
2010-04-02 05:06:56 +08:00
|
|
|
|
2007-03-22 00:34:04 +08:00
|
|
|
META_Object(osgTerrain, TerrainTechnique);
|
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
TerrainTile* getTerrainTile() { return _terrainTile; }
|
|
|
|
const TerrainTile* getTerrainTile() const { return _terrainTile; }
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2010-04-04 00:21:34 +08:00
|
|
|
virtual void init(int dirtyMask, bool assumeMultiThreaded);
|
2007-03-22 00:34:04 +08:00
|
|
|
|
|
|
|
virtual void update(osgUtil::UpdateVisitor* nv);
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2007-03-22 00:34:04 +08:00
|
|
|
virtual void cull(osgUtil::CullVisitor* nv);
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2007-03-22 00:34:04 +08:00
|
|
|
/** Clean scene graph from any terrain technique specific nodes.*/
|
|
|
|
virtual void cleanSceneGraph();
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Traverse the terrain subgraph.*/
|
2007-03-28 00:01:01 +08:00
|
|
|
virtual void traverse(osg::NodeVisitor& nv);
|
|
|
|
|
From Jason Beverage, "I posted a question on osg users about resources not being properly released when using osgTerrain databases and multiple viewers are used a few weeks ago and I've found that at least part of the problem comes down to the fact that the nodes that are traversed by the GeometryTechnique are never actually added to the scene graph, and thus don't have releaseGLObjects called on them. I'm submitting a few changes that takes care of this by allowing the TerrainTechnique to provide a releaseGLObjects implementation. I've applied these changes in osgEarth and this example program no longer crashes on the second run, although I get corrupt geometry (see attached shot) which could be down to a driver issue. If I increment the context ID for the second viewer, I no longer get the corrupt geometry.
The attached changes are against OpenSceneGraph 2.8.2.
//Sample program. Run against an osgEarth or VPB database based on osgTerrain.
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer* viewer = new osgViewer::Viewer();
viewer->setUpViewInWindow(100,
100,500,500);
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
viewer->setSceneData( loadedModel.get() );
viewer->run();
delete viewer;
viewer = new osgViewer::Viewer();
viewer->setUpViewInWindow(100,100,500,500);
loadedModel = osgDB::readNodeFiles(arguments);
viewer->setSceneData( loadedModel.get() );
viewer->run();
delete viewer;
}"
2009-11-20 19:08:40 +08:00
|
|
|
/** If State is non-zero, this function releases any associated OpenGL objects for
|
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objects
|
|
|
|
* for all graphics contexts. */
|
|
|
|
virtual void releaseGLObjects(osg::State* = 0) const {}
|
|
|
|
|
2010-04-02 05:06:56 +08:00
|
|
|
void addNeighbour(TerrainTile* tile) { _neighbours.addNeighbour(tile); }
|
|
|
|
void removeNeighbour(TerrainTile* tile) { _neighbours.removeNeighbour(tile); }
|
|
|
|
bool containsNeighbour(TerrainTile* tile) { return _neighbours.containsNeighbour(tile); }
|
|
|
|
|
2003-11-26 03:42:35 +08:00
|
|
|
protected:
|
|
|
|
|
2007-03-14 19:24:04 +08:00
|
|
|
virtual ~TerrainTechnique();
|
2010-04-02 05:06:56 +08:00
|
|
|
|
|
|
|
void setTerrainTile(TerrainTile* tile);
|
|
|
|
void setDirty(bool dirty);
|
|
|
|
|
2008-03-27 18:55:39 +08:00
|
|
|
friend class osgTerrain::TerrainTile;
|
2003-11-26 03:42:35 +08:00
|
|
|
|
2010-04-02 05:06:56 +08:00
|
|
|
TerrainTile* _terrainTile;
|
|
|
|
|
|
|
|
|
|
|
|
TerrainNeighbours _neighbours;
|
2003-11-26 03:42:35 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|