34 const SbViewportRegion& viewportregion,
Scene* scene) :
35 SoGLRenderAction(viewportregion), scene(scene), selectedcolor_storage(sizeof(void*), alloc_colorpacker, free_colorpacker)
38 this->isVisible =
true;
39 this->selectedColor = SbColor(1.0f, 0.8f, 0.4f);
40 this->activeColor = SbColor(1.0f, 0.4f, 0.2f);
41 this->linepattern = 0xffff;
45 this->postprocpath =
new SoTempPath(32);
46 this->postprocpath->ref();
52 postprocpath->unref();
57 std::unique_lock lock(scene->execute_mutex);
60 SoGLRenderAction::apply(node);
64 SoSearchAction* searchAction =
new SoSearchAction;
65 searchAction->setType(SoSelection::getClassTypeId());
67 searchAction->apply(node);
69 const SoPathList& pathlist = searchAction->getPaths();
71 if (pathlist.getLength() > 0)
73 for (
int i = 0; i < pathlist.getLength(); i++)
75 SoPath* path = pathlist[i];
76 SoSelection* selection = (SoSelection*) path->getTail();
78 if (selection->getNumSelected() > 0)
81 this->drawHighlight(path, selection->getList());
88 void scene3D::SoGLHighlightRenderAction::drawHighlight(SoPath* pathtothis,
89 const SoPathList* pathlist)
92 int oldnumpasses = this->getNumPasses();
93 this->setNumPasses(1);
96 int thispos = ((SoFullPath*) pathtothis)->getLength() - 1;
97 this->postprocpath->truncate(0);
99 for (
int i = 0; i < thispos; i++)
101 this->postprocpath->append(pathtothis->getNode(i));
105 for (
int i = 0; i < pathlist->getLength(); i++)
108 SoFullPath* path = (SoFullPath*)(*pathlist)[i];
111 for (
int j = 0; j < path->getLength(); j++)
113 this->postprocpath->append(path->getNode(j));
133 glEnable(GL_STENCIL_TEST);
134 glClearStencil(1.0f);
135 glClear(GL_STENCIL_BUFFER_BIT);
139 glStencilFunc(GL_NEVER, 0x0, 0x0);
140 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
141 SoGLRenderAction::apply(this->postprocpath);
144 glStencilFunc(GL_NOTEQUAL, 0, 1);
146 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
149 drawWireframe(this->postprocpath, i == pathlist->getLength() - 1);
152 this->postprocpath->truncate(thispos);
154 glDisable(GL_STENCIL_TEST);
158 this->setNumPasses(oldnumpasses);
161 void scene3D::SoGLHighlightRenderAction::drawWireframe(SoPath* pathtothis,
bool active)
164 SoState* state = this->getState();
170 glDisable(GL_LIGHTING);
173 SoColorPacker** selected_cptr =
174 (SoColorPacker**) this->selectedcolor_storage.get();
178 SoGLLazyElement::setDiffuse(state, pathtothis->getHead(), 1,
179 &this->selectedColor, *selected_cptr);
184 SoGLLazyElement::setDiffuse(state, pathtothis->getTail(), 1,
185 &this->activeColor, *selected_cptr);
193 SoPolygonOffsetElement::LINES, TRUE);
195 SoMaterialBindingElement::OVERALL);
197 SoOverrideElement::setNormalVectorOverride(state, NULL, TRUE);
198 SoOverrideElement::setMaterialBindingOverride(state, NULL, TRUE);
199 SoOverrideElement::setLightModelOverride(state, NULL, TRUE);
200 SoOverrideElement::setDiffuseColorOverride(state, NULL, TRUE);
201 SoOverrideElement::setLineWidthOverride(state, NULL, TRUE);
202 SoOverrideElement::setLinePatternOverride(state, NULL, TRUE);
203 SoOverrideElement::setDrawStyleOverride(state, NULL, TRUE);
204 SoOverrideElement::setPolygonOffsetOverride(state, NULL, TRUE);
205 SoTextureOverrideElement::setQualityOverride(state, TRUE);
208 SoGLRenderAction::apply(this->postprocpath);
211 glEnable(GL_LIGHTING);