Change the DefaultFont so that it's managemed via the ObjectCache to enabl it to be release and cleared in a central manner.
Added call to Registry::releaseGLObjects() to osgViewer/Renderer.cpp to enable automatic clean up of objects in the ObjectCache.
This commit is contained in:
parent
887ecf255c
commit
2716c8a32b
@ -83,7 +83,7 @@ public:
|
||||
|
||||
virtual std::string getFileName() const;
|
||||
|
||||
static osg::ref_ptr<Font>& getDefaultFont();
|
||||
static osg::ref_ptr<Font> getDefaultFont();
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSets;
|
||||
StateSets& getCachedStateSets() { return _statesets; }
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
|
||||
DefaultFont();
|
||||
|
||||
virtual const char* className() const { return "DefaultFont"; }
|
||||
|
||||
virtual std::string getFileName() const { return ""; }
|
||||
|
||||
virtual bool supportsMultipleFontResolutions() const { return false; }
|
||||
|
@ -36,13 +36,23 @@
|
||||
using namespace osgText;
|
||||
using namespace std;
|
||||
|
||||
osg::ref_ptr<Font>& Font::getDefaultFont()
|
||||
osg::ref_ptr<Font> Font::getDefaultFont()
|
||||
{
|
||||
static OpenThreads::Mutex s_DefaultFontMutex;
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_DefaultFontMutex);
|
||||
|
||||
static osg::ref_ptr<Font> s_defaultFont = new DefaultFont;
|
||||
return s_defaultFont;
|
||||
osg::ref_ptr<osg::Object> object = osgDB::Registry::instance()->getObjectCache()->getFromObjectCache("DefaultFont");
|
||||
osg::ref_ptr<osgText::Font> font = dynamic_cast<osgText::Font*>(object.get());
|
||||
if (!font)
|
||||
{
|
||||
font = new DefaultFont;
|
||||
osgDB::Registry::instance()->getObjectCache()->addEntryToObjectCache("DefaultFont", font.get());
|
||||
return font;
|
||||
}
|
||||
else
|
||||
{
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
static OpenThreads::ReentrantMutex& getFontFileMutex()
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <osgDB/DatabasePager>
|
||||
#include <osgDB/ImagePager>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
@ -960,6 +961,8 @@ void Renderer::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
|
||||
void Renderer::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
osgDB::Registry::instance()->releaseGLObjects(state);
|
||||
|
||||
if (_sceneView[0].valid()) _sceneView[0]->releaseGLObjects(state);
|
||||
if (_sceneView[1].valid()) _sceneView[1]->releaseGLObjects(state);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user