forked from mirror/openmw-tes3mp
Implement releaseGLObjects for cached resources
This commit is contained in:
parent
86ae2ae395
commit
4fba157d3b
14 changed files with 59 additions and 6 deletions
|
@ -221,8 +221,8 @@ SceneWidget::SceneWidget(std::shared_ptr<Resource::ResourceSystem> resourceSyste
|
||||||
|
|
||||||
SceneWidget::~SceneWidget()
|
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
|
// 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->getSceneManager()->releaseGLObjects(mView->getCamera()->getGraphicsContext()->getState());
|
mResourceSystem->releaseGLObjects(mView->getCamera()->getGraphicsContext()->getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneWidget::setLighting(Lighting *lighting)
|
void SceneWidget::setLighting(Lighting *lighting)
|
||||||
|
|
|
@ -73,8 +73,6 @@ namespace MWGui
|
||||||
|
|
||||||
std::vector<std::string> mSplashScreens;
|
std::vector<std::string> mSplashScreens;
|
||||||
|
|
||||||
// TODO: add releaseGLObjects() for mTexture
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||||
std::unique_ptr<MyGUI::ITexture> mGuiTexture;
|
std::unique_ptr<MyGUI::ITexture> mGuiTexture;
|
||||||
|
|
||||||
|
|
|
@ -38,4 +38,9 @@ namespace Resource
|
||||||
return mVFS;
|
return mVFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceManager::releaseGLObjects(osg::State *state)
|
||||||
|
{
|
||||||
|
mCache->releaseGLObjects(state);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace VFS
|
||||||
namespace osg
|
namespace osg
|
||||||
{
|
{
|
||||||
class Stats;
|
class Stats;
|
||||||
|
class State;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Resource
|
namespace Resource
|
||||||
|
@ -38,6 +39,8 @@ namespace Resource
|
||||||
|
|
||||||
virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) const {}
|
virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) const {}
|
||||||
|
|
||||||
|
virtual void releaseGLObjects(osg::State* state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const VFS::Manager* mVFS;
|
const VFS::Manager* mVFS;
|
||||||
osg::ref_ptr<Resource::ObjectCache> mCache;
|
osg::ref_ptr<Resource::ObjectCache> mCache;
|
||||||
|
|
|
@ -97,4 +97,10 @@ namespace Resource
|
||||||
(*it)->reportStats(frameNumber, stats);
|
(*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
|
namespace osg
|
||||||
{
|
{
|
||||||
class Stats;
|
class Stats;
|
||||||
|
class State;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Resource
|
namespace Resource
|
||||||
|
@ -60,6 +61,9 @@ namespace Resource
|
||||||
|
|
||||||
void reportStats(unsigned int frameNumber, osg::Stats* stats) const;
|
void reportStats(unsigned int frameNumber, osg::Stats* stats) const;
|
||||||
|
|
||||||
|
/// Call releaseGLObjects for each resource manager.
|
||||||
|
void releaseGLObjects(osg::State* state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<SceneManager> mSceneManager;
|
std::unique_ptr<SceneManager> mSceneManager;
|
||||||
std::unique_ptr<ImageManager> mImageManager;
|
std::unique_ptr<ImageManager> mImageManager;
|
||||||
|
|
|
@ -628,6 +628,11 @@ namespace Resource
|
||||||
{
|
{
|
||||||
mCache->releaseGLObjects(state);
|
mCache->releaseGLObjects(state);
|
||||||
mInstanceCache->releaseGLObjects(state);
|
mInstanceCache->releaseGLObjects(state);
|
||||||
|
|
||||||
|
mShaderManager->releaseGLObjects(state);
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex);
|
||||||
|
mSharedStateManager->releaseGLObjects(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneManager::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)
|
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
|
/// 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.
|
/// 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.
|
/// Set up an IncrementalCompileOperation for background compiling of loaded scenes.
|
||||||
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico);
|
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico);
|
||||||
|
|
|
@ -158,4 +158,13 @@ namespace Shader
|
||||||
return found->second;
|
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);
|
osg::ref_ptr<osg::Program> getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader);
|
||||||
|
|
||||||
|
void releaseGLObjects(osg::State* state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mPath;
|
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();
|
void clearCache();
|
||||||
|
|
||||||
// TODO: add releaseGLObjects() for our vertex/element buffer objects
|
void releaseGLObjects(osg::State* state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Index buffers are shared across terrain batches where possible. There is one index buffer for each
|
// 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();
|
mBufferCache.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChunkManager::releaseGLObjects(osg::State *state)
|
||||||
|
{
|
||||||
|
ResourceManager::releaseGLObjects(state);
|
||||||
|
mBufferCache.releaseGLObjects(state);
|
||||||
|
}
|
||||||
|
|
||||||
void ChunkManager::setCullingActive(bool active)
|
void ChunkManager::setCullingActive(bool active)
|
||||||
{
|
{
|
||||||
mCullingActive = active;
|
mCullingActive = active;
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace Terrain
|
||||||
|
|
||||||
virtual void clearCache();
|
virtual void clearCache();
|
||||||
|
|
||||||
|
void releaseGLObjects(osg::State* state) override;
|
||||||
|
|
||||||
void setCullingActive(bool active);
|
void setCullingActive(bool active);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue