Improved the handling a releaseGLObjects() and add setThreadSafeRefUnref and resizeGLObjectsBuffers methods

This commit is contained in:
Robert Osfield 2007-01-08 20:40:29 +00:00
parent 77f0f74920
commit 709d2fa435
4 changed files with 68 additions and 6 deletions

View File

@ -142,6 +142,12 @@ public:
FontImplementation* getImplementation();
const FontImplementation* getImplementation() const;
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */

View File

@ -434,6 +434,13 @@ public:
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(osg::PrimitiveFunctor& pf) const;
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */

View File

@ -254,16 +254,48 @@ Font::Glyph* Font::getGlyph(unsigned int charcode)
else return 0;
}
void Font::releaseGLObjects(osg::State* state) const
void Font::setThreadSafeRefUnref(bool threadSafe)
{
Object::setThreadSafeRefUnref(threadSafe);
if (_texenv.valid()) _texenv->setThreadSafeRefUnref(threadSafe);
if (_stateset.valid()) _stateset->setThreadSafeRefUnref(threadSafe);
for(GlyphTextureList::const_iterator itr=_glyphTextureList.begin();
itr!=_glyphTextureList.end();
++itr)
{
(*itr)->releaseGLObjects(state);
(*itr)->setThreadSafeRefUnref(threadSafe);
}
const_cast<Font*>(this)->_glyphTextureList.clear();
const_cast<Font*>(this)->_sizeGlyphMap.clear();
}
void Font::resizeGLObjectBuffers(unsigned int maxSize)
{
if (_stateset.valid()) _stateset->resizeGLObjectBuffers(maxSize);
for(GlyphTextureList::const_iterator itr=_glyphTextureList.begin();
itr!=_glyphTextureList.end();
++itr)
{
(*itr)->resizeGLObjectBuffers(maxSize);
}
}
void Font::releaseGLObjects(osg::State* state) const
{
if (_stateset.valid()) _stateset->releaseGLObjects(state);
for(GlyphTextureList::const_iterator itr=_glyphTextureList.begin();
itr!=_glyphTextureList.end();
++itr)
{
osg::notify(osg::NOTICE)<<" Texture::releaseGLObjects("<<state<<")"<<std::endl;
// (*itr)->releaseGLObjects(state);
(*itr)->releaseGLObjects(state);
}
// const_cast<Font*>(this)->_glyphTextureList.clear();
// const_cast<Font*>(this)->_sizeGlyphMap.clear();
}
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
@ -610,7 +642,7 @@ void Font::GlyphTexture::apply(osg::State& state) const
}
else
{
//std::cout << "no need to subload "<<std::endl;
osg::notify(osg::NOTICE) << "no need to subload "<<std::endl;
}

View File

@ -1639,6 +1639,24 @@ void Text::accept(osg::PrimitiveFunctor& pf) const
}
void Text::setThreadSafeRefUnref(bool threadSafe)
{
Drawable::setThreadSafeRefUnref(threadSafe);
getActiveFont()->setThreadSafeRefUnref(threadSafe);
}
void Text::resizeGLObjectBuffers(unsigned int maxSize)
{
Drawable::resizeGLObjectBuffers(maxSize);
_autoTransformCache.resize(maxSize);
getActiveFont()->resizeGLObjectBuffers(maxSize);
}
void Text::releaseGLObjects(osg::State* state) const
{
Drawable::releaseGLObjects(state);
@ -1646,7 +1664,6 @@ void Text::releaseGLObjects(osg::State* state) const
}
void Text::setBackdropType(BackdropType type)
{
if (_backdropType==type) return;