implement correct way to query VBO status of viewer from SoBRepFaceSet node

This commit is contained in:
wmayer 2017-02-11 17:53:47 +01:00
parent 0700345049
commit 6d6fbdcd8d
5 changed files with 142 additions and 78 deletions

View File

@ -91,6 +91,7 @@ void Gui::SoFCDB::init()
SoFCSelectionAction ::initClass();
SoFCDocumentAction ::initClass();
SoGLWidgetNode ::initClass();
SoGLVBOActivatedElement ::initClass();
SoFCEnableSelectionAction ::initClass();
SoFCEnableHighlightAction ::initClass();
SoFCSelectionColorAction ::initClass();

View File

@ -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<SoGLVBOActivatedElement *>
(SoElement::getElement(state, classStackIndex));
elem->active = active;
}
void SoGLVBOActivatedElement::get(SoState * state, SbBool& active)
{
const SoGLVBOActivatedElement* self = static_cast<const SoGLVBOActivatedElement *>
(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;
}

View File

@ -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

View File

@ -1453,6 +1453,7 @@ void View3DInventorViewer::renderScene(void)
SoGLRenderAction* glra = this->getSoRenderManager()->getGLRenderAction();
SoGLWidgetElement::set(glra->getState(), qobject_cast<QGLWidget*>(this->getGLWidget()));
SoGLRenderActionElement::set(glra->getState(), glra);
SoGLVBOActivatedElement::set(glra->getState(), this->vboEnabled);
glra->apply(this->backgroundroot);
navigation->updateAnimation();

View File

@ -56,14 +56,8 @@
#include "SoBrepFaceSet.h"
#include <Gui/SoFCUnifiedSelection.h>
#include <Gui/SoFCSelectionAction.h>
#include <App/Application.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Command.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <stdio.h>
#include <string.h>
#include <Gui/SoFCInteractiveElement.h>
#ifdef FC_OS_WIN32
#include <windows.h>
#include <GL/gl.h>
@ -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<const SoGLCoordinateElement*>(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<const SoGLCoordinateElement*>(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<Gui::View3DInventor*>(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;