Hi Cory,

For the purpose of state sorting and lazy state updating it's
important to shader StateSet - which is why all Text that share the
same Font will share the same StateSet.

Perhaps setting the StateSet of the Geode that sits above the Text
drawable will answer your needs.

Robert.

On Thu, Oct 8, 2009 at 4:27 PM, Cory Riddell <[email protected]> wrote:
> My app uses the same font everywhere. So, I have a global method to return a
> reference to a single Font instance:
> osg::ref_ptr<osgText::Font> getArialFont() {
>   static osg::ref_ptr<osgText::Font> s_font =
> osgText::readFontFile("fonts/arial.ttf");
>   return s_font;
> }
>
> When I pass it to Text::setFont(), the Text instance's StateSet gets set to
> the Font's StateSet. Every Text instance ends up sharing the same StateSet
> and changes to it end up acting globally. Here's the code from
> osgText::Text:
>
> void Text::setFont(osg::ref_ptr<Font> font)
> {
>   if (_font==font) return;
>
>   osg::StateSet* previousFontStateSet = _font.valid() ? _font->getStateSet()
> : DefaultFont::instance()->getStateSet();
>   osg::StateSet* newFontStateSet = font.valid() ? font->getStateSet() :
> DefaultFont::instance()->getStateSet();
>
>   if (getStateSet() == previousFontStateSet)
>   {
>     setStateSet( newFontStateSet );
>   }
>
>   _font = font;
>
>   computeGlyphRepresentation();
> }
>
> If I later set some text to be depth sorted and other text to not be depth
> sorted, then whomever makes the setting last, wins.
>
> I have two questions.
> 1) Why would you want the Font's StateSet to become the Text's StateSet?
> Text and Font are very different concepts.
> 2) Ideally, StateSet would have COW semantics, but it doesn't and it
> wouldn't be trivial to add. Would it be reasonable to pass a copy of
> newFontStateSet to Text::setStateSet()?
>
> Cory
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to