Replaced Widget::GraphicsSubgraph with GraphicsSubgraphMap to allow finer control of when the rendering subgraphs are done.

This commit is contained in:
Robert Osfield
2014-05-28 10:06:14 +00:00
parent 6af9edf33b
commit 1fcb91900a
13 changed files with 83 additions and 31 deletions

View File

@@ -126,5 +126,5 @@ void ComboBox::createGraphicsImplementation()
_switch->setSingleChildOn(_currentItem);
style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(_switch.get());
setGraphicsSubgraph(0, _switch.get());
}

View File

@@ -87,5 +87,9 @@ void Dialog::createGraphicsImplementation()
style->setupDialogStateSet(getOrCreateStateSet());
style->setupClipStateSet(dialogWithTileExtents, getOrCreateStateSet());
setGraphicsSubgraph(_group.get());
// render before the subgraph
setGraphicsSubgraph(-1, _group.get());
// render after the subgraph
setGraphicsSubgraph(1, style->createDepthSetPanel(dialogWithTileExtents));
}

View File

@@ -38,5 +38,5 @@ void Label::createGraphicsImplementation()
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(node.get());
setGraphicsSubgraph(0, node.get());
}

View File

@@ -83,5 +83,5 @@ void LineEdit::createGraphicsImplementation()
style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(_textDrawable.get());
setGraphicsSubgraph(0, _textDrawable.get());
}

View File

@@ -77,5 +77,10 @@ void Popup::createGraphicsImplementation()
style->setupDialogStateSet(getOrCreateStateSet());
style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(_transform.get());
// render before the subgraph
setGraphicsSubgraph(-1, _transform.get());
// render after the subgraph
setGraphicsSubgraph(1, style->createDepthSetPanel(_extents));
}

View File

@@ -97,7 +97,7 @@ void PushButton::createGraphicsImplementation()
style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(group.get());
setGraphicsSubgraph(0, group.get());
}
void PushButton::pressedImplementation()

View File

@@ -76,6 +76,27 @@ osg::Node* Style::createPanel(const osg::BoundingBox& extents, const osg::Vec4&
return geometry.release();
}
osg::Node* Style::createDepthSetPanel(const osg::BoundingBox& extents)
{
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
geometry->setVertexArray(vertices.get());
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMin(), extents.zMin()) );
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMax(), extents.zMin()) );
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMin(), extents.zMin()) );
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMax(), extents.zMin()) );
geometry->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4) );
osg::ref_ptr<osg::StateSet> stateset = geometry->getOrCreateStateSet();
stateset->setAttributeAndModes( new osg::Depth(osg::Depth::LESS,0.0, 1.0,true), osg::StateAttribute::ON);
stateset->setAttributeAndModes( new osg::ColorMask(false, false, false, false));
return geometry.release();
}
osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings)
{
return 0;

View File

@@ -225,20 +225,22 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
osg::Group::traverse(nv);
}
}
else if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR ||
nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
else if (_visible || (nv.getVisitorType()!=osg::NodeVisitor::UPDATE_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR))
{
if (_visible)
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
while(itr!= _graphicsSubgraphMap.end() && itr->first<=0)
{
if (_graphicsSubgraph.valid()) _graphicsSubgraph->accept(nv);
osg::Group::traverse(nv);
itr->second->accept(nv);
++itr;
}
Group::traverse(nv);
while(itr!= _graphicsSubgraphMap.end())
{
itr->second->accept(nv);
++itr;
}
}
else
{
if (_graphicsSubgraph.valid()) _graphicsSubgraph->accept(nv);
osg::Group::traverse(nv);
}
}
@@ -308,13 +310,25 @@ osg::BoundingSphere Widget::computeBound() const
void Widget::resizeGLObjectBuffers(unsigned int maxSize)
{
if (_graphicsSubgraph.valid()) _graphicsSubgraph->resizeGLObjectBuffers(maxSize);
for(GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
itr != _graphicsSubgraphMap.end();
++itr)
{
itr->second->resizeGLObjectBuffers(maxSize);
}
Group::resizeGLObjectBuffers(maxSize);
}
void Widget::releaseGLObjects(osg::State* state) const
{
if (_graphicsSubgraph.valid()) _graphicsSubgraph->releaseGLObjects(state);
for(GraphicsSubgraphMap::const_iterator itr = _graphicsSubgraphMap.begin();
itr != _graphicsSubgraphMap.end();
++itr)
{
itr->second->releaseGLObjects(state);
}
Group::releaseGLObjects(state);
}

View File

@@ -38,10 +38,6 @@ static bool writeColorMap( osgDB::OutputStream& os, const osg::TransferFunction1
}
#endif
#define ADD_MAP_SERIALIZER(PROP, TYPE, KEYTYPE, ELEMENTTYPE) \
wrapper->addSerializer( new osgDB::MapSerializer< MyClass, TYPE >( \
#PROP, &MyClass::get##PROP, &MyClass::get##PROP, &MyClass::set##PROP, KEYTYPE, ELEMENTTYPE), osgDB::BaseSerializer::RW_MAP )
REGISTER_OBJECT_WRAPPER( TransferFunction1D,
new osg::TransferFunction1D,

View File

@@ -69,7 +69,7 @@ REGISTER_OBJECT_WRAPPER( Widget,
ADD_BOOL_SERIALIZER(HasEventFocus, false);
ADD_OBJECT_SERIALIZER( GraphicsSubgraph, osg::Node, NULL );
ADD_MAP_SERIALIZER(GraphicsSubgraphMap, osgUI::Widget::GraphicsSubgraphMap, osgDB::BaseSerializer::RW_INT, osgDB::BaseSerializer::RW_OBJECT);
ADD_BOUNDINGBOXF_SERIALIZER(Extents, osg::BoundingBoxf());