Improved handling of clean up of osg::Program/osg::Shader on closing of a graphis context.
This commit is contained in:
parent
0c9ab51e09
commit
93a2c3d011
@ -132,7 +132,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
|
||||
void requestLink();
|
||||
void linkProgram();
|
||||
void validateProgram();
|
||||
bool validateProgram();
|
||||
bool needsLink() const {return _needsLink;}
|
||||
bool isLinked() const {return _isLinked;}
|
||||
bool getInfoLog( std::string& infoLog ) const;
|
||||
|
@ -81,6 +81,11 @@ class OSG_EXPORT Shader : public osg::Object
|
||||
/** Get the Shader type as a descriptive string. */
|
||||
const char* getTypename() const;
|
||||
|
||||
/** release OpenGL objects in specified graphics context if State
|
||||
object is passed, otherwise release OpenGL objects for all graphics context if
|
||||
State object pointer NULL.*/
|
||||
void releaseGLObjects(osg::State* state=0) const;
|
||||
|
||||
/** Mark our PCSs as needing recompilation.
|
||||
* Also mark Programs that depend on us as needing relink */
|
||||
void dirtyShader();
|
||||
|
@ -1999,9 +1999,19 @@ void Program::dirtyProgram()
|
||||
}
|
||||
|
||||
|
||||
void Program::releaseGLObjects(osg::State* /*state*/) const
|
||||
void Program::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
// TODO
|
||||
for( unsigned int i=0; i < _shaderList.size(); ++i )
|
||||
{
|
||||
if (_shaderList[i].valid()) _shaderList[i]->releaseGLObjects(state);
|
||||
}
|
||||
|
||||
if (!state) _pcpList.setAllElementsTo(0);
|
||||
else
|
||||
{
|
||||
unsigned int contextID = state->getContextID();
|
||||
_pcpList[contextID] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2274,13 +2284,13 @@ void Program::PerContextProgram::linkProgram()
|
||||
osg::notify(osg::INFO) << std::endl;
|
||||
}
|
||||
|
||||
void Program::PerContextProgram::validateProgram()
|
||||
bool Program::PerContextProgram::validateProgram()
|
||||
{
|
||||
GLint validated = GL_FALSE;
|
||||
_extensions->glValidateProgram( _glProgramHandle );
|
||||
_extensions->glGetProgramiv( _glProgramHandle, GL_VALIDATE_STATUS, &validated );
|
||||
if( validated == GL_TRUE)
|
||||
return;
|
||||
return true;
|
||||
|
||||
osg::notify(osg::INFO)
|
||||
<< "glValidateProgram FAILED \"" << _program->getName() << "\""
|
||||
@ -2293,6 +2303,8 @@ void Program::PerContextProgram::validateProgram()
|
||||
osg::notify(osg::INFO) << "infolog:\n" << infoLog << std::endl;
|
||||
|
||||
osg::notify(osg::INFO) << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Program::PerContextProgram::getInfoLog( std::string& infoLog ) const
|
||||
|
@ -201,6 +201,16 @@ const char* Shader::getTypename() const
|
||||
}
|
||||
|
||||
|
||||
void Shader::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
if (!state) _pcsList.setAllElementsTo(0);
|
||||
else
|
||||
{
|
||||
unsigned int contextID = state->getContextID();
|
||||
_pcsList[contextID] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::compileShader( unsigned int contextID ) const
|
||||
{
|
||||
PerContextShader* pcs = getPCS( contextID );
|
||||
|
@ -736,6 +736,9 @@ void SceneView::releaseAllGLObjects()
|
||||
if (!_camera) return;
|
||||
|
||||
_camera->releaseGLObjects(_state.get());
|
||||
|
||||
// we need to reset State as it keeps handles to Program objects.
|
||||
if (_state.valid()) _state->reset();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user