void RenderPartition::popVisibility(void) { if(getFrustumCulling() == false) return; _visibilityStack.pop_back(); }
// select all visible nodes UInt32 RenderAction::selectVisibles(void) { if(getFrustumCulling() == false) return getNNodes(); useNodeList(); Color3f col; UInt32 count = 0; for(UInt32 i = 0; i < getNNodes(); i++) { if(isVisible(getNode(i))) { col.setValuesRGB(0,1,0); addNode(getNode(i)); ++count; } else { col.setValuesRGB(1,0,0); } if(getVolumeDrawing()) { dropVolume(this, getNode(i), col); } } return count; }
bool ShadingAction::isVisible(Node *node) { if ( getFrustumCulling() == false ) return true; getStatistics()->getElem(statCullTestedNodes)->inc(); DynamicVolume vol; // node->getWorldVolume( vol ); node->updateVolume(); vol = node->getVolume(); vol.transform(top_matrix()); if ( _frustum.intersect( vol ) ) { // fprintf(stderr,"%p: node 0x%p vis\n", Thread::getCurrent(), node); return true; } getStatistics()->getElem(statCulledNodes)->inc(); // fprintf(stderr,"%p: node 0x%p invis\n", Thread::getCurrent(), node); // _frustum.dump(); return false; }
UInt32 AdapterDrawAction::selectVisiblesGlobal (void) { if (!getFrustumCulling()) { return getNNodes(); } GLint l = 0; bool d = getVolumeDrawing(); if ( d ) { l = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); } useNodeList(); UInt32 count = 0; for ( UInt32 i = 0; i < getNNodes(); ++i ) { if ( isVisible( getNode(i).getCPtr() ) ) { addNode( getNode(i) ); ++count; } if (d) { OSGCache::CacheData& data = OSGCache::the()[getNode(i)]; OSGCache::CacheData::AdapterContainer& all = data.getAdapter(BVolAdapterBase::getAdapterId()); // for BVolHierarchyBase there are more than one leaf nodes, then render // for SingleHierarchyBase there are more than one inner nodes, then skip if (all.size() > 1 && ((BVolAdapterBase*)all[0])->isInner()) { continue; } glColor3f(0,1,0); glPushMatrix(); glLoadIdentity(); getCamera()->setup(this, *getViewport()); //const Matrix& matrixI = data.getToWorldMatrix(); //glMultMatrixf(matrixI.getValues()); OSGCache::CacheData::AdapterContainer::const_iterator iter=all.begin(); for (; iter != all.end(); ++iter) { ((BVolAdapterBase*)*iter)->getBoundingVolume().drawWireframe(); } glPopMatrix(); } } if (l) { glEnable(GL_LIGHTING); } return count; }
// test a single node bool RenderPartition::isVisible(Node *pNode) { if(getFrustumCulling() == false) return true; if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCullTestedNodes)->inc(); } // _oDrawEnv.getRTAction()->getStatistics()->getElem(statCullTestedNodes)->inc(); if(pNode->getVolume().isInfinite() == true) return true; BoxVolume vol; pNode->updateVolume(); vol = pNode->getVolume(); vol.transform(topMatrix()); if(_oFrustum.intersect(vol)) { // fprintf(stderr,"%p: node 0x%p vis\n", Thread::getCurrent(), node); return true; } if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCulledNodes)->inc(); } // _oDrawEnv.getRTAction()->getStatistics()->getElem(statCulledNodes)->inc(); // fprintf(stderr,"%p: node 0x%p invis\n", Thread::getCurrent(), node); // _frustum.dump(); return false; }
// visibility levels bool RenderPartition::pushVisibility(Node * const pNode) { if(getFrustumCulling() == false) return true; FrustumVolume::PlaneSet inplanes = _visibilityStack.back(); if(inplanes == FrustumVolume::P_ALL) { _visibilityStack.push_back(inplanes); return true; } Color3f col; bool result = true; FrustumVolume frustum = _oFrustum; BoxVolume vol = pNode->getVolume(); // don't mess with infinite volumes if(vol.isInfinite() == false) { pNode->updateVolume(); vol = pNode->getVolume(); #if 1 vol.transform(topMatrix()); #else // not quite working Matrix m = topMatrix(); m.invert(); frustum.transform(m); #endif } if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCullTestedNodes)->inc(); } if(intersect(frustum, vol, inplanes) == false) { result = false; col.setValuesRGB(1,0,0); if(_oDrawEnv.getStatCollector() != NULL) { _oDrawEnv.getStatCollector()->getElem(statCulledNodes)->inc(); } } else { if(inplanes == FrustumVolume::P_ALL) { col.setValuesRGB(0,1,0); } else { col.setValuesRGB(0,0,1); } } if(getVolumeDrawing()) { dropVolume(this, pNode, col); } _visibilityStack.push_back(inplanes); return result; }