Improvements to the handling of multiple graphics contexts. Still needs alot

of work, but at least it isn't crashes in trivial cases right now.
This commit is contained in:
Robert Osfield
2003-01-20 20:28:28 +00:00
parent 6e778f2436
commit 4de63e72c6
4 changed files with 48 additions and 11 deletions

View File

@@ -124,6 +124,9 @@ class OSGTEXT_EXPORT Text : public osg::Drawable
void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; }
const EncodedText* getEncodedText() const { return _encodedText.get(); }
/// override the compile to set up the alignment etc.
virtual void compile(osg::State& state) const;
protected:
enum FontType

View File

@@ -109,7 +109,9 @@ int FTFont::Descender() const
float FTFont::Advance( const wchar_t* string)
{
// all are the same, a bit a hack
FTGlyphContainer* glyphList=_contextGlyphList[0];
FTGlyphContainer* glyphList=getValidGlypContainer();
if (!glyphList) return 1.0f;
const wchar_t* c = string; // wchar_t IS unsigned?
float width = 0;
@@ -128,7 +130,10 @@ float FTFont::Advance( const wchar_t* string)
float FTFont::Advance( const char* string)
{
// all are the same, a bit a hack
FTGlyphContainer* glyphList=_contextGlyphList[0];
FTGlyphContainer* glyphList=getValidGlypContainer();
if (!glyphList) return 1.0f;
const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
float width = 0;
@@ -145,7 +150,10 @@ float FTFont::Advance( std::vector<int>::const_iterator first,
std::vector<int>::const_iterator last)
{
// all are the same, a bit a hack
FTGlyphContainer* glyphList=_contextGlyphList[0];
FTGlyphContainer* glyphList=getValidGlypContainer();
if (!glyphList) return 1.0f;
float width = 0;
for (std::vector<int>::const_iterator c = first;

View File

@@ -180,12 +180,7 @@ class FTGL_EXPORT FTFont
*/
FTSize charSize;
/**
* An object that holds a list of glyphs
*/
// mrn@changes
// FTGlyphContainer* glyphList;
/**
* The number of glyphs in this font
*/
@@ -207,6 +202,17 @@ class FTGL_EXPORT FTFont
// mrn@changes
typedef std::vector<FTGlyphContainer*> GlyphContextContainer;
GlyphContextContainer _contextGlyphList;
FTGlyphContainer* getValidGlypContainer()
{
for(GlyphContextContainer::iterator itr=_contextGlyphList.begin();
itr!=_contextGlyphList.end();
++itr)
{
if ((*itr)!=0) return *itr;
}
return 0;
}
private:

View File

@@ -128,7 +128,7 @@ setDefaults()
_initAlignment=false;
_useDisplayList=false;
_useDisplayList=false;
_encodedText = new EncodedText();
}
@@ -191,6 +191,24 @@ void Text::accept(PrimitiveFunctor& functor) const
functor.drawArrays( GL_QUADS, 0, 4);
}
void Text::compile(State& state) const
{
// ahhhh, this is bit doddy, the draw is potentially
// modifying the text object, this isn't thread safe.
Text* this_non_const = const_cast<Text*>(this);
if(!_font->isCreated() || !(this_non_const->_font->getFont()->Created(state.getContextID())))
{
this_non_const->_font->create(state);
this_non_const->dirtyBound();
}
if(!_initAlignment)
{
this_non_const->initAlignment();
}
}
void Text::drawImplementation(State& state) const
{
if(!_init)
@@ -200,14 +218,16 @@ void Text::drawImplementation(State& state) const
// modifying the text object, this isn't thread safe.
Text* this_non_const = const_cast<Text*>(this);
if(!_font->isCreated())
if(!_font->isCreated() || !(this_non_const->_font->getFont()->Created(state.getContextID())))
{
this_non_const->_font->create(state);
this_non_const->dirtyBound();
}
if(!_initAlignment)
{
this_non_const->initAlignment();
}
// we must disable all the vertex arrays to prevent any state
// propagating into text.