To solve creations with multi-threaded creation of text, added mutex to Font, and use of this mutex in Text, and added mutex to the reading

of fonts.
This commit is contained in:
Robert Osfield 2007-08-31 20:16:02 +00:00
parent 86e998f64c
commit 5ae1eb711a
2 changed files with 11 additions and 0 deletions

View File

@ -26,6 +26,8 @@
#include <osgDB/ReaderWriter> #include <osgDB/ReaderWriter>
#include <osgText/Export> #include <osgText/Export>
#include <OpenThreads/Mutex>
namespace osgText { namespace osgText {
class Font; class Font;
@ -159,6 +161,11 @@ public:
* for all graphics contexts. */ * for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state=0) const; virtual void releaseGLObjects(osg::State* state=0) const;
typedef OpenThreads::Mutex FontMutex;
/** Get the mutex that enables the serialization of calls to this font.*/
FontMutex& getSerializeFontCallsMutex() const { return _serializeFontCallsMutex; }
protected: protected:
virtual ~Font(); virtual ~Font();
@ -172,6 +179,7 @@ protected:
typedef std::pair< unsigned int, unsigned int > SizePair; typedef std::pair< unsigned int, unsigned int > SizePair;
typedef std::map< SizePair, GlyphMap > SizeGlyphMap; typedef std::map< SizePair, GlyphMap > SizeGlyphMap;
mutable FontMutex _serializeFontCallsMutex;
osg::ref_ptr<osg::TexEnv> _texenv; osg::ref_ptr<osg::TexEnv> _texenv;
osg::ref_ptr<osg::StateSet> _stateset; osg::ref_ptr<osg::StateSet> _stateset;

View File

@ -448,6 +448,7 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite
return lastChar; return lastChar;
} }
void Text::computeGlyphRepresentation() void Text::computeGlyphRepresentation()
{ {
Font* activefont = getActiveFont(); Font* activefont = getActiveFont();
@ -462,6 +463,8 @@ void Text::computeGlyphRepresentation()
computePositions(); //to reset the origin computePositions(); //to reset the origin
return; return;
} }
OpenThreads::ScopedLock<Font::FontMutex> lock(activefont->getSerializeFontCallsMutex());
// initialize bounding box, it will be expanded during glyph position calculation // initialize bounding box, it will be expanded during glyph position calculation
_textBB.init(); _textBB.init();