Added setDataVariance(DYNAMIC) to stats text labels that are dyanmically updated.

This commit is contained in:
Robert Osfield 2017-03-09 17:01:33 +00:00
parent 7868909f43
commit 96760970ed
5 changed files with 42 additions and 13 deletions

View File

@ -55,7 +55,7 @@
#endif #endif
#define INLINE_DRAWABLE_DRAW // #define INLINE_DRAWABLE_DRAW
namespace osg { namespace osg {

View File

@ -22,7 +22,7 @@
namespace osgText { namespace osgText {
//#define NEW_APPROACH #define NEW_APPROACH
class OSGTEXT_EXPORT TextBase : public osg::Drawable class OSGTEXT_EXPORT TextBase : public osg::Drawable
{ {

View File

@ -280,7 +280,27 @@ void Text::computeGlyphRepresentation()
if (!_texcoords) { _texcoords = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX); _texcoords->setBufferObject(_vbo.get()); } if (!_texcoords) { _texcoords = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX); _texcoords->setBufferObject(_vbo.get()); }
else _texcoords->clear(); else _texcoords->clear();
#if 0
_textureGlyphQuadMap.clear(); _textureGlyphQuadMap.clear();
#else
for(TextureGlyphQuadMap::iterator itr = _textureGlyphQuadMap.begin();
itr != _textureGlyphQuadMap.end();
++itr)
{
GlyphQuads& glyphquads = itr->second;
glyphquads._glyphs.clear();
for(Primitives::iterator pitr = glyphquads._primitives.begin();
pitr != glyphquads._primitives.end();
++pitr)
{
(*pitr)->clear();
(*pitr)->dirty();
}
}
#endif
_lineCount = 0; _lineCount = 0;
if (_text.empty()) if (_text.empty())
@ -1113,11 +1133,11 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
state.Normal(_normal.x(), _normal.y(), _normal.z()); state.Normal(_normal.x(), _normal.y(), _normal.z());
#ifdef NEW_APPROACH #ifdef NEW_APPROACH
bool usingVertexArrayObjects = usingVertexBufferObjects && state.useVertexArrayObject(_useVertexArrayObject);
VertexArrayState* vas = state.getCurrentVertexArrayState(); VertexArrayState* vas = state.getCurrentVertexArrayState();
bool usingVertexArrayObjects = usingVertexBufferObjects && state.useVertexArrayObject(_useVertexArrayObject);
bool requiresSetArrays = !usingVertexBufferObjects || !usingVertexArrayObjects || vas->getRequiresSetArrays();
bool requiresSetArrays = !usingVertexArrayObjects || vas->getRequiresSetArrays();
if (requiresSetArrays) if (requiresSetArrays)
{ {
vas->lazyDisablingOfVertexAttributes(); vas->lazyDisablingOfVertexAttributes();
@ -1233,11 +1253,11 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
} }
#ifdef NEW_APPROACH #ifdef NEW_APPROACH
if (!usingVertexArrayObjects && !requiresSetArrays) if (!usingVertexArrayObjects)
{ {
// unbind the VBO's if any are used. // unbind the VBO's if any are used.
state.unbindVertexBufferObject(); vas->unbindVertexBufferObject();
state.unbindElementBufferObject(); vas->unbindElementBufferObject();
} }
#else #else
// unbind the VBO's if any are used. // unbind the VBO's if any are used.
@ -1378,20 +1398,17 @@ void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, co
if (coords.valid() && !coords->empty()) if (coords.valid() && !coords->empty())
{ {
#ifdef NEW_APPROACH #ifdef NEW_APPROACH
bool usingVertexArrayObjects = usingVertexBufferObjects && state.useVertexArrayObject(_useVertexArrayObject);
VertexArrayState* vas = state.getCurrentVertexArrayState(); VertexArrayState* vas = state.getCurrentVertexArrayState();
bool usingVertexArrayObjects = usingVertexBufferObjects && state.useVertexArrayObject(_useVertexArrayObject);
bool requiresSetArrays = !usingVertexBufferObjects || !usingVertexArrayObjects || vas->getRequiresSetArrays();
if(_colorGradientMode == SOLID) if(_colorGradientMode == SOLID)
{ {
OSG_NOTICE<<" Text::drawForegroundText() vas->disableColorArray(state);"<<std::endl;
vas->disableColorArray(state); vas->disableColorArray(state);
state.Color(colorMultiplier.r()*_color.r(),colorMultiplier.g()*_color.g(),colorMultiplier.b()*_color.b(),colorMultiplier.a()*_color.a()); state.Color(colorMultiplier.r()*_color.r(),colorMultiplier.g()*_color.g(),colorMultiplier.b()*_color.b(),colorMultiplier.a()*_color.a());
} }
else else
{ {
bool requiresSetArrays = !usingVertexArrayObjects || vas->getRequiresSetArrays();
OSG_NOTICE<<" Text::drawForegroundText() "<<requiresSetArrays<<"vas->setColorArray(state, colors.get())"<<std::endl;
if (requiresSetArrays) if (requiresSetArrays)
{ {
vas->setColorArray(state, colors.get()); vas->setColorArray(state, colors.get());

View File

@ -128,7 +128,7 @@ osg::VertexArrayState* TextBase::createVertexArrayState(osg::RenderInfo& renderI
} }
else else
{ {
// OSG_NOTICE<<" Setup VertexArrayState to without using VAO "<<vas<<std::endl; OSG_NOTICE<<" Setup VertexArrayState to without using VAO "<<vas<<std::endl;
} }
return vas; return vas;

View File

@ -1184,6 +1184,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
frameRateValue->setCharacterSize(_characterSize); frameRateValue->setCharacterSize(_characterSize);
frameRateValue->setPosition(pos); frameRateValue->setPosition(pos);
frameRateValue->setText("0.0"); frameRateValue->setText("0.0");
frameRateValue->setDataVariance(osg::Object::DYNAMIC);
frameRateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getViewerStats(),"Frame rate",-1, true, 1.0)); frameRateValue->setDrawCallback(new AveragedValueTextDrawCallback(viewer->getViewerStats(),"Frame rate",-1, true, 1.0));
@ -1382,6 +1383,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
averageValue->setCharacterSize(_characterSize); averageValue->setCharacterSize(_characterSize);
averageValue->setPosition(pos); averageValue->setPosition(pos);
averageValue->setText("1000"); averageValue->setText("1000");
averageValue->setDataVariance(osg::Object::DYNAMIC);
pos.x() = averageValue->getBoundingBox().xMax() + 2.0f*_characterSize; pos.x() = averageValue->getBoundingBox().xMax() + 2.0f*_characterSize;
@ -1405,6 +1407,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
minValue->setCharacterSize(_characterSize); minValue->setCharacterSize(_characterSize);
minValue->setPosition(pos); minValue->setPosition(pos);
minValue->setText("1000"); minValue->setText("1000");
minValue->setDataVariance(osg::Object::DYNAMIC);
pos.x() = minValue->getBoundingBox().xMax() + 2.0f*_characterSize; pos.x() = minValue->getBoundingBox().xMax() + 2.0f*_characterSize;
@ -1427,6 +1430,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
maxValue->setCharacterSize(_characterSize); maxValue->setCharacterSize(_characterSize);
maxValue->setPosition(pos); maxValue->setPosition(pos);
maxValue->setText("1000"); maxValue->setText("1000");
maxValue->setDataVariance(osg::Object::DYNAMIC);
pos.x() = maxValue->getBoundingBox().xMax(); pos.x() = maxValue->getBoundingBox().xMax();
@ -1449,6 +1454,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
requestList->setCharacterSize(_characterSize); requestList->setCharacterSize(_characterSize);
requestList->setPosition(pos); requestList->setPosition(pos);
requestList->setText("0"); requestList->setText("0");
requestList->setDataVariance(osg::Object::DYNAMIC);
pos.x() = requestList->getBoundingBox().xMax() + 2.0f*_characterSize;; pos.x() = requestList->getBoundingBox().xMax() + 2.0f*_characterSize;;
@ -1471,6 +1478,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
compileList->setCharacterSize(_characterSize); compileList->setCharacterSize(_characterSize);
compileList->setPosition(pos); compileList->setPosition(pos);
compileList->setText("0"); compileList->setText("0");
compileList->setDataVariance(osg::Object::DYNAMIC);
pos.x() = maxLabel->getBoundingBox().xMax(); pos.x() = maxLabel->getBoundingBox().xMax();
@ -1555,6 +1564,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
camStatsText->setCharacterSize(_characterSize); camStatsText->setCharacterSize(_characterSize);
camStatsText->setPosition(pos); camStatsText->setPosition(pos);
camStatsText->setText(""); camStatsText->setText("");
camStatsText->setDataVariance(osg::Object::DYNAMIC);
camStatsText->setDrawCallback(new CameraSceneStatsTextDrawCallback(*citr, cameraCounter)); camStatsText->setDrawCallback(new CameraSceneStatsTextDrawCallback(*citr, cameraCounter));
// Move camera block to the right // Move camera block to the right
@ -1628,6 +1638,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase* viewer)
text->setFont(_font); text->setFont(_font);
text->setCharacterSize(_characterSize); text->setCharacterSize(_characterSize);
text->setPosition(pos); text->setPosition(pos);
text->setDataVariance(osg::Object::DYNAMIC);
text->setDrawCallback(new ViewSceneStatsTextDrawCallback(*it, viewCounter)); text->setDrawCallback(new ViewSceneStatsTextDrawCallback(*it, viewCounter));
pos.x() += 10 * _characterSize + 2 * backgroundMargin + backgroundSpacing; pos.x() += 10 * _characterSize + 2 * backgroundMargin + backgroundSpacing;
@ -1661,6 +1672,7 @@ void StatsHandler::createTimeStatsLine(const std::string& lineLabel,
value->setCharacterSize(_characterSize); value->setCharacterSize(_characterSize);
value->setPosition(pos); value->setPosition(pos);
value->setText("0.0"); value->setText("0.0");
value->setDataVariance(osg::Object::DYNAMIC);
if (!timeTakenName.empty()) if (!timeTakenName.empty())
{ {