diff --git a/simgear/scene/tgdb/VPBTechnique.cxx b/simgear/scene/tgdb/VPBTechnique.cxx index 4938e60f..b5d4ccfa 100644 --- a/simgear/scene/tgdb/VPBTechnique.cxx +++ b/simgear/scene/tgdb/VPBTechnique.cxx @@ -61,6 +61,7 @@ VPBTechnique::VPBTechnique() setFilterBias(0); setFilterWidth(0.1); setFilterMatrixAs(GAUSSIAN); + _vegetationConstraintGroup = new osg::Group(); } VPBTechnique::VPBTechnique(const SGReaderWriterOptions* options) @@ -69,6 +70,7 @@ VPBTechnique::VPBTechnique(const SGReaderWriterOptions* options) setFilterWidth(0.1); setFilterMatrixAs(GAUSSIAN); setOptions(options); + _vegetationConstraintGroup = new osg::Group(); } VPBTechnique::VPBTechnique(const VPBTechnique& gt,const osg::CopyOp& copyop): @@ -78,6 +80,7 @@ VPBTechnique::VPBTechnique(const VPBTechnique& gt,const osg::CopyOp& copyop): setFilterWidth(gt._filterWidth); setFilterMatrix(gt._filterMatrix); setOptions(gt._options); + _vegetationConstraintGroup = new osg::Group(); } VPBTechnique::~VPBTechnique() @@ -2283,21 +2286,24 @@ osg::Vec3d VPBTechnique::checkAgainstElevationConstraints(osg::Vec3d origin, osg // intersection with the constraint model. void VPBTechnique::addVegetationConstraint(osg::ref_ptr constraint) { - const std::lock_guard lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope _vegetationConstraintGroup->addChild(constraint.get()); } // Remove a previously added constraint. E.g on model unload. void VPBTechnique::removeVegetationConstraint(osg::ref_ptr constraint) { - const std::lock_guard lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope _vegetationConstraintGroup->removeChild(constraint.get()); } +// Remove all the constraints, which will still be referenced by the terrain tile itself. +void VPBTechnique::clearVegetationConstraints() +{ + _vegetationConstraintGroup->removeChildren(0, _vegetationConstraintGroup->getNumChildren()); +} + // Check a given vertex against any vegetation constraints E.g. to ensure we don't get trees sprouting from roads or runways. bool VPBTechnique::checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex) { - const std::lock_guard lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope osg::ref_ptr intersector; intersector = new osgUtil::LineSegmentIntersector(origin, vertex); osgUtil::IntersectionVisitor visitor(intersector.get()); @@ -2308,9 +2314,7 @@ bool VPBTechnique::checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec void VPBTechnique::clearConstraints() { const std::lock_guard elock(VPBTechnique::_elevationConstraintMutex); // Lock the _elevationConstraintGroup for this scope - const std::lock_guard vlock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope _elevationConstraintGroup = new osg::Group(); - _vegetationConstraintGroup = new osg::Group(); } void VPBTechnique::addLineFeatureList(SGBucket bucket, LineFeatureBinList roadList) diff --git a/simgear/scene/tgdb/VPBTechnique.hxx b/simgear/scene/tgdb/VPBTechnique.hxx index 9e9a2e25..6fa5224b 100644 --- a/simgear/scene/tgdb/VPBTechnique.hxx +++ b/simgear/scene/tgdb/VPBTechnique.hxx @@ -91,16 +91,12 @@ class VPBTechnique : public TerrainTechnique * for all graphics contexts. */ virtual void releaseGLObjects(osg::State* = 0) const; - // Elevation constraints ensure that the terrain mesh is placed underneath objects such as airports + // Elevation constraints ensure that the terrain mesh is placed underneath objects such as airports. + // As airports are generated in a separate loading thread, these are static. static void addElevationConstraint(osg::ref_ptr constraint); static void removeElevationConstraint(osg::ref_ptr constraint); static osg::Vec3d checkAgainstElevationConstraints(osg::Vec3d origin, osg::Vec3d vertex, float vertex_gap); - // Vegetation constraints ensure that trees don't grow in roads - static void addVegetationConstraint(osg::ref_ptr constraint); - static void removeVegetationConstraint(osg::ref_ptr constraint); - static bool checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex); - static void clearConstraints(); // LineFeatures and AreaFeatures are draped over the underlying mesh. @@ -178,6 +174,13 @@ class VPBTechnique : public TerrainTechnique virtual osg::Vec3d getMeshIntersection(BufferData& buffer, Locator* masterLocator, osg::Vec3d pt, osg::Vec3d up); + // Vegetation constraints ensure that trees don't grow in roads. Unlike the elevation constraints, + // we only use these internally and during generation of this particular tile. + virtual void addVegetationConstraint(osg::ref_ptr constraint); + virtual void removeVegetationConstraint(osg::ref_ptr constraint); + virtual bool checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex); + virtual void clearVegetationConstraints(); + OpenThreads::Mutex _writeBufferMutex; osg::ref_ptr _currentBufferData; osg::ref_ptr _newBufferData; @@ -189,12 +192,11 @@ class VPBTechnique : public TerrainTechnique osg::Matrix3 _filterMatrix; osg::ref_ptr _filterMatrixUniform; osg::ref_ptr _options; + osg::ref_ptr _vegetationConstraintGroup; inline static osg::ref_ptr _elevationConstraintGroup = new osg::Group(); inline static std::mutex _elevationConstraintMutex; // protects the _elevationConstraintGroup; - inline static osg::ref_ptr _vegetationConstraintGroup = new osg::Group(); - inline static std::mutex _vegetationConstraintMutex; // protects the _vegetationConstraintGroup; typedef std::pair BucketLineFeatureBinList; typedef std::pair BucketAreaFeatureBinList;