Replaced Widget::GraphicsSubgraph with GraphicsSubgraphMap to allow finer control of when the rendering subgraphs are done.
This commit is contained in:
@@ -1703,6 +1703,10 @@ public:
|
||||
#define REMOVE_SERIALIZER(PROP) \
|
||||
wrapper->markSerializerAsRemoved( #PROP );
|
||||
|
||||
#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 )
|
||||
|
||||
#define ADD_METHOD_OBJECT( METHODNAME, METHODOBJECTCLASS ) wrapper->addMethodObject(METHODNAME, new METHODOBJECTCLASS());
|
||||
|
||||
#define ADD_METHOD(METHODNAME) \
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
void setDisabledTextColor(const osg::Vec4& color) { _disabledTextColor = color; }
|
||||
const osg::Vec4& getDisabledTextColor() const { return _disabledTextColor; }
|
||||
|
||||
virtual osg::Node* createDepthSetPanel(const osg::BoundingBox& extents);
|
||||
virtual osg::Node* createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour);
|
||||
virtual osg::Node* createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings);
|
||||
virtual osg::Node* createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* textSettings, const std::string& text);
|
||||
|
||||
@@ -42,13 +42,20 @@ public:
|
||||
|
||||
virtual void dirty();
|
||||
|
||||
typedef std::map<int, osg::ref_ptr<osg::Node> > GraphicsSubgraphMap;
|
||||
|
||||
/** Set the subgraph to be used to render the widget.*/
|
||||
void setGraphicsSubgraph(int orderNum, osg::Node* node) { _graphicsSubgraphMap[orderNum] = node; _graphicsInitialized = true; }
|
||||
/** Get the subgraph to be used to render the widget.*/
|
||||
osg::Node* getGraphicsSubgraph(int orderNum) { GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.find(orderNum); return (itr!=_graphicsSubgraphMap.end()) ? itr->second.get() : 0; }
|
||||
/** Get the const subgraph to be used to render the widget.*/
|
||||
const osg::Node* getGraphicsSubgraph(int orderNum) const { GraphicsSubgraphMap::const_iterator itr = _graphicsSubgraphMap.find(orderNum); return (itr!=_graphicsSubgraphMap.end()) ? itr->second.get() : 0; }
|
||||
|
||||
void setGraphicsSubgraphMap(const GraphicsSubgraphMap& gsm) { _graphicsSubgraphMap = gsm; _graphicsInitialized = true; }
|
||||
GraphicsSubgraphMap& getGraphicsSubgraphMap() { return _graphicsSubgraphMap; }
|
||||
const GraphicsSubgraphMap& getGraphicsSubgraphMap() const { return _graphicsSubgraphMap; }
|
||||
|
||||
|
||||
/** Set the subgraph to be used to erndering the widget.*/
|
||||
void setGraphicsSubgraph(osg::Node* node) { _graphicsSubgraph = node; _graphicsInitialized = true; }
|
||||
/** Get the subgraph to be used to erndering the widget.*/
|
||||
osg::Node* getGraphicsSubgraph() { return _graphicsSubgraph.get(); }
|
||||
/** Get the const subgraph to be used to erndering the widget.*/
|
||||
const osg::Node* getGraphicsSubgraph() const { return _graphicsSubgraph.get(); }
|
||||
|
||||
/** createGraphics entry method, calls either callback object named "createGraphics" or the createGraphicsImplementation() method.*/
|
||||
virtual void createGraphics();
|
||||
@@ -136,7 +143,7 @@ protected:
|
||||
bool _hasEventFocus;
|
||||
bool _graphicsInitialized;
|
||||
|
||||
osg::ref_ptr<osg::Node> _graphicsSubgraph;
|
||||
GraphicsSubgraphMap _graphicsSubgraphMap;
|
||||
|
||||
osg::BoundingBoxf _extents;
|
||||
|
||||
|
||||
@@ -126,5 +126,5 @@ void ComboBox::createGraphicsImplementation()
|
||||
_switch->setSingleChildOn(_currentItem);
|
||||
|
||||
style->setupClipStateSet(_extents, getOrCreateStateSet());
|
||||
setGraphicsSubgraph(_switch.get());
|
||||
setGraphicsSubgraph(0, _switch.get());
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -83,5 +83,5 @@ void LineEdit::createGraphicsImplementation()
|
||||
|
||||
style->setupClipStateSet(_extents, getOrCreateStateSet());
|
||||
|
||||
setGraphicsSubgraph(_textDrawable.get());
|
||||
setGraphicsSubgraph(0, _textDrawable.get());
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void PushButton::createGraphicsImplementation()
|
||||
|
||||
style->setupClipStateSet(_extents, getOrCreateStateSet());
|
||||
|
||||
setGraphicsSubgraph(group.get());
|
||||
setGraphicsSubgraph(0, group.get());
|
||||
}
|
||||
|
||||
void PushButton::pressedImplementation()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user