// 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; }
Action::ResultE RenderAction::stop(ResultE res) { #ifdef OSG_RENPART_DUMP_PAR fprintf(stderr, "Stop\n"); fflush(stderr); #endif Inherited::stop(res); if(!_doCullOnly) { drawBuffer(_currentBuffer); if(getVolumeDrawing()) drawVolume(_oFrustum); } if(_pViewarea != NULL && _pViewarea->getRenderOptions() != NULL) { _pViewarea->getRenderOptions()->deactivate(this); } else if(_pWindow != NULL && _pWindow->getRenderOptions() != NULL) { _pWindow->getRenderOptions()->deactivate(this); } return Action::Continue; }
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; }
// 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; }
Action::ResultE RenderAction::stop(ResultE res) { #ifdef OSG_RENPART_DUMP_PAR fprintf(stderr, "Stop\n"); fflush(stderr); #endif Inherited::stop(res); if(!_doCullOnly) { drawBuffer(_currentBuffer); if(getVolumeDrawing()) drawVolume(_oFrustum); if(_pStatistics != NULL) { UInt32 uiNMatrix = 0; UInt32 uiNState = 0; UInt32 uiNShader = 0; UInt32 uiNShaderParam = 0; UInt32 uiNTriangles = 0; for(UInt32 i = 0; i < _vRenderPartitions[_currentBuffer].size(); ++i) { uiNMatrix += _vRenderPartitions[ _currentBuffer][i]->getNumMatrixChanges(); uiNState += _vRenderPartitions[ _currentBuffer][i]->getNumStateChanges(); uiNShader += _vRenderPartitions[ _currentBuffer][i]->getNumShaderChanges(); uiNShaderParam += _vRenderPartitions[ _currentBuffer][i]->getNumShaderParamChanges(); uiNTriangles += _vRenderPartitions[_currentBuffer][i]->getNumTriangles(); } _pStatistics->getElem(statNMatrices )->set(uiNMatrix ); _pStatistics->getElem(statNStates )->set(uiNState ); _pStatistics->getElem(statNShaders )->set(uiNShader ); _pStatistics->getElem(statNShaderParams)->set(uiNShaderParam); _pStatistics->getElem(statNTriangles )->set(uiNTriangles); } } if(_pViewport != NULL && _pViewport->getRenderOptions() != NULL) { _pViewport->getRenderOptions()->deactivate(this); } else if(_pWindow != NULL && _pWindow->getRenderOptions() != NULL) { _pWindow->getRenderOptions()->deactivate(this); } return Action::Continue; }