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.
This commit is contained in:
Robert Osfield
2003-03-03 16:12:00 +00:00
parent 371d84683f
commit 5d84c10c8f
3 changed files with 21 additions and 14 deletions

View File

@@ -117,10 +117,11 @@ public:
int _partUsedX;
int _partUsedY;
typedef std::vector<Glyph*> GlyphList;
typedef osg::buffered_object<GlyphList> GlyphBuffer;
typedef std::vector< osg::ref_ptr<Glyph> > 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<GlyphTexture> _texture;
GlyphTexture* _texture;
int _texturePosX;
int _texturePosY;
osg::Vec2 _minTexCoord;

View File

@@ -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)

View File

@@ -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)