OpenSceneGraph/include/osgTerrain/TerrainTechnique

106 lines
3.1 KiB
Plaintext
Raw Normal View History

2006-07-18 23:21:48 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2003-11-26 03:42:35 +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
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#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
class OSGTERRAIN_EXPORT TerrainNeighbours
{
public:
TerrainNeighbours();
~TerrainNeighbours();
void clear();
void addNeighbour(TerrainTile* tile);
void removeNeighbour(TerrainTile* tile);
bool containsNeighbour(TerrainTile* tile) const;
protected:
TerrainNeighbours(const TerrainNeighbours& tn) {}
TerrainNeighbours& operator = (const TerrainNeighbours& rhs) { return *this; }
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:
TerrainTechnique();
2003-11-26 03:42:35 +08:00
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TerrainTechnique(const TerrainTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgTerrain, TerrainTechnique);
TerrainTile* getTerrainTile() { return _terrainTile; }
const TerrainTile* getTerrainTile() const { return _terrainTile; }
2003-11-26 03:42:35 +08:00
virtual void init(int dirtyMask, bool assumeMultiThreaded);
virtual void update(osgUtil::UpdateVisitor* nv);
2003-11-26 03:42:35 +08:00
virtual void cull(osgUtil::CullVisitor* nv);
2003-11-26 03:42:35 +08:00
/** Clean scene graph from any terrain technique specific nodes.*/
virtual void cleanSceneGraph();
2003-11-26 03:42:35 +08:00
/** Traverse the terrain subgraph.*/
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 {}
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:
virtual ~TerrainTechnique();
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
TerrainTile* _terrainTile;
TerrainNeighbours _neighbours;
2003-11-26 03:42:35 +08:00
};
}
#endif