From 5d84c10c8f85e1f56160c33628e28948ed4ce52c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Mar 2003 16:12:00 +0000 Subject: [PATCH] Changed the ownership of Glyph's so that GlyphTexture's own a reference to Glyph's as well as Font's so keeping the Font valid even after the Font itself has been desctructed. --- include/osgText/Font | 19 ++++++++++--------- src/osgProducer/OsgCameraGroup.cpp | 2 +- src/osgText/Font.cpp | 14 ++++++++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/osgText/Font b/include/osgText/Font index 1636f1c1b..aabb44166 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -117,10 +117,11 @@ public: int _partUsedX; int _partUsedY; - typedef std::vector GlyphList; - typedef osg::buffered_object GlyphBuffer; + typedef std::vector< osg::ref_ptr > GlyphRefList; + typedef std::vector< const Glyph* > GlyphPtrList; + typedef osg::buffered_object< GlyphPtrList > GlyphBuffer; - GlyphList _glyphs; + GlyphRefList _glyphs; mutable GlyphBuffer _glyphsToSubload; }; @@ -151,11 +152,11 @@ public: void setTexture(GlyphTexture* texture) { _texture = texture; } - GlyphTexture* getTexture() { return _texture.get(); } - const GlyphTexture* getTexture() const { return _texture.get(); } + GlyphTexture* getTexture() { return _texture; } + const GlyphTexture* getTexture() const { return _texture; } - osg::StateSet* getStateSet() { return _texture.valid()?_texture->getStateSet():0; } - const osg::StateSet* getStateSet() const { return _texture.valid()?_texture->getStateSet():0; } + osg::StateSet* getStateSet() { return _texture?_texture->getStateSet():0; } + const osg::StateSet* getStateSet() const { return _texture?_texture->getStateSet():0; } void setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; } int getTexturePositionX() const { return _texturePosX; } @@ -167,7 +168,7 @@ public: void setMaxTexCoord(const osg::Vec2& coord) { _maxTexCoord=coord; } const osg::Vec2& getMaxTexCoord() const { return _maxTexCoord; } - void subload(); + void subload() const; protected: @@ -180,7 +181,7 @@ public: osg::Vec2 _verticalBearing; float _verticalAdvance; - osg::ref_ptr _texture; + GlyphTexture* _texture; int _texturePosX; int _texturePosY; osg::Vec2 _minTexCoord; diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index b4af57e7b..139f45bcb 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -169,7 +169,7 @@ void OsgCameraGroup::setFusionDistance( osgUtil::SceneView::FusionDistanceMode m void OsgCameraGroup::advance() { if( !_initialized ) return; - Producer::CameraGroup::advance(); + CameraGroup::advance(); } void OsgCameraGroup::realize( ThreadingModel thread_model) diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index ddec5e9fe..64cfa234f 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -186,7 +186,13 @@ void Font::GlyphTexture::apply(osg::State& state) const // graphics contexts should be set before create text. for(unsigned int i=_glyphsToSubload.size();i<=contextID;++i) { - _glyphsToSubload[i] = _glyphs; + GlyphPtrList& glyphPtrs = _glyphsToSubload[i]; + for(GlyphRefList::const_iterator itr=_glyphs.begin(); + itr!=_glyphs.end(); + ++itr) + { + glyphPtrs.push_back(itr->get()); + } } } @@ -224,12 +230,12 @@ void Font::GlyphTexture::apply(osg::State& state) const //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); // now subload the glyphs that are outstanding for this graphics context. - GlyphList& glyphsWereSubloading = _glyphsToSubload[contextID]; + GlyphPtrList& glyphsWereSubloading = _glyphsToSubload[contextID]; if (!glyphsWereSubloading.empty()) { - for(GlyphList::iterator itr=glyphsWereSubloading.begin(); + for(GlyphPtrList::iterator itr=glyphsWereSubloading.begin(); itr!=glyphsWereSubloading.end(); ++itr) { @@ -248,7 +254,7 @@ void Font::GlyphTexture::apply(osg::State& state) const Font::Glyph::Glyph() {} Font::Glyph::~Glyph() {} -void Font::Glyph::subload() +void Font::Glyph::subload() const { GLenum errorNo = glGetError(); if (errorNo!=GL_NO_ERROR)