diff --git a/examples/osgforest/osgforest.cpp b/examples/osgforest/osgforest.cpp index 6c7ae9a28..5f569de66 100644 --- a/examples/osgforest/osgforest.cpp +++ b/examples/osgforest/osgforest.cpp @@ -803,6 +803,18 @@ class ShaderGeometry : public osg::Drawable typedef std::vector PositionSizeList; + virtual void resizeGLObjectBuffers(unsigned int maxSize) + { + osg::Drawable::resizeGLObjectBuffers(maxSize); + if (_geometry) _geometry->resizeGLObjectBuffers(maxSize); + } + + virtual void releaseGLObjects(osg::State* state) const + { + osg::Drawable::releaseGLObjects(state); + if (_geometry) _geometry->releaseGLObjects(state); + } + virtual void drawImplementation(osg::RenderInfo& renderInfo) const { for(PositionSizeList::const_iterator itr = _trees.begin(); diff --git a/include/osgFX/Effect b/include/osgFX/Effect index 205e2e852..14b085c38 100644 --- a/include/osgFX/Effect +++ b/include/osgFX/Effect @@ -119,6 +119,9 @@ namespace osgFX /** default traversal */ inline void inherited_traverse(osg::NodeVisitor& nv); + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(osg::State* state = 0) const; + protected: virtual ~Effect(); Effect &operator=(const Effect &) { return *this; } diff --git a/include/osgParticle/PrecipitationEffect b/include/osgParticle/PrecipitationEffect index 1f713f4ab..f7b89008d 100644 --- a/include/osgParticle/PrecipitationEffect +++ b/include/osgParticle/PrecipitationEffect @@ -37,8 +37,10 @@ namespace osgParticle virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj) != 0; } virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } } - virtual void traverse(osg::NodeVisitor& nv); + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(osg::State* state = 0) const; + virtual void traverse(osg::NodeVisitor& nv); /** Set all the parameters to create an rain effect of specified intensity.*/ void rain(float intensity); @@ -117,6 +119,9 @@ namespace osgParticle void setNumberOfVertices(unsigned int numVertices) { _numberOfVertices = numVertices; } unsigned int getNumberOfVertices() const { return _numberOfVertices; } + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(osg::State* state) const; + virtual void drawImplementation(osg::RenderInfo& renderInfo) const; struct Cell @@ -174,7 +179,7 @@ namespace osgParticle protected: - virtual ~PrecipitationDrawable() {} + virtual ~PrecipitationDrawable(); bool _requiresPreviousMatrix; diff --git a/include/osgSim/SphereSegment b/include/osgSim/SphereSegment index c9fae8c34..08fb38f38 100644 --- a/include/osgSim/SphereSegment +++ b/include/osgSim/SphereSegment @@ -240,6 +240,10 @@ public: /** recompute the primitives rendering meshes/lines thtat represent the sphere segment.*/ void updatePrimitives(); + + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(osg::State* state = 0) const; + virtual osg::BoundingSphere computeBound() const; private: diff --git a/src/osg/OcclusionQueryNode.cpp b/src/osg/OcclusionQueryNode.cpp index d4c86c483..4f9a2788c 100644 --- a/src/osg/OcclusionQueryNode.cpp +++ b/src/osg/OcclusionQueryNode.cpp @@ -385,6 +385,8 @@ QueryGeometry::getNumPixels( const osg::Camera* cam ) void QueryGeometry::releaseGLObjects( osg::State* state ) const { + Geometry::releaseGLObjects(state); + if (!state) { // delete all query IDs for all contexts. diff --git a/src/osgFX/Effect.cpp b/src/osgFX/Effect.cpp index 9192320dd..474825d12 100644 --- a/src/osgFX/Effect.cpp +++ b/src/osgFX/Effect.cpp @@ -135,6 +135,20 @@ void Effect::traverse(osg::NodeVisitor& nv) // wow, we're finished! :) } +void Effect::resizeGLObjectBuffers(unsigned int maxSize) +{ + Group::resizeGLObjectBuffers(maxSize); + if (_dummy_for_validation) _dummy_for_validation->resizeGLObjectBuffers(maxSize); +} + +void Effect::releaseGLObjects(osg::State* state) const +{ + Group::releaseGLObjects(state); + if (_dummy_for_validation) _dummy_for_validation->releaseGLObjects(state); +} + + + void Effect::build_dummy_node() { _dummy_for_validation = new osg::Geode; diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 9a96f761b..d453904d2 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -659,6 +659,8 @@ osg::BoundingBox osgParticle::ParticleSystem::computeBoundingBox() const void osgParticle::ParticleSystem::resizeGLObjectBuffers(unsigned int maxSize) { + Drawable::resizeGLObjectBuffers(maxSize); + _bufferedArrayData.resize(maxSize); for(unsigned int i=0; i<_bufferedArrayData.size(); ++i) { @@ -668,6 +670,8 @@ void osgParticle::ParticleSystem::resizeGLObjectBuffers(unsigned int maxSize) void osgParticle::ParticleSystem::releaseGLObjects(osg::State* state) const { + Drawable::releaseGLObjects(state); + if (state) { _bufferedArrayData[state->getContextID()].releaseGLObjects(state); diff --git a/src/osgParticle/PrecipitationEffect.cpp b/src/osgParticle/PrecipitationEffect.cpp index d710c2e12..dee77ad31 100644 --- a/src/osgParticle/PrecipitationEffect.cpp +++ b/src/osgParticle/PrecipitationEffect.cpp @@ -121,22 +121,64 @@ void PrecipitationEffect::snow(float intensity) void PrecipitationEffect::compileGLObjects(osg::RenderInfo& renderInfo) const { - if (_quadGeometry.valid()) - { - _quadGeometry->compileGLObjects(renderInfo); - if (_quadGeometry->getStateSet()) _quadGeometry->getStateSet()->compileGLObjects(*renderInfo.getState()); - } + if (_quadGeometry.valid()) _quadGeometry->compileGLObjects(renderInfo); + if (_lineGeometry.valid()) _lineGeometry->compileGLObjects(renderInfo); + if (_pointGeometry.valid()) _pointGeometry->compileGLObjects(renderInfo); - if (_lineGeometry.valid()) - { - _lineGeometry->compileGLObjects(renderInfo); - if (_lineGeometry->getStateSet()) _lineGeometry->getStateSet()->compileGLObjects(*renderInfo.getState()); - } + if (_quadStateSet.valid()) _quadStateSet->compileGLObjects(*renderInfo.getState()); + if (_lineStateSet.valid()) _lineStateSet->compileGLObjects(*renderInfo.getState()); + if (_pointStateSet.valid()) _pointStateSet->compileGLObjects(*renderInfo.getState()); - if (_pointGeometry.valid()) + for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin(); + itr != _viewDrawableMap.end(); + ++itr) { - _pointGeometry->compileGLObjects(renderInfo); - if (_pointGeometry->getStateSet()) _pointGeometry->getStateSet()->compileGLObjects(*renderInfo.getState()); + const PrecipitationDrawableSet& pds = itr->second; + if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->compileGLObjects(renderInfo); + if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->compileGLObjects(renderInfo); + if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->compileGLObjects(renderInfo); + } +} + +void PrecipitationEffect::resizeGLObjectBuffers(unsigned int maxSize) +{ + if (_quadGeometry.valid()) _quadGeometry->resizeGLObjectBuffers(maxSize); + if (_lineGeometry.valid()) _lineGeometry->resizeGLObjectBuffers(maxSize); + if (_pointGeometry.valid()) _pointGeometry->resizeGLObjectBuffers(maxSize); + + if (_quadStateSet.valid()) _quadStateSet->resizeGLObjectBuffers(maxSize); + if (_lineStateSet.valid()) _lineStateSet->resizeGLObjectBuffers(maxSize); + if (_pointStateSet.valid()) _pointStateSet->resizeGLObjectBuffers(maxSize); + + for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin(); + itr != _viewDrawableMap.end(); + ++itr) + { + const PrecipitationDrawableSet& pds = itr->second; + if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->resizeGLObjectBuffers(maxSize); + if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->resizeGLObjectBuffers(maxSize); + if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->resizeGLObjectBuffers(maxSize); + } +} + +void PrecipitationEffect::releaseGLObjects(osg::State* state) const +{ + if (_quadGeometry.valid()) _quadGeometry->releaseGLObjects(state); + if (_lineGeometry.valid()) _lineGeometry->releaseGLObjects(state); + if (_pointGeometry.valid()) _pointGeometry->releaseGLObjects(state); + + if (_quadStateSet.valid()) _quadStateSet->releaseGLObjects(state); + if (_lineStateSet.valid()) _lineStateSet->releaseGLObjects(state); + if (_pointStateSet.valid()) _pointStateSet->releaseGLObjects(state); + + for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin(); + itr != _viewDrawableMap.end(); + ++itr) + { + const PrecipitationDrawableSet& pds = itr->second; + if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->releaseGLObjects(state); + if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->releaseGLObjects(state); + if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->releaseGLObjects(state); } } @@ -829,7 +871,24 @@ PrecipitationEffect::PrecipitationDrawable::PrecipitationDrawable(const Precipit { } +PrecipitationEffect::PrecipitationDrawable::~PrecipitationDrawable() +{ + OSG_NOTICE<<"PrecipitationEffect::~PrecipitationDrawable() "<resizeGLObjectBuffers(maxSize); +} + +void PrecipitationEffect::PrecipitationDrawable::releaseGLObjects(osg::State* state) const +{ + Drawable::releaseGLObjects(state); + + if (_geometry) _geometry->releaseGLObjects(state); +} void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::RenderInfo& renderInfo) const { diff --git a/src/osgSim/LightPointDrawable.cpp b/src/osgSim/LightPointDrawable.cpp index 1a6b9f7bc..b97e5461a 100644 --- a/src/osgSim/LightPointDrawable.cpp +++ b/src/osgSim/LightPointDrawable.cpp @@ -54,6 +54,11 @@ LightPointDrawable::LightPointDrawable(const LightPointDrawable& lpd,const osg:: { } +LightPointDrawable::~LightPointDrawable() +{ + OSG_NOTICE<<"LightPointDrawable::~LightPointDrawable()"<resizeGLObjectBuffers(maxSize); + if (_spokesGeometry.valid()) _spokesGeometry->resizeGLObjectBuffers(maxSize); + if (_edgeLineGeometry.valid()) _edgeLineGeometry->resizeGLObjectBuffers(maxSize); + if (_sidesGeometry.valid()) _sidesGeometry->resizeGLObjectBuffers(maxSize); + + if (_litOpaqueState.valid()) _litOpaqueState->resizeGLObjectBuffers(maxSize); + if (_unlitOpaqueState.valid()) _unlitOpaqueState->resizeGLObjectBuffers(maxSize); + if (_litTransparentState.valid()) _litTransparentState->resizeGLObjectBuffers(maxSize); + if (_unlitTransparentState.valid()) _unlitTransparentState->resizeGLObjectBuffers(maxSize); +} + +void SphereSegment::releaseGLObjects(osg::State* state) const +{ + if (_surfaceGeometry.valid()) _surfaceGeometry->releaseGLObjects(state); + if (_spokesGeometry.valid()) _spokesGeometry->releaseGLObjects(state); + if (_edgeLineGeometry.valid()) _edgeLineGeometry->releaseGLObjects(state); + if (_sidesGeometry.valid()) _sidesGeometry->releaseGLObjects(state); + + if (_litOpaqueState.valid()) _litOpaqueState->releaseGLObjects(state); + if (_unlitOpaqueState.valid()) _unlitOpaqueState->releaseGLObjects(state); + if (_litTransparentState.valid()) _litTransparentState->releaseGLObjects(state); + if (_unlitTransparentState.valid()) _unlitTransparentState->releaseGLObjects(state); +} + osg::BoundingSphere SphereSegment::computeBound() const { _bbox.init();