Restructured the clean up of arrays/primitives and GL objects

This commit is contained in:
Robert Osfield 2019-01-04 08:08:07 +00:00
parent b7947b13f3
commit fd47b84bd7
2 changed files with 35 additions and 18 deletions

View File

@ -256,8 +256,28 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
Drawable::~Drawable() Drawable::~Drawable()
{ {
_stateset = 0; // clean up display lists if assigned, for the display lists size we can't use glGLObjectSizeHint() as it's a virtual function, so have to default to a 0 size hint.
Drawable::releaseGLObjects(); #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
for(unsigned int i=0;i<_globjList.size();++i)
{
if (_globjList[i] != 0)
{
Drawable::deleteDisplayList(i,_globjList[i], 0); // we don't know getGLObjectSizeHint()
_globjList[i] = 0;
}
}
#endif
// clean up VertexArrayState
for(unsigned int i=0; i<_vertexArrayStateList.size(); ++i)
{
VertexArrayState* vas = _vertexArrayStateList[i].get();
if (vas)
{
vas->release();
_vertexArrayStateList[i] = 0;
}
}
} }
osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const
@ -319,6 +339,7 @@ void Drawable::releaseGLObjects(State* state) const
// current OpenGL context. // current OpenGL context.
unsigned int contextID = state->getContextID(); unsigned int contextID = state->getContextID();
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
if (_useDisplayList) if (_useDisplayList)
{ {
// get the globj for the current contextID. // get the globj for the current contextID.
@ -331,6 +352,7 @@ void Drawable::releaseGLObjects(State* state) const
globj = 0; globj = 0;
} }
} }
#endif
VertexArrayState* vas = contextID <_vertexArrayStateList.size() ? _vertexArrayStateList[contextID].get() : 0; VertexArrayState* vas = contextID <_vertexArrayStateList.size() ? _vertexArrayStateList[contextID].get() : 0;
if (vas) if (vas)

View File

@ -82,22 +82,17 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
Geometry::~Geometry() Geometry::~Geometry()
{ {
_stateset = 0; // clean up display lists if assigned, and use the GLObjectSizeHint() while prior to it being invalidated by the automatic clean up of arrays that will invalidate the getGLObjectSizeHint() value.
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
#if 1 for(unsigned int i=0;i<_globjList.size();++i)
// use the destructors to automatically handle GL object clean up when the array/primtives ref count goes to 0 {
_primitives.clear(); if (_globjList[i] != 0)
_vertexArray = 0; {
_normalArray = 0; Drawable::deleteDisplayList(i,_globjList[i], getGLObjectSizeHint());
_colorArray = 0; _globjList[i] = 0;
_secondaryColorArray = 0; }
_fogCoordArray = 0; }
_texCoordList.clear(); #endif
_vertexAttribList.clear();
#else
// original clean up that cleans up GL objects regardless of any sharing of arrays/primitives
Geometry::releaseGLObjects();
#endif
} }
#define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0) #define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0)