Skip to content

Commit

Permalink
Streamline GLRender method with indexed faceset implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
VolkerEnderlein committed Jun 16, 2021
1 parent 1bf3ed5 commit dfb56d2
Showing 1 changed file with 48 additions and 50 deletions.
98 changes: 48 additions & 50 deletions src/shapenodes/SoIndexedLineSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,90 +144,87 @@ SoIndexedLineSet::initClass(void)
}

//
// translates current normal binding into the internal Binding enum
// translates current material binding into the internal Binding enum
//
SoIndexedLineSet::Binding
SoIndexedLineSet::findNormalBinding(SoState * state)
SoIndexedLineSet::findMaterialBinding(SoState * state)
{
Binding binding = PER_VERTEX_INDEXED;

SoNormalBindingElement::Binding normbind =
(SoNormalBindingElement::Binding) SoNormalBindingElement::get(state);
Binding binding = OVERALL;
SoMaterialBindingElement::Binding matbind =
(SoMaterialBindingElement::Binding) SoMaterialBindingElement::get(state);

switch (normbind) {
case SoNormalBindingElement::OVERALL:
switch (matbind) {
case SoMaterialBindingElement::OVERALL:
binding = OVERALL;
break;
case SoNormalBindingElement::PER_VERTEX:
case SoMaterialBindingElement::PER_VERTEX:
binding = PER_VERTEX;
break;
case SoNormalBindingElement::PER_VERTEX_INDEXED:
case SoMaterialBindingElement::PER_VERTEX_INDEXED:
binding = PER_VERTEX_INDEXED;
break;
case SoNormalBindingElement::PER_PART:
case SoMaterialBindingElement::PER_PART:
binding = PER_SEGMENT;
break;
case SoNormalBindingElement::PER_PART_INDEXED:
case SoMaterialBindingElement::PER_PART_INDEXED:
binding = PER_SEGMENT_INDEXED;
break;
case SoNormalBindingElement::PER_FACE:
case SoMaterialBindingElement::PER_FACE:
binding = PER_LINE;
break;
case SoNormalBindingElement::PER_FACE_INDEXED:
case SoMaterialBindingElement::PER_FACE_INDEXED:
binding = PER_LINE_INDEXED;
break;
default:
#if COIN_DEBUG
SoDebugError::postWarning("SoIndexedLineSet::findNormalBinding",
"unknown normal binding setting");
SoDebugError::postWarning("SoIndexedLineSet::findMaterialBinding",
"unknown material binding setting");
#endif // COIN_DEBUG
break;
}

return binding;
}


//
// translates current material binding into the internal Binding enum
// translates current normal binding into the internal Binding enum
//
SoIndexedLineSet::Binding
SoIndexedLineSet::findMaterialBinding(SoState * state)
SoIndexedLineSet::findNormalBinding(SoState* state)
{
Binding binding = OVERALL;

SoMaterialBindingElement::Binding matbind =
(SoMaterialBindingElement::Binding) SoMaterialBindingElement::get(state);
Binding binding = PER_VERTEX_INDEXED;
SoNormalBindingElement::Binding normbind =
(SoNormalBindingElement::Binding) SoNormalBindingElement::get(state);

switch (matbind) {
case SoMaterialBindingElement::OVERALL:
switch (normbind) {
case SoNormalBindingElement::OVERALL:
binding = OVERALL;
break;
case SoMaterialBindingElement::PER_VERTEX:
case SoNormalBindingElement::PER_VERTEX:
binding = PER_VERTEX;
break;
case SoMaterialBindingElement::PER_VERTEX_INDEXED:
case SoNormalBindingElement::PER_VERTEX_INDEXED:
binding = PER_VERTEX_INDEXED;
break;
case SoMaterialBindingElement::PER_PART:
case SoNormalBindingElement::PER_PART:
binding = PER_SEGMENT;
break;
case SoMaterialBindingElement::PER_PART_INDEXED:
case SoNormalBindingElement::PER_PART_INDEXED:
binding = PER_SEGMENT_INDEXED;
break;
case SoMaterialBindingElement::PER_FACE:
case SoNormalBindingElement::PER_FACE:
binding = PER_LINE;
break;
case SoMaterialBindingElement::PER_FACE_INDEXED:
case SoNormalBindingElement::PER_FACE_INDEXED:
binding = PER_LINE_INDEXED;
break;
default:
#if COIN_DEBUG
SoDebugError::postWarning("SoIndexedFaceSet::findNormalBinding",
SoDebugError::postWarning("SoIndexedLineSet::findNormalBinding",
"unknown normal binding setting");
#endif // COIN_DEBUG
break;
}

return binding;
}

Expand All @@ -239,23 +236,22 @@ SoIndexedLineSet::GLRender(SoGLRenderAction * action)
if (this->coordIndex.getNum() < 2) return;
SoState * state = action->getState();

SbBool didpush = FALSE;
SbBool hasvp = FALSE;

if (this->vertexProperty.getValue()) {
hasvp = TRUE;
state->push();
didpush = TRUE;
this->vertexProperty.getValue()->GLRender(action);
}

if (!this->shouldGLRender(action)) {
if (didpush)
if (hasvp)
state->pop();
return;
}

SoMaterialBundle mb(action);
SoTextureCoordinateBundle tb(action, TRUE, FALSE);
SbBool doTextures = tb.needCoordinates();
Binding mbind = this->findMaterialBinding(state);
Binding nbind = this->findNormalBinding(state);

const SoCoordinateElement * coords;
const SbVec3f * normals;
Expand All @@ -264,26 +260,28 @@ SoIndexedLineSet::GLRender(SoGLRenderAction * action)
const int32_t * nindices;
const int32_t * tindices;
const int32_t * mindices;
SbBool doTextures;
SbBool normalCacheUsed;

SoMaterialBundle mb(action);

SoTextureCoordinateBundle tb(action, TRUE, FALSE);
doTextures = tb.needCoordinates();
SbBool sendNormals = !mb.isColorOnly() || tb.isFunction();

getVertexData(state, coords, normals, cindices,
nindices, tindices, mindices, numindices,
sendNormals, normalCacheUsed);
this->getVertexData(state, coords, normals, cindices,
nindices, tindices, mindices, numindices,
sendNormals, normalCacheUsed);

if (sendNormals && normals == NULL) {
if (!didpush) {
if (!hasvp) {
state->push();
didpush = TRUE;
hasvp = TRUE;
}
sendNormals = FALSE;
SoLazyElement::setLightModel(state, SoLazyElement::BASE_COLOR);
}

Binding mbind = this->findMaterialBinding(state);
Binding nbind = this->findNormalBinding(state);

if (this->getNodeType() == SoNode::VRML1) {
// For VRML1, PER_VERTEX means per vertex in shape, not PER_VERTEX
// on the state.
Expand Down Expand Up @@ -331,6 +329,7 @@ SoIndexedLineSet::GLRender(SoGLRenderAction * action)
const SoGLVBOElement * vboelem = SoGLVBOElement::getInstance(state);
SoVBO * colorvbo = NULL;

SbBool didrenderasvbo = FALSE;
if (dova && (mbind != OVERALL)) {
dova = FALSE;
if ((mbind == PER_VERTEX_INDEXED) && ((mindices == cindices) || (mindices == NULL))) {
Expand All @@ -346,18 +345,17 @@ SoIndexedLineSet::GLRender(SoGLRenderAction * action)
}
}
}
SbBool didrenderasvbo = FALSE;
if (dova) {
SbBool dovbo = this->startVertexArray(action,
coords,
nbind != OVERALL ? normals : NULL,
doTextures,
mbind != OVERALL);
didrenderasvbo = dovbo;

LOCK_VAINDEXER(this);
if (PRIVATE(this)->vaindexer == NULL) {
SoVertexArrayIndexer * indexer = new SoVertexArrayIndexer;

int i = 0;
while (i < numindices) {
int cnt = 0;
Expand Down Expand Up @@ -409,7 +407,7 @@ SoIndexedLineSet::GLRender(SoGLRenderAction * action)
drawPoints ? 1 : 0);
}

if (didpush) {
if (hasvp) {
state->pop();
}
// send approx number of lines for autocache handling
Expand Down

0 comments on commit dfb56d2

Please sign in to comment.