Added calling of releaseGLObjects() and resizeGLObjects() to the Camera DrawCallback's to enable the draw callbacks to clean up their own GL objects.

This commit is contained in:
Robert Osfield 2019-01-19 16:16:53 +00:00
parent 664d597e20
commit 68e4341cb4
2 changed files with 32 additions and 14 deletions

View File

@ -599,12 +599,12 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
Callback(org, copyop) {} Callback(org, copyop) {}
META_Object(osg, DrawCallback); META_Object(osg, DrawCallback);
/** Functor method called by rendering thread to recursively launch operator() on _nestedcallback **/ /** Functor method called by rendering thread to recursively launch operator() on _nestedcallback **/
inline void run(osg::RenderInfo& renderInfo) const inline void run(osg::RenderInfo& renderInfo) const
{ {
operator () (renderInfo); operator () (renderInfo);
if (_nestedCallback.valid()) if (_nestedCallback.valid())
((const DrawCallback*)_nestedCallback.get())->run(renderInfo); ((const DrawCallback*)_nestedCallback.get())->run(renderInfo);
} }
@ -614,6 +614,23 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Functor method, provided for backwards compatibility, called by operator() (osg::RenderInfo& renderInfo) method.**/ /** Functor method, provided for backwards compatibility, called by operator() (osg::RenderInfo& renderInfo) method.**/
virtual void operator () (const osg::Camera& /*camera*/) const {} virtual void operator () (const osg::Camera& /*camera*/) const {}
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize)
{
if (_nestedCallback.valid())
_nestedCallback->resizeGLObjectBuffers(maxSize);
}
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state = 0) const
{
if (_nestedCallback.valid())
_nestedCallback->releaseGLObjects(state);
}
}; };
/** Set the initial draw callback for custom operations to be done before the drawing of the camera's subgraph and pre render stages.*/ /** Set the initial draw callback for custom operations to be done before the drawing of the camera's subgraph and pre render stages.*/

View File

@ -330,25 +330,26 @@ void Camera::detach(BufferComponent buffer)
void Camera::resizeGLObjectBuffers(unsigned int maxSize) void Camera::resizeGLObjectBuffers(unsigned int maxSize)
{ {
if (_renderingCache.valid()) if (_renderer.valid()) _renderer->resizeGLObjectBuffers(maxSize);
{ if (_renderingCache.valid()) _renderingCache->resizeGLObjectBuffers(maxSize);
const_cast<Camera*>(this)->_renderingCache->resizeGLObjectBuffers(maxSize);
} if (_initialDrawCallback.valid()) _initialDrawCallback->resizeGLObjectBuffers(maxSize);
if (_preDrawCallback.valid()) _preDrawCallback->resizeGLObjectBuffers(maxSize);
if (_postDrawCallback.valid()) _postDrawCallback->resizeGLObjectBuffers(maxSize);
if (_finalDrawCallback.valid()) _finalDrawCallback->resizeGLObjectBuffers(maxSize);
Transform::resizeGLObjectBuffers(maxSize); Transform::resizeGLObjectBuffers(maxSize);
} }
void Camera::releaseGLObjects(osg::State* state) const void Camera::releaseGLObjects(osg::State* state) const
{ {
if (_renderer.valid()) if (_renderer.valid()) _renderer->releaseGLObjects(state);
{ if (_renderingCache.valid()) _renderingCache->releaseGLObjects(state);
_renderer->releaseGLObjects(state);
}
if (_renderingCache.valid()) if (_initialDrawCallback.valid()) _initialDrawCallback->releaseGLObjects(state);
{ if (_preDrawCallback.valid()) _preDrawCallback->releaseGLObjects(state);
_renderingCache->releaseGLObjects(state); if (_postDrawCallback.valid()) _postDrawCallback->releaseGLObjects(state);
} if (_finalDrawCallback.valid()) _finalDrawCallback->releaseGLObjects(state);
Transform::releaseGLObjects(state); Transform::releaseGLObjects(state);
} }