Fixed for crashes on exit associaciated with VAO usage and vairous niche usage cases

This commit is contained in:
Robert Osfield
2019-01-08 19:32:50 +00:00
parent 1c65815f4e
commit f6b64afdfc
13 changed files with 161 additions and 7 deletions

View File

@@ -25,7 +25,6 @@
namespace osg {
// forward declare
class State;
class UserDataContainer;
class Node;
class NodeVisitor;

View File

@@ -30,6 +30,7 @@ namespace osg {
class DeleteHandler;
class Observer;
class ObserverSet;
class State;
/** template class to help enforce static initialization order. */
template <typename T, T M()>
@@ -115,7 +116,15 @@ class OSG_EXPORT Referenced
/** Remove Observer that is observing this object.*/
void removeObserver(Observer* observer) const;
public:
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
/** 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 {}
public:
friend class DeleteHandler;

View File

@@ -161,6 +161,9 @@ class OSG_EXPORT View : public virtual osg::Object
void updateSlaves();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
protected :
virtual ~View();

View File

@@ -72,6 +72,16 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
virtual void render(osg::RenderInfo& renderInfo,RenderLeaf* previous);
virtual void resizeGLObjectBuffers(unsigned int maxSize)
{
if (_drawable) _drawable->resizeGLObjectBuffers(maxSize);
}
virtual void releaseGLObjects(osg::State* state=0) const
{
if (_drawable) _drawable->releaseGLObjects(state);
}
/// Allow StateGraph to change the RenderLeaf's _parent.
friend class osgUtil::StateGraph;

View File

@@ -484,6 +484,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
* then need to be deleted in OpenGL by SceneView::flushAllDeleteGLObjects(). */
virtual void releaseAllGLObjects();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
/** Flush all deleted OpenGL objects, such as texture objects, display lists, etc.*/
virtual void flushAllDeletedGLObjects();

View File

@@ -43,8 +43,8 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
public:
typedef std::map< const osg::StateSet*, osg::ref_ptr<StateGraph> > ChildList;
typedef std::vector< osg::ref_ptr<RenderLeaf> > LeafList;
typedef std::map< const osg::StateSet*, osg::ref_ptr<StateGraph> > ChildList;
typedef std::vector< osg::ref_ptr<RenderLeaf> > LeafList;
StateGraph* _parent;
@@ -172,6 +172,42 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
void prune();
void resizeGLObjectBuffers(unsigned int maxSize)
{
for(ChildList::iterator itr = _children.begin();
itr != _children.end();
++itr)
{
(itr->second)->resizeGLObjectBuffers(maxSize);
}
for(LeafList::iterator itr = _leaves.begin();
itr != _leaves.end();
++itr)
{
(*itr)->resizeGLObjectBuffers(maxSize);
}
}
void releaseGLObjects(osg::State* state=0) const
{
if (_stateset) _stateset->releaseGLObjects(state);
for(ChildList::const_iterator itr = _children.begin();
itr != _children.end();
++itr)
{
(itr->second)->releaseGLObjects(state);
}
for(LeafList::const_iterator itr = _leaves.begin();
itr != _leaves.end();
++itr)
{
(*itr)->releaseGLObjects(state);
}
}
inline StateGraph* find_or_insert(const osg::StateSet* stateset)
{
// search for the appropriate state group, return it if found.

View File

@@ -60,6 +60,9 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
virtual void compile();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
void setCompileOnNextDraw(bool flag) { _compileOnNextDraw = flag; }
bool getCompileOnNextDraw() const { return _compileOnNextDraw; }