Gui: Fix render order of datum planes

This commit is contained in:
Kacper Donat
2025-01-06 01:14:54 +01:00
committed by Chris Hennes
parent 7a39746fa3
commit 83807826cf
5 changed files with 100 additions and 14 deletions

View File

@@ -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<SoDelayedAnnotationsElement*>(state->getElementNoPush(classStackIndex));
elt->paths.append(path);
}
SoPathList SoDelayedAnnotationsElement::getDelayedPaths(SoState* state)
{
auto elt = static_cast<SoDelayedAnnotationsElement*>(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());
}
}

View File

@@ -24,11 +24,48 @@
#include <Inventor/actions/SoGLRenderAction.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/elements/SoElement.h>
#include <FCGlobal.h>
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

View File

@@ -147,6 +147,7 @@ void Gui::SoFCDB::init()
SoFCPathAnnotation ::initClass();
SoMouseWheelEvent ::initClass();
So3DAnnotation ::initClass();
SoDelayedAnnotationsElement ::initClass();
PropertyItem ::init();
PropertySeparatorItem ::init();

View File

@@ -130,6 +130,8 @@
#include "NavigationAnimation.h"
#include "Utilities.h"
#include <Inventor/So3DAnnotation.h>
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)

View File

@@ -41,6 +41,8 @@
#include "SoFCSelection.h"
#include "ViewProviderCoordinateSystem.h"
#include <Inventor/So3DAnnotation.h>
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();