Skip to content

Commit

Permalink
make vboAvailable a static variable and extend interface of renderSha…
Browse files Browse the repository at this point in the history
…pe to avoid side effects
  • Loading branch information
wwmayer committed Feb 12, 2017
1 parent 8612c4f commit 0700345
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
32 changes: 13 additions & 19 deletions src/Mod/Part/Gui/SoBrepFaceSet.cpp
Expand Up @@ -96,6 +96,8 @@ using namespace PartGui;

SO_NODE_SOURCE(SoBrepFaceSet);

SbBool SoBrepFaceSet::vboAvailable = false;

void SoBrepFaceSet::initClass()
{
SO_NODE_INIT_CLASS(SoBrepFaceSet, SoIndexedFaceSet, "IndexedFaceSet");
Expand All @@ -109,15 +111,12 @@ SoBrepFaceSet::SoBrepFaceSet()
SO_NODE_ADD_FIELD(selectionIndex, (-1));

static bool init = false;
static bool vertex_buffer_object = false;
if (!init) {
std::string ext = (const char*)(glGetString(GL_EXTENSIONS));
vertex_buffer_object = (ext.find("GL_ARB_vertex_buffer_object") != std::string::npos);
vboAvailable = (ext.find("GL_ARB_vertex_buffer_object") != std::string::npos);
init = true;
}

vboAvailable = vertex_buffer_object;

#ifdef FC_OS_WIN32
#if QT_VERSION < 0x50000
const QGLContext* gl = QGLContext::currentContext();
Expand All @@ -128,10 +127,10 @@ SoBrepFaceSet::SoBrepFaceSet()
#endif

updateVbo = false;
vboLoaded = false;
indice_array = 0;
if (vboAvailable) {
glGenBuffersARB(2, &myvbo[0]);
vboLoaded = false;
indice_array = 0;
}
selectionIndex.setNum(0);
}
Expand Down Expand Up @@ -248,7 +247,7 @@ void SoBrepFaceSet::doAction(SoAction* action)
}
}
// The recommended way to set 'updateVbo' is to reimplement the method 'notify'
// but the class made this method private so that we can't override it.
// but the base class made this method private so that we can't override it.
// So, the alternative way is to write a custom SoAction class.
else if (action->getTypeId() == Gui::SoUpdateVBOAction::getClassTypeId()) {
this->updateVbo = true;
Expand Down Expand Up @@ -325,7 +324,7 @@ void SoBrepFaceSet::GLRender(SoGLRenderAction *action)
pindices = this->partIndex.getValues(0);
numparts = this->partIndex.getNum();

renderShape(state, static_cast<const SoGLCoordinateElement*>(coords), cindices, numindices,
renderShape(state, vboAvailable, 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
Expand Down Expand Up @@ -452,7 +451,7 @@ void SoBrepFaceSet::GLRender(SoGLRenderAction *action)
if (!nindices) nindices = cindices;
pindices = this->partIndex.getValues(0);
numparts = this->partIndex.getNum();
renderShape(state, static_cast<const SoGLCoordinateElement*>(coords), cindices, numindices,
renderShape(state, vboAvailable, 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
Expand Down Expand Up @@ -813,11 +812,8 @@ void SoBrepFaceSet::renderHighlight(SoGLRenderAction *action)
mbind = OVERALL;
doTextures = false;

SbBool tmp = vboAvailable;
vboAvailable = false;
renderShape(state, static_cast<const SoGLCoordinateElement*>(coords), &(cindices[start]), length,
renderShape(state, false, static_cast<const SoGLCoordinateElement*>(coords), &(cindices[start]), length,
&(pindices[id]), 1, normals, nindices, &mb, mindices, &tb, tindices, nbind, mbind, doTextures?1:0);
vboAvailable = tmp;
}
state->pop();

Expand Down Expand Up @@ -900,11 +896,8 @@ void SoBrepFaceSet::renderSelection(SoGLRenderAction *action)
else
nbind = OVERALL;

SbBool tmp = vboAvailable;
vboAvailable = false;
renderShape(state, static_cast<const SoGLCoordinateElement*>(coords), &(cindices[start]), length,
renderShape(state, false, static_cast<const SoGLCoordinateElement*>(coords), &(cindices[start]), length,
&(pindices[id]), 1, normals_s, nindices_s, &mb, mindices, &tb, tindices, nbind, mbind, doTextures?1:0);
vboAvailable = tmp;
}
state->pop();

Expand All @@ -913,6 +906,7 @@ void SoBrepFaceSet::renderSelection(SoGLRenderAction *action)
}

void SoBrepFaceSet::renderShape(SoState * state,
SbBool hasVBO,
const SoGLCoordinateElement * const vertexlist,
const int32_t *vertexindices,
int num_indices,
Expand Down Expand Up @@ -964,11 +958,11 @@ void SoBrepFaceSet::renderShape(SoState * state,
}

/*
vboAvailable is used to determine if vbo is an avilable extension on the system .
'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 (vboAvailable && ViewerVBO) {
if (hasVBO && ViewerVBO) {
float * vertex_array = NULL;
GLuint * index_array = NULL;
SbVec3f *mynormal1,*mynormal2,*mynormal3;
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Part/Gui/SoBrepFaceSet.h
Expand Up @@ -113,6 +113,7 @@ class PartGuiExport SoBrepFaceSet : public SoIndexedFaceSet {
Binding findMaterialBinding(SoState * const state) const;
Binding findNormalBinding(SoState * const state) const;
void renderShape(SoState * state,
SbBool hasVBO,
const SoGLCoordinateElement * const vertexlist,
const int32_t *vertexindices,
int num_vertexindices,
Expand Down Expand Up @@ -142,7 +143,7 @@ class PartGuiExport SoBrepFaceSet : public SoIndexedFaceSet {
#endif

// Define some VBO pointer for the current mesh
SbBool vboAvailable;
static SbBool vboAvailable;
SbBool updateVbo;
uint32_t myvbo[2];
SbBool vboLoaded;
Expand Down

0 comments on commit 0700345

Please sign in to comment.