Enabled the settng/getting of the Text3D's WallStateSet and BackStateSet along with use of these in the rendering implementation

to allow separate colour and other state to be assigned to the front, wall and back faces.
This commit is contained in:
Robert Osfield 2011-03-07 12:33:11 +00:00
parent afecdbb46b
commit 215fca84f7
2 changed files with 136 additions and 88 deletions

View File

@ -23,7 +23,7 @@ namespace osgText {
class OSGTEXT_EXPORT Text3D : public osgText::TextBase
{
public:
public:
/** Reder mode used to render the Text.
* PER_FACE : render all front face with the default StateSet
@ -54,24 +54,28 @@ public:
/** Set the render mode used to render the text. */
void setRenderMode(RenderMode renderMode) { _renderMode = renderMode; computeGlyphRepresentation(); }
// /** Get the wall StateSet */
// osg::StateSet * getWallStateSet() { return _wallStateSet.get(); }
// /** Get or create the wall StateSet */
// osg::StateSet * getOrCreateWallStateSet()
// {
// if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet;
// return _wallStateSet.get();
// }
// /** Set the wall StateSet */
// void setWallStateSet(osg::StateSet * wallStateSet) { _wallStateSet = wallStateSet; }
//
// /** Get the back StateSet */
// osg::StateSet * getBackStateSet() { return _backStateSet.get(); }
// /** Get or create the back StateSet */
// osg::StateSet * getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
// /** Set the back StateSet */
// void setBackStateSet(osg::StateSet * backStateSet) { _backStateSet = backStateSet; }
//
/** Get the wall StateSet */
osg::StateSet* getWallStateSet() { return _wallStateSet.get(); }
/** Get the wall StateSet */
const osg::StateSet* getWallStateSet() const { return _wallStateSet.get(); }
/** Get or create the wall StateSet */
osg::StateSet* getOrCreateWallStateSet()
{
if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet;
return _wallStateSet.get();
}
/** Set the wall StateSet */
void setWallStateSet(osg::StateSet* wallStateSet) { _wallStateSet = wallStateSet; }
/** Get the back StateSet */
osg::StateSet* getBackStateSet() { return _backStateSet.get(); }
/** Get the back StateSet */
osg::StateSet* getBackStateSet() const { return _backStateSet.get(); }
/** Get or create the back StateSet */
osg::StateSet* getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
/** Set the back StateSet */
void setBackStateSet(osg::StateSet* backStateSet) { _backStateSet = backStateSet; }
@ -105,14 +109,14 @@ public:
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state=0) const;
// // make Font a friend to allow it set the _font to 0 if the font is
// // forcefully unloaded.
// // make Font a friend to allow it set the _font to 0 if the font is
// // forcefully unloaded.
friend class Font;
virtual osg::BoundingBox computeBound() const;
protected:
protected:
virtual ~Text3D() {}

View File

@ -584,6 +584,17 @@ void Text3D::renderPerGlyph(osg::State & state) const
{
osg::Matrix original_modelview = state.getModelViewMatrix();
const osg::StateSet* frontStateSet = getStateSet();
const osg::StateSet* wallStateSet = getWallStateSet();
const osg::StateSet* backStateSet = getBackStateSet();
bool applyMainColor = false;
if (wallStateSet==0) wallStateSet = frontStateSet;
else if (wallStateSet->getAttribute(osg::StateAttribute::MATERIAL)!=0) applyMainColor = true;
if (backStateSet==0) backStateSet = frontStateSet;
else if (backStateSet->getAttribute(osg::StateAttribute::MATERIAL)!=0) applyMainColor = true;
// ** for each line, do ...
TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end();
for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine)
@ -605,6 +616,11 @@ void Text3D::renderPerGlyph(osg::State & state) const
state.applyDisablingOfVertexAttributes();
if (frontStateSet!=backStateSet)
{
state.apply(frontStateSet);
if (applyMainColor) state.Color(_color.r(),_color.g(),_color.b(),_color.a());
}
osg::Geometry::PrimitiveSetList & pslFront = it->_glyphGeometry->getFrontPrimitiveSetList();
for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslFront.begin(), end = pslFront.end(); itr!=end; ++itr)
@ -612,6 +628,8 @@ void Text3D::renderPerGlyph(osg::State & state) const
(*itr)->draw(state, false);
}
if (wallStateSet!=frontStateSet) state.apply(wallStateSet);
// ** render the wall face of the glyph
osg::Geometry::PrimitiveSetList & pslWall = it->_glyphGeometry->getWallPrimitiveSetList();
for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslWall.begin(), end=pslWall.end(); itr!=end; ++itr)
@ -619,6 +637,12 @@ void Text3D::renderPerGlyph(osg::State & state) const
(*itr)->draw(state, false);
}
if (backStateSet!=wallStateSet)
{
state.apply(backStateSet);
if (applyMainColor) state.Color(_color.r(),_color.g(),_color.b(),_color.a());
}
osg::Geometry::PrimitiveSetList & pslBack = it->_glyphGeometry->getBackPrimitiveSetList();
for(osg::Geometry::PrimitiveSetList::const_iterator itr=pslBack.begin(), end=pslBack.end(); itr!=end; ++itr)
{
@ -636,6 +660,18 @@ void Text3D::renderPerFace(osg::State & state) const
state.Normal(0.0f,0.0f,1.0f);
#endif
const osg::StateSet* frontStateSet = getStateSet();
const osg::StateSet* wallStateSet = getWallStateSet();
const osg::StateSet* backStateSet = getBackStateSet();
bool applyMainColor = false;
if (wallStateSet==0) wallStateSet = frontStateSet;
else if (wallStateSet->getAttribute(osg::StateAttribute::MATERIAL)!=0) applyMainColor = true;
if (backStateSet==0) backStateSet = frontStateSet;
else if (backStateSet->getAttribute(osg::StateAttribute::MATERIAL)!=0) applyMainColor = true;
TextRenderInfo::const_iterator itLine, endLine = _textRenderInfo.end();
for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine)
{
@ -659,6 +695,7 @@ void Text3D::renderPerFace(osg::State & state) const
}
}
if (wallStateSet!=frontStateSet) state.apply(wallStateSet);
// ** render all wall face of the text
for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine)
@ -687,6 +724,13 @@ void Text3D::renderPerFace(osg::State & state) const
// ** render all back face of the text
state.Normal(0.0f,0.0f,-1.0f);
#endif
if (backStateSet!=wallStateSet)
{
state.apply(backStateSet);
if (applyMainColor) state.Color(_color.r(),_color.g(),_color.b(),_color.a());
}
for (itLine = _textRenderInfo.begin(); itLine!=endLine; ++itLine)
{
// ** for each glyph in the line, do ...