From 1fcb91900a57308d31bf382be2849a3a8a9cf69f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 28 May 2014 10:06:14 +0000 Subject: [PATCH] Replaced Widget::GraphicsSubgraph with GraphicsSubgraphMap to allow finer control of when the rendering subgraphs are done. --- include/osgDB/Serializer | 4 ++ include/osgUI/Style | 1 + include/osgUI/Widget | 21 ++++++---- src/osgUI/ComboBox.cpp | 2 +- src/osgUI/Dialog.cpp | 6 ++- src/osgUI/Label.cpp | 2 +- src/osgUI/LineEdit.cpp | 2 +- src/osgUI/Popup.cpp | 7 +++- src/osgUI/PushButton.cpp | 2 +- src/osgUI/Style.cpp | 21 ++++++++++ src/osgUI/Widget.cpp | 40 +++++++++++++------ .../serializers/osg/TransferFunction1D.cpp | 4 -- src/osgWrappers/serializers/osgUI/Widget.cpp | 2 +- 13 files changed, 83 insertions(+), 31 deletions(-) diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index 43b6e4d79..c79ce2cc2 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -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) \ diff --git a/include/osgUI/Style b/include/osgUI/Style index f165024d4..0229125b6 100644 --- a/include/osgUI/Style +++ b/include/osgUI/Style @@ -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); diff --git a/include/osgUI/Widget b/include/osgUI/Widget index 03e9803e6..3ccd6a815 100644 --- a/include/osgUI/Widget +++ b/include/osgUI/Widget @@ -42,13 +42,20 @@ public: virtual void dirty(); + typedef std::map > 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 _graphicsSubgraph; + GraphicsSubgraphMap _graphicsSubgraphMap; osg::BoundingBoxf _extents; diff --git a/src/osgUI/ComboBox.cpp b/src/osgUI/ComboBox.cpp index 60cfe8224..92dbefb5c 100644 --- a/src/osgUI/ComboBox.cpp +++ b/src/osgUI/ComboBox.cpp @@ -126,5 +126,5 @@ void ComboBox::createGraphicsImplementation() _switch->setSingleChildOn(_currentItem); style->setupClipStateSet(_extents, getOrCreateStateSet()); - setGraphicsSubgraph(_switch.get()); + setGraphicsSubgraph(0, _switch.get()); } diff --git a/src/osgUI/Dialog.cpp b/src/osgUI/Dialog.cpp index c939479f7..b1de85d18 100644 --- a/src/osgUI/Dialog.cpp +++ b/src/osgUI/Dialog.cpp @@ -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)); } diff --git a/src/osgUI/Label.cpp b/src/osgUI/Label.cpp index afafae91b..aa1b3649b 100644 --- a/src/osgUI/Label.cpp +++ b/src/osgUI/Label.cpp @@ -38,5 +38,5 @@ void Label::createGraphicsImplementation() _textDrawable = dynamic_cast(node.get()); style->setupClipStateSet(_extents, getOrCreateStateSet()); - setGraphicsSubgraph(node.get()); + setGraphicsSubgraph(0, node.get()); } diff --git a/src/osgUI/LineEdit.cpp b/src/osgUI/LineEdit.cpp index a66462db2..018528df2 100644 --- a/src/osgUI/LineEdit.cpp +++ b/src/osgUI/LineEdit.cpp @@ -83,5 +83,5 @@ void LineEdit::createGraphicsImplementation() style->setupClipStateSet(_extents, getOrCreateStateSet()); - setGraphicsSubgraph(_textDrawable.get()); + setGraphicsSubgraph(0, _textDrawable.get()); } diff --git a/src/osgUI/Popup.cpp b/src/osgUI/Popup.cpp index 436faa3d7..cf6af1604 100644 --- a/src/osgUI/Popup.cpp +++ b/src/osgUI/Popup.cpp @@ -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)); } diff --git a/src/osgUI/PushButton.cpp b/src/osgUI/PushButton.cpp index 9264abd46..2b100654a 100644 --- a/src/osgUI/PushButton.cpp +++ b/src/osgUI/PushButton.cpp @@ -97,7 +97,7 @@ void PushButton::createGraphicsImplementation() style->setupClipStateSet(_extents, getOrCreateStateSet()); - setGraphicsSubgraph(group.get()); + setGraphicsSubgraph(0, group.get()); } void PushButton::pressedImplementation() diff --git a/src/osgUI/Style.cpp b/src/osgUI/Style.cpp index 647e27e19..aca41863f 100644 --- a/src/osgUI/Style.cpp +++ b/src/osgUI/Style.cpp @@ -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 geometry = new osg::Geometry; + + osg::ref_ptr 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 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; diff --git a/src/osgUI/Widget.cpp b/src/osgUI/Widget.cpp index 86986bbf8..af37e0540 100644 --- a/src/osgUI/Widget.cpp +++ b/src/osgUI/Widget.cpp @@ -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); } diff --git a/src/osgWrappers/serializers/osg/TransferFunction1D.cpp b/src/osgWrappers/serializers/osg/TransferFunction1D.cpp index 75b3c8c23..cb774fb9d 100644 --- a/src/osgWrappers/serializers/osg/TransferFunction1D.cpp +++ b/src/osgWrappers/serializers/osg/TransferFunction1D.cpp @@ -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, diff --git a/src/osgWrappers/serializers/osgUI/Widget.cpp b/src/osgWrappers/serializers/osgUI/Widget.cpp index c6ef66daf..91d3b5c29 100644 --- a/src/osgWrappers/serializers/osgUI/Widget.cpp +++ b/src/osgWrappers/serializers/osgUI/Widget.cpp @@ -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());