From 6d6fbdcd8d08f6e53a40318cf425f9498482adc1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 11 Feb 2017 17:53:47 +0100 Subject: [PATCH] implement correct way to query VBO status of viewer from SoBRepFaceSet node --- src/Gui/SoFCDB.cpp | 1 + src/Gui/SoFCInteractiveElement.cpp | 55 +++++++++++++ src/Gui/SoFCInteractiveElement.h | 125 +++++++++++++++++------------ src/Gui/View3DInventorViewer.cpp | 1 + src/Mod/Part/Gui/SoBrepFaceSet.cpp | 38 +++------ 5 files changed, 142 insertions(+), 78 deletions(-) diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index bf0db3a26..9e424b9dd 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -91,6 +91,7 @@ void Gui::SoFCDB::init() SoFCSelectionAction ::initClass(); SoFCDocumentAction ::initClass(); SoGLWidgetNode ::initClass(); + SoGLVBOActivatedElement ::initClass(); SoFCEnableSelectionAction ::initClass(); SoFCEnableHighlightAction ::initClass(); SoFCSelectionColorAction ::initClass(); diff --git a/src/Gui/SoFCInteractiveElement.cpp b/src/Gui/SoFCInteractiveElement.cpp index 3777eec16..02156523a 100644 --- a/src/Gui/SoFCInteractiveElement.cpp +++ b/src/Gui/SoFCInteractiveElement.cpp @@ -214,3 +214,58 @@ void SoGLWidgetNode::GLRender(SoGLRenderAction * action) { SoGLWidgetNode::doAction(action); } + +// --------------------------------- + +SO_ELEMENT_SOURCE(SoGLVBOActivatedElement); + +void SoGLVBOActivatedElement::initClass(void) +{ + SO_ELEMENT_INIT_CLASS(SoGLVBOActivatedElement, inherited); + SO_ENABLE(SoGLRenderAction, SoGLVBOActivatedElement); + SO_ENABLE(SoHandleEventAction, SoGLVBOActivatedElement); +} + +void SoGLVBOActivatedElement::init(SoState * state) +{ + inherited::init(state); + this->active = false; +} + +SoGLVBOActivatedElement::~SoGLVBOActivatedElement() +{ +} + +void SoGLVBOActivatedElement::set(SoState * state, SbBool active) +{ + SoGLVBOActivatedElement * elem = static_cast + (SoElement::getElement(state, classStackIndex)); + elem->active = active; +} + +void SoGLVBOActivatedElement::get(SoState * state, SbBool& active) +{ + const SoGLVBOActivatedElement* self = static_cast + (SoElement::getConstElement(state, classStackIndex)); + active = self->active; +} + +void SoGLVBOActivatedElement::push(SoState * state) +{ + inherited::push(state); +} + +void SoGLVBOActivatedElement::pop(SoState * state, const SoElement * prevTopElement) +{ + inherited::pop(state, prevTopElement); +} + +SbBool SoGLVBOActivatedElement::matches(const SoElement * /*element*/) const +{ + return true; +} + +SoElement * SoGLVBOActivatedElement::copyMatchInfo(void) const +{ + return 0; +} diff --git a/src/Gui/SoFCInteractiveElement.h b/src/Gui/SoFCInteractiveElement.h index 60ea0e9a4..b7c9f8dcf 100644 --- a/src/Gui/SoFCInteractiveElement.h +++ b/src/Gui/SoFCInteractiveElement.h @@ -54,56 +54,56 @@ protected: private: SbBool interactiveMode; }; - -class GuiExport SoGLWidgetElement : public SoElement { - typedef SoElement inherited; - - SO_ELEMENT_HEADER(SoGLWidgetElement); - -public: - static void initClass(void); - - virtual void init(SoState * state); - virtual void push(SoState * state); - virtual void pop(SoState * state, const SoElement * prevTopElement); - - virtual SbBool matches(const SoElement * element) const; - virtual SoElement * copyMatchInfo(void) const; - - static void set(SoState * state, QGLWidget * window); - static void get(SoState * state, QGLWidget *& window); - -protected: - virtual ~SoGLWidgetElement(); - -protected: - QGLWidget * window; -}; - -class GuiExport SoGLRenderActionElement : public SoElement { - typedef SoElement inherited; - - SO_ELEMENT_HEADER(SoGLRenderActionElement); - -public: - static void initClass(void); - - virtual void init(SoState * state); - virtual void push(SoState * state); - virtual void pop(SoState * state, const SoElement * prevTopElement); - - virtual SbBool matches(const SoElement * element) const; - virtual SoElement * copyMatchInfo(void) const; - - static void set(SoState * state, SoGLRenderAction * action); - static void get(SoState * state, SoGLRenderAction * & action); - -protected: - virtual ~SoGLRenderActionElement(); - -protected: - SoGLRenderAction * glRenderAction; -}; + +class GuiExport SoGLWidgetElement : public SoElement { + typedef SoElement inherited; + + SO_ELEMENT_HEADER(SoGLWidgetElement); + +public: + static void initClass(void); + + virtual void init(SoState * state); + virtual void push(SoState * state); + virtual void pop(SoState * state, const SoElement * prevTopElement); + + virtual SbBool matches(const SoElement * element) const; + virtual SoElement * copyMatchInfo(void) const; + + static void set(SoState * state, QGLWidget * window); + static void get(SoState * state, QGLWidget *& window); + +protected: + virtual ~SoGLWidgetElement(); + +protected: + QGLWidget * window; +}; + +class GuiExport SoGLRenderActionElement : public SoElement { + typedef SoElement inherited; + + SO_ELEMENT_HEADER(SoGLRenderActionElement); + +public: + static void initClass(void); + + virtual void init(SoState * state); + virtual void push(SoState * state); + virtual void pop(SoState * state, const SoElement * prevTopElement); + + virtual SbBool matches(const SoElement * element) const; + virtual SoElement * copyMatchInfo(void) const; + + static void set(SoState * state, SoGLRenderAction * action); + static void get(SoState * state, SoGLRenderAction * & action); + +protected: + virtual ~SoGLRenderActionElement(); + +protected: + SoGLRenderAction * glRenderAction; +}; class GuiExport SoGLWidgetNode : public SoNode { typedef SoNode inherited; @@ -123,6 +123,31 @@ protected: virtual ~SoGLWidgetNode(); }; +class GuiExport SoGLVBOActivatedElement : public SoElement { + typedef SoElement inherited; + + SO_ELEMENT_HEADER(SoGLVBOActivatedElement); + +public: + static void initClass(void); + + virtual void init(SoState * state); + virtual void push(SoState * state); + virtual void pop(SoState * state, const SoElement * prevTopElement); + + virtual SbBool matches(const SoElement * element) const; + virtual SoElement * copyMatchInfo(void) const; + + static void set(SoState * state, SbBool); + static void get(SoState * state, SbBool& active); + +protected: + virtual ~SoGLVBOActivatedElement(); + +protected: + SbBool active; +}; + } // namespace Gui #endif // GUI_SOFCINTERACTIVEELEMENT_H diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 5767e215d..d3e07d48a 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1453,6 +1453,7 @@ void View3DInventorViewer::renderScene(void) SoGLRenderAction* glra = this->getSoRenderManager()->getGLRenderAction(); SoGLWidgetElement::set(glra->getState(), qobject_cast(this->getGLWidget())); SoGLRenderActionElement::set(glra->getState(), glra); + SoGLVBOActivatedElement::set(glra->getState(), this->vboEnabled); glra->apply(this->backgroundroot); navigation->updateAnimation(); diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index e73442e84..fc5cf4c20 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -56,14 +56,8 @@ #include "SoBrepFaceSet.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include + #ifdef FC_OS_WIN32 #include #include @@ -451,7 +445,12 @@ void SoBrepFaceSet::GLRender(SoGLRenderAction *action) if (!nindices) nindices = cindices; pindices = this->partIndex.getValues(0); numparts = this->partIndex.getNum(); - renderShape(state, vboAvailable, static_cast(coords), cindices, numindices, + SbBool hasVBO = vboAvailable; + if (hasVBO) { + // get the VBO status of the viewer + Gui::SoGLVBOActivatedElement::get(state, hasVBO); + } + renderShape(state, hasVBO, static_cast(coords), cindices, numindices, pindices, numparts, normals, nindices, &mb, mindices, &tb, tindices, nbind, mbind, doTextures?1:0); // Disable caching for this node @@ -944,25 +943,8 @@ void SoBrepFaceSet::renderShape(SoState * state, int matnr = 0; int trinr = 0; - /* This code detect if the user activated VBO through the preference menu */ - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - Gui::View3DInventor* view; - if (doc != NULL) - view = static_cast(doc->getActiveView()); - else - view = NULL; - bool ViewerVBO = false; - if (view != NULL) { - Gui::View3DInventorViewer* viewer = view->getViewer(); - ViewerVBO = viewer->isEnabledVBO(); - } - - /* - 'hasVBO' is used to determine if vbo is an available extension on the system. - This is not because end user wants VBO that it is available. - */ - - if (hasVBO && ViewerVBO) { + // Can we use vertex buffer objects? + if (hasVBO) { float * vertex_array = NULL; GLuint * index_array = NULL; SbVec3f *mynormal1,*mynormal2,*mynormal3;