diff --git a/src/Gui/Inventor/So3DAnnotation.cpp b/src/Gui/Inventor/So3DAnnotation.cpp index b28126cf45..50ba2b10ad 100644 --- a/src/Gui/Inventor/So3DAnnotation.cpp +++ b/src/Gui/Inventor/So3DAnnotation.cpp @@ -35,8 +35,41 @@ using namespace Gui; +SO_ELEMENT_SOURCE(SoDelayedAnnotationsElement); + +void SoDelayedAnnotationsElement::init(SoState* state) +{ + SoElement::init(state); +} + +void SoDelayedAnnotationsElement::initClass() +{ + SO_ELEMENT_INIT_CLASS(SoDelayedAnnotationsElement, inherited); + + SO_ENABLE(SoGLRenderAction, SoDelayedAnnotationsElement); +} + +void SoDelayedAnnotationsElement::addDelayedPath(SoState* state, SoPath* path) +{ + auto elt = static_cast(state->getElementNoPush(classStackIndex)); + + elt->paths.append(path); +} + +SoPathList SoDelayedAnnotationsElement::getDelayedPaths(SoState* state) +{ + auto elt = static_cast(state->getElementNoPush(classStackIndex)); + auto copy = elt->paths; + + elt->paths.truncate(0); + + return copy; +} + SO_NODE_SOURCE(So3DAnnotation); +bool So3DAnnotation::render = false; + So3DAnnotation::So3DAnnotation() { SO_NODE_CONSTRUCTOR(So3DAnnotation); @@ -65,25 +98,23 @@ void So3DAnnotation::GLRender(SoGLRenderAction* action) void So3DAnnotation::GLRenderBelowPath(SoGLRenderAction* action) { - if (action->isRenderingDelayedPaths()) { - glClear(GL_DEPTH_BUFFER_BIT); + if (render) { inherited::GLRenderBelowPath(action); } else { SoCacheElement::invalidate(action->getState()); - action->addDelayedPath(action->getCurPath()->copy()); + SoDelayedAnnotationsElement::addDelayedPath(action->getState(), action->getCurPath()->copy()); } } void So3DAnnotation::GLRenderInPath(SoGLRenderAction* action) { - if (action->isRenderingDelayedPaths()) { - glClear(GL_DEPTH_BUFFER_BIT); + if (render) { inherited::GLRenderInPath(action); } else { SoCacheElement::invalidate(action->getState()); - action->addDelayedPath(action->getCurPath()->copy()); + SoDelayedAnnotationsElement::addDelayedPath(action->getState(), action->getCurPath()->copy()); } } diff --git a/src/Gui/Inventor/So3DAnnotation.h b/src/Gui/Inventor/So3DAnnotation.h index 7bd12bc103..700227be01 100644 --- a/src/Gui/Inventor/So3DAnnotation.h +++ b/src/Gui/Inventor/So3DAnnotation.h @@ -24,11 +24,48 @@ #include #include +#include #include namespace Gui { +class GuiExport SoDelayedAnnotationsElement: public SoElement +{ + using inherited = SoElement; + + SO_ELEMENT_HEADER(SoDelayedAnnotationsElement); + +protected: + ~SoDelayedAnnotationsElement() override = default; + + SoDelayedAnnotationsElement& operator=(const SoDelayedAnnotationsElement& other) = default; + SoDelayedAnnotationsElement& operator=(SoDelayedAnnotationsElement&& other) noexcept = default; + +public: + SoDelayedAnnotationsElement(const SoDelayedAnnotationsElement& other) = delete; + SoDelayedAnnotationsElement(SoDelayedAnnotationsElement&& other) noexcept = delete; + + void init(SoState* state) override; + + static void initClass(); + + static void addDelayedPath(SoState* state, SoPath* path); + static SoPathList getDelayedPaths(SoState* state); + + SbBool matches([[maybe_unused]] const SoElement* element) const override + { + return FALSE; + } + + SoElement* copyMatchInfo() const override + { + return nullptr; + } + + SoPathList paths; +}; + /*! @brief 3D Annotation Node - Annotation with depth buffer * * This class is just like SoAnnotation with the difference that it does not disable @@ -39,21 +76,29 @@ namespace Gui */ class GuiExport So3DAnnotation: public SoSeparator { - typedef SoSeparator inherited; + using inherited = SoSeparator; SO_NODE_HEADER(So3DAnnotation); public: - static void initClass(); + static bool render; + So3DAnnotation(); - virtual void GLRender(SoGLRenderAction* action); - virtual void GLRenderBelowPath(SoGLRenderAction* action); - virtual void GLRenderInPath(SoGLRenderAction* action); - virtual void GLRenderOffPath(SoGLRenderAction* action); + So3DAnnotation(const So3DAnnotation& other) = delete; + So3DAnnotation(So3DAnnotation&& other) noexcept = delete; + So3DAnnotation& operator=(const So3DAnnotation& other) = delete; + So3DAnnotation& operator=(So3DAnnotation&& other) noexcept = delete; + + static void initClass(); + + void GLRender(SoGLRenderAction* action) override; + void GLRenderBelowPath(SoGLRenderAction* action) override; + void GLRenderInPath(SoGLRenderAction* action) override; + void GLRenderOffPath(SoGLRenderAction* action) override; protected: - virtual ~So3DAnnotation() = default; + ~So3DAnnotation() override = default; }; } // namespace Gui diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 75db396f83..d762615c11 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -147,6 +147,7 @@ void Gui::SoFCDB::init() SoFCPathAnnotation ::initClass(); SoMouseWheelEvent ::initClass(); So3DAnnotation ::initClass(); + SoDelayedAnnotationsElement ::initClass(); PropertyItem ::init(); PropertySeparatorItem ::init(); diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index b7bfaab27e..ff57cede1b 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -130,6 +130,8 @@ #include "NavigationAnimation.h" #include "Utilities.h" +#include + FC_LOG_LEVEL_INIT("3DViewer", true, true) @@ -2387,6 +2389,11 @@ void View3DInventorViewer::renderScene() try { // Render normal scenegraph. inherited::actualRedraw(); + + So3DAnnotation::render = true; + glClear(GL_DEPTH_BUFFER_BIT); + glra->apply(SoDelayedAnnotationsElement::getDelayedPaths(state)); + So3DAnnotation::render = false; } catch (const Base::MemoryException&) { // FIXME: If this exception appears then the background and camera position get broken somehow. (Werner 2006-02-01) diff --git a/src/Gui/ViewProviderDatum.cpp b/src/Gui/ViewProviderDatum.cpp index c4714c9c6e..00d8d3d692 100644 --- a/src/Gui/ViewProviderDatum.cpp +++ b/src/Gui/ViewProviderDatum.cpp @@ -41,6 +41,8 @@ #include "SoFCSelection.h" #include "ViewProviderCoordinateSystem.h" +#include + using namespace Gui; @@ -111,7 +113,7 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject) visible->addChild(pRoot); // Hidden features - auto hidden = new SoAnnotation(); + auto hidden = new So3DAnnotation(); // Style for hidden lines style = new SoDrawStyle();