diff --git a/include/osgText/Font b/include/osgText/Font index a32fffe1e..8474a6c1c 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -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. */ diff --git a/include/osgText/Text b/include/osgText/Text index 2c3e754b9..6f37b36bf 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -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. */ diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index ee718af3a..268d7abe7 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -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(this)->_glyphTextureList.clear(); - const_cast(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("<releaseGLObjects(state); + (*itr)->releaseGLObjects(state); + } + + // const_cast(this)->_glyphTextureList.clear(); + // const_cast(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 "<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;