Implement releaseGLObjects for cached resources

0.6.1
scrawl 7 years ago
parent 86ae2ae395
commit 4fba157d3b

@ -221,8 +221,8 @@ SceneWidget::SceneWidget(std::shared_ptr<Resource::ResourceSystem> resourceSyste
SceneWidget::~SceneWidget()
{
// Since we're holding on to the scene templates past the existence of this graphics context, we'll need to manually release the created objects
mResourceSystem->getSceneManager()->releaseGLObjects(mView->getCamera()->getGraphicsContext()->getState());
// Since we're holding on to the resources past the existence of this graphics context, we'll need to manually release the created objects
mResourceSystem->releaseGLObjects(mView->getCamera()->getGraphicsContext()->getState());
}
void SceneWidget::setLighting(Lighting *lighting)

@ -73,8 +73,6 @@ namespace MWGui
std::vector<std::string> mSplashScreens;
// TODO: add releaseGLObjects() for mTexture
osg::ref_ptr<osg::Texture2D> mTexture;
std::unique_ptr<MyGUI::ITexture> mGuiTexture;

@ -38,4 +38,9 @@ namespace Resource
return mVFS;
}
void ResourceManager::releaseGLObjects(osg::State *state)
{
mCache->releaseGLObjects(state);
}
}

@ -11,6 +11,7 @@ namespace VFS
namespace osg
{
class Stats;
class State;
}
namespace Resource
@ -38,6 +39,8 @@ namespace Resource
virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) const {}
virtual void releaseGLObjects(osg::State* state);
protected:
const VFS::Manager* mVFS;
osg::ref_ptr<Resource::ObjectCache> mCache;

@ -97,4 +97,10 @@ namespace Resource
(*it)->reportStats(frameNumber, stats);
}
void ResourceSystem::releaseGLObjects(osg::State *state)
{
for (std::vector<ResourceManager*>::const_iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
(*it)->releaseGLObjects(state);
}
}

@ -12,6 +12,7 @@ namespace VFS
namespace osg
{
class Stats;
class State;
}
namespace Resource
@ -60,6 +61,9 @@ namespace Resource
void reportStats(unsigned int frameNumber, osg::Stats* stats) const;
/// Call releaseGLObjects for each resource manager.
void releaseGLObjects(osg::State* state);
private:
std::unique_ptr<SceneManager> mSceneManager;
std::unique_ptr<ImageManager> mImageManager;

@ -628,6 +628,11 @@ namespace Resource
{
mCache->releaseGLObjects(state);
mInstanceCache->releaseGLObjects(state);
mShaderManager->releaseGLObjects(state);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex);
mSharedStateManager->releaseGLObjects(state);
}
void SceneManager::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)

@ -116,7 +116,7 @@ namespace Resource
/// Manually release created OpenGL objects for the given graphics context. This may be required
/// in cases where multiple contexts are used over the lifetime of the application.
void releaseGLObjects(osg::State* state);
void releaseGLObjects(osg::State* state) override;
/// Set up an IncrementalCompileOperation for background compiling of loaded scenes.
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico);

@ -158,4 +158,13 @@ namespace Shader
return found->second;
}
void ShaderManager::releaseGLObjects(osg::State *state)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
for (auto shader : mShaders)
shader.second->releaseGLObjects(state);
for (auto program : mPrograms)
program.second->releaseGLObjects(state);
}
}

@ -32,6 +32,7 @@ namespace Shader
osg::ref_ptr<osg::Program> getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader);
void releaseGLObjects(osg::State* state);
private:
std::string mPath;

@ -243,4 +243,18 @@ namespace Terrain
}
}
void BufferCache::releaseGLObjects(osg::State *state)
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mIndexBufferMutex);
for (auto indexbuffer : mIndexBufferMap)
indexbuffer.second->releaseGLObjects(state);
}
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mUvBufferMutex);
for (auto uvbuffer : mUvBufferMap)
uvbuffer.second->releaseGLObjects(state);
}
}
}

@ -24,7 +24,7 @@ namespace Terrain
void clearCache();
// TODO: add releaseGLObjects() for our vertex/element buffer objects
void releaseGLObjects(osg::State* state);
private:
// Index buffers are shared across terrain batches where possible. There is one index buffer for each

@ -62,6 +62,12 @@ void ChunkManager::clearCache()
mBufferCache.clearCache();
}
void ChunkManager::releaseGLObjects(osg::State *state)
{
ResourceManager::releaseGLObjects(state);
mBufferCache.releaseGLObjects(state);
}
void ChunkManager::setCullingActive(bool active)
{
mCullingActive = active;

@ -36,6 +36,8 @@ namespace Terrain
virtual void clearCache();
void releaseGLObjects(osg::State* state) override;
void setCullingActive(bool active);
private:

Loading…
Cancel
Save