void apply(osg::Node& node) { if (node.getStateSet()) process(node.getStateSet()); if (node.getUpdateCallback()) { _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); } LayerAttributes* la = dynamic_cast<LayerAttributes*>(node.getUserData()); if (la) { if ((_objectsHandled[la]++)==0) { OSG_NOTICE<<"LayerAttributeOperator for "<<la<<" required, assigning one."<<std::endl; _operatorList.insert(new LayerAttributesOperator(&node, la)); } else { OSG_NOTICE<<"LayerAttributeOperator for "<<la<<" not required, as one already assigned."<<std::endl; } } traverse(node); }
void apply(osg::Node& node) { if (_visited.count(&node)!=0) return; _visited.insert(&node); if (node.getStateSet()) apply(*(node.getStateSet())); traverse(node); }
void StatsVisitor::apply(osg::Node& node) { if (node.getStateSet()) { ++_numInstancedStateSet; _statesetSet.insert(node.getStateSet()); } traverse(node); }
void StatsVisitor::apply(osg::Node& node) { if (node.getStateSet()) { apply(*node.getStateSet()); } traverse(node); }
void ShaderVisitor::apply(osg::Node& node) { if (node.getStateSet()) { pushRequirements(); applyStateSet(node.getStateSet(), node); traverse(node); popRequirements(); } else traverse(node); }
/// Returns true if the given node is a basic root group with no special information. /// Used in conjunction with UseFbxRoot option. /// Identity transforms are considered as basic root nodes. bool isBasicRootNode(const osg::Node &node) { const osg::Group *osgGroup = node.asGroup(); if (!osgGroup || node.asGeode()) // WriterNodeVisitor handles Geodes the "old way" (= Derived from Node, not Group as for now). Geodes may be considered "basic root nodes" when WriterNodeVisitor will be adapted. { // Geodes & such are not basic root nodes return false; } // Test if we've got an empty transform (= a group!) const osg::Transform *transform = osgGroup->asTransform(); if (transform) { if (const osg::MatrixTransform *matrixTransform = transform->asMatrixTransform()) { if (!matrixTransform->getMatrix().isIdentity()) { // Non-identity matrix transform return false; } } else if (const osg::PositionAttitudeTransform *pat = transform->asPositionAttitudeTransform()) { if (pat->getPosition() != osg::Vec3d() || pat->getAttitude() != osg::Quat() || pat->getScale() != osg::Vec3d(1.0f, 1.0f, 1.0f) || pat->getPivotPoint() != osg::Vec3d()) { // Non-identity position attribute transform return false; } } else { // Other transform (not identity or not predefined type) return false; } } // Test the presence of a non-empty stateset if (node.getStateSet()) { osg::ref_ptr<osg::StateSet> emptyStateSet = new osg::StateSet; if (node.getStateSet()->compare(*emptyStateSet, true) != 0) { return false; } } return true; }
void ShaderGenerator::apply( osg::Node& node ) { if ( !_active ) return; if ( node.getStateSet() ) _state->pushStateSet( node.getStateSet() ); traverse(node); if ( node.getStateSet() ) _state->popStateSet(); }
void CVRCullVisitor::apply(osg::Node& node) { bool status = _cullingStatus; bool firstStatus = _firstCullStatus; if(isCulled(node)) { _firstCullStatus = firstStatus; _cullingStatus = status; return; } // push the culling mode. pushCurrentMask(); // push the node's state. StateSet* node_state = node.getStateSet(); if(node_state) pushStateSet(node_state); handle_cull_callbacks_and_traverse(node); // pop the node's state off the geostate stack. if(node_state) popStateSet(); // pop the culling mode. popCurrentMask(); _firstCullStatus = firstStatus; _cullingStatus = status; }
void ShaderGenerator::apply(osg::Node& node) { if ( !_active ) return; if ( ignore(&node) ) return; if ( _duplicateSharedSubgraphs ) duplicateSharedNode(node); applyNonCoreNodeIfNecessary( node ); osg::ref_ptr<osg::StateSet> stateset = node.getStateSet(); if ( stateset.valid() ) { _state->pushStateSet( stateset.get() ); } traverse(node); if ( stateset.valid() ) { _state->popStateSet(); } }
void ShaderGenerator::apply( osg::Node& node ) { if ( !_active ) return; osg::ref_ptr<osg::StateSet> ss = node.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { // optimize state set sharing if ( _stateSetCache.valid() ) _stateSetCache->share(replacement, replacement); _state->popStateSet(); node.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } traverse(node); if ( ss.get() ) { _state->popStateSet(); } }
void apply(osg::Node& node) { if (node.getStateSet()) process(node.getStateSet()); if (node.getUpdateCallback()) { _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); } LayerAttributes* la = dynamic_cast<LayerAttributes*>(node.getUserData()); if (la) { _operatorList.insert(new LayerAttributesOperator(&node, la)); } traverse(node); }
void CountsVisitor::apply(osg::Node& node) { pushStateSet(node.getStateSet()); _nodes++; osg::ref_ptr<osg::Object> rp = (osg::Object*)&node; _uNodes.insert(rp); apply(node.getStateSet()); if (++_depth > _maxDepth) _maxDepth = _depth; traverse(node); _depth--; popStateSet(); }
// ---------------------------------------------------------------- // SharedStateManager::apply // ---------------------------------------------------------------- void SharedStateManager::apply(osg::Node &node) { osg::StateSet *ss = node.getStateSet(); if (ss) process(ss, &node); traverse(node); }
virtual void apply(osg::Node& node) { if (node.getStateSet()) { node.setStateSet(0); ++_numStateSetRemoved; } traverse(node); }
void CountStateSets::apply( osg::Node& node ) { if( !processStateSet( node.getStateSet() ) && _removeEmptyStateSets ) { node.setStateSet( NULL ); _removedStateSets++; } traverse( node ); }
virtual void apply(osg::Node& node) { if (osgFX::Effect* effect = dynamic_cast<osgFX::Effect*>(&node)) applyEffect(*effect); osg::StateSet* stateset = node.getStateSet(); if (stateset) applyStateSet(stateset); traverse(node); }
void BaseDotVisitor::handleNodeAndTraverse(osg::Node& node, int id) { osg::StateSet* ss = node.getStateSet(); if ( ss ) { int id2; if ( getOrCreateId( ss, id2 ) ) { handle( *ss, id2 ); } handle( node, *ss, id, id2 ); } traverse(node); }
void GLObjectsVisitor::apply(osg::Node& node) { bool programSetBefore = _lastCompiledProgram.valid(); if (node.getStateSet()) { apply(*(node.getStateSet())); } traverse(node); bool programSetAfter = _renderInfo.getState()!=0 && _renderInfo.getState()->getLastAppliedProgramObject()!=0; if (programSetBefore && !programSetAfter) { osg::State* state = _renderInfo.getState(); osg::GLExtensions* extensions = state->get<osg::GLExtensions>(); extensions->glUseProgram(0); state->setLastAppliedProgramObject(0); _lastCompiledProgram = 0; } }
void GLES2ShaderGenVisitor::apply(osg::Node &node) { osg::StateSet *stateSet = node.getStateSet(); if (stateSet) _state->pushStateSet(stateSet); traverse(node); if (stateSet) _state->popStateSet(); }
void FlattenSceneGraphVisitor::apply(osg::Node& node) { osg::ref_ptr< osg::StateSet > ss = node.getStateSet(); if (ss) { pushStateSet(ss.get()); } traverse(node); if (ss) { popStateSet(); } }
void LinkVisitor::apply(osg::Node& node) { osg::StateSet* st = node.getStateSet(); if (st) handle_stateset(st); osg::NodeCallback* cb = node.getUpdateCallback(); while (cb) { osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb); if (cba) link(cba); cb = cb->getNestedCallback(); } traverse(node); }
void GenerateGL3LightingUniforms::apply(osg::Node& node) { osg::StateSet* stateset = node.getStateSet(); if (stateset) { if (_statesets.find(stateset) == _statesets.end()) { const osg::StateSet::RefAttributePair* rap = stateset->getAttributePair(osg::StateAttribute::MATERIAL); if (rap) { osg::Material* material = dynamic_cast<osg::Material*>(rap->first.get()); if (material) { osg::Material* mat = material; #if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) // If there's no FFP, we need to replace the Material with a GL3 Material to prevent // error messages on the console. if (dynamic_cast<MaterialGL3*>(material) == 0L) { mat = new MaterialGL3(*material); stateset->setAttributeAndModes(mat, rap->second); } #endif // Install the MaterialCallback so uniforms are updated. if (!mat->getUpdateCallback()) { if (stateset->getDataVariance() == osg::Object::DYNAMIC) mat->setUpdateCallback(new MaterialCallback()); else { MaterialCallback mc; mc.operator()(mat, NULL); } } } // mark this stateset as visited. _statesets.insert(stateset); } } } traverse(node); }
void ProxyCullVisitor::apply(osg::Node& node) { //OE_INFO << "Node: " << node.className() << std::endl; if ( isCulledByProxyFrustum(node) ) return; _cv->pushOntoNodePath( &node ); _cv->pushCurrentMask(); osg::StateSet* node_state = node.getStateSet(); if (node_state) _cv->pushStateSet(node_state); handle_cull_callbacks_and_traverse(node); if (node_state) _cv->popStateSet(); _cv->popCurrentMask(); _cv->popFromNodePath(); }
void ShaderGenerator::apply( osg::Node& node ) { if ( !_active ) return; if ( ignore(&node) ) return; osg::ref_ptr<osg::StateSet> stateset = node.getStateSet(); if ( stateset.valid() ) { _state->pushStateSet( stateset.get() ); } traverse(node); if ( stateset.valid() ) { _state->popStateSet(); } }
void FltExportVisitor::apply( osg::Node& node ) { _firstNode = false; ScopedStatePushPop guard( this, node.getStateSet() ); osgSim::LightPointNode* lpn = dynamic_cast< osgSim::LightPointNode* >( &node ); if (lpn) { writeLightPoint( lpn ); } else { // Unknown Node. Warn and return. // (Note, if the base class of this Node was a Group, then apply(Group&) // would export a Group record then continue traversal. Because we are // a Node, there's no way to continue traversal, so just return.) std::string warning( "fltexp: Unknown Node in OpenFlight export." ); osg::notify( osg::WARN ) << warning << std::endl; _fltOpt->getWriteResult().warn( warning ); return; } }
void ShaderGenerator::apply( osg::Node& node ) { if ( !_active ) return; bool ignore; if ( node.getUserValue(SHADERGEN_HINT_IGNORE, ignore) && ignore ) return; osg::ref_ptr<osg::StateSet> stateset = node.getStateSet(); if ( stateset.valid() ) { _state->pushStateSet( stateset.get() ); } traverse(node); if ( stateset.valid() ) { _state->popStateSet(); } }
void ShaderGenerator::apply( osg::Node& node ) { osg::ref_ptr<osg::StateSet> ss = node.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { _state->popStateSet(); node.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } traverse(node); if ( ss.get() ) { _state->popStateSet(); } }
virtual void apply(osg::Node& node) { apply(node.getStateSet()); traverse(node); }
void TerrainCuller::apply(osg::Node& node) { // push the node's state. osg::StateSet* node_state = node.getStateSet(); TileNode* tileNode = dynamic_cast<TileNode*>(&node); if (tileNode) { _currentTileNode = tileNode; _currentTileDrawCommands = 0u; if (!_terrain.patchLayers().empty()) { // todo: check for patch/virtual const RenderBindings& bindings = _context->getRenderBindings(); TileRenderModel& renderModel = _currentTileNode->renderModel(); bool pushedMatrix = false; for (PatchLayerVector::const_iterator i = _terrain.patchLayers().begin(); i != _terrain.patchLayers().end(); ++i) { PatchLayer* layer = i->get(); if (layer->getAcceptCallback() == 0L || layer->getAcceptCallback()->acceptKey(_currentTileNode->getKey())) { // Push this tile's matrix if we haven't already done so: if (!pushedMatrix) { SurfaceNode* surface = tileNode->getSurfaceNode(); // push the surface matrix: osg::Matrix mvm = *getModelViewMatrix(); surface->computeLocalToWorldMatrix(mvm, this); pushModelViewMatrix(createOrReuseMatrix(mvm), surface->getReferenceFrame()); pushedMatrix = true; } // Add the draw command: DrawTileCommand* cmd = addDrawCommand(layer->getUID(), &renderModel, 0L, tileNode); if (cmd) { cmd->_drawPatch = true; cmd->_drawCallback = layer->getDrawCallback(); ++_currentTileDrawCommands; } } } if (pushedMatrix) { popModelViewMatrix(); } } } else { SurfaceNode* surface = dynamic_cast<SurfaceNode*>(&node); if (surface) { TileRenderModel& renderModel = _currentTileNode->renderModel(); // push the surface matrix: osg::Matrix mvm = *getModelViewMatrix(); surface->computeLocalToWorldMatrix(mvm, this); pushModelViewMatrix(createOrReuseMatrix(mvm), surface->getReferenceFrame()); // First go through any legit rendering pass data in the Tile and // and add a DrawCommand for each. for (unsigned p = 0; p < renderModel._passes.size(); ++p) { const RenderingPass& pass = renderModel._passes[p]; if (pass._layer.valid() && pass._layer->getRenderType() == Layer::RENDERTYPE_TILE) { if (addDrawCommand(pass._sourceUID, &renderModel, &pass, _currentTileNode)) { ++_currentTileDrawCommands; } } } // Next, add a DrawCommand for each tile layer not represented in the TerrainTileModel // as a rendering pass. for (LayerVector::const_iterator i = _terrain.tileLayers().begin(); i != _terrain.tileLayers().end(); ++i) { Layer* layer = i->get(); if (addDrawCommand(layer->getUID(), &renderModel, 0L, _currentTileNode)) { ++_currentTileDrawCommands; } } // If the culler added no draw commands for this tile... do something! if (_currentTileDrawCommands == 0) { //OE_INFO << LC << "Adding blank render.\n"; addDrawCommand(-1, &renderModel, 0L, _currentTileNode); } popModelViewMatrix(); _terrain._drawState->_bs.expandBy(surface->getBound()); _terrain._drawState->_box.expandBy(_terrain._drawState->_bs); } } traverse(node); }
//------------------------------------------------------------------------------ void ResourceVisitor::collect( osg::Node& node ) { ////////////////////// // STATE ATTRIBUTES // ////////////////////// osg::StateSet* ss = node.getStateSet(); if( NULL != ss ) { osg::StateSet::AttributeList& attr = ss->getAttributeList(); for( osg::StateSet::AttributeList::iterator itr = attr.begin(); itr != attr.end(); ++itr ) if( GLMemoryAdapter* res = dynamic_cast<GLMemoryAdapter*>( (*itr).second.first.get() ) ) { osg::ref_ptr<Resource> resource = res->getMemory(); addResource( *res->getMemory() ); } osg::StateSet::TextureAttributeList& texAttrList = ss->getTextureAttributeList(); for( osg::StateSet::TextureAttributeList::iterator itr = texAttrList.begin(); itr != texAttrList.end(); ++itr ) { osg::StateSet::AttributeList& texAttr = (*itr); for( osg::StateSet::AttributeList::iterator texitr = texAttr.begin(); texitr != texAttr.end(); ++texitr ) { if( GLMemoryAdapter* res = dynamic_cast<GLMemoryAdapter*>( (*texitr).second.first.get() ) ) { osg::ref_ptr<Resource> resource = res->getMemory(); addResource( *resource ); } } } } /////////////// // DRAWABLES // /////////////// osg::Geode* geode = dynamic_cast<osg::Geode*>( &node ); if( NULL != geode ) { for( unsigned int d=0; d<geode->getNumDrawables(); ++d ) { if( GLMemoryAdapter* res = dynamic_cast<GLMemoryAdapter*>( geode->getDrawable(d) ) ) { osg::ref_ptr<Resource> resource = res->getMemory(); addResource( *resource ); } } } ////////////// // INTERNAL // ////////////// osgCompute::Computation* computation = dynamic_cast<osgCompute::Computation*>( &node ); if( NULL != computation ) { ResourceHandleList& resources = computation->getResources(); for( ResourceHandleListItr itr = resources.begin(); itr != resources.end(); ++itr ) { if( (*itr)._resource.valid() ) { addResource( *((*itr)._resource) ); } } } }