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 2e68db5b55
commit 6455159757
2 changed files with 32 additions and 14 deletions

View File

@ -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.**/
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.*/

View File

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