Esempio n. 1
0
 void StateSet::setUniforms(const osg::StateSet::UniformList &uniforms)
 {
     for(osg::StateSet::UniformList::const_iterator it = uniforms.begin() ; it != uniforms.end() ; ++it)
     {
         const int override = it->second.second;
         osg::ref_ptr<osg::Uniform> uniform = it->second.first;
         const std::string &name = uniform->getName();
         uniform_table_t::iterator u_it = this->uniforms.find(name);
         if (override & osg::StateAttribute::PROTECTED)
         {
             if (u_it != this->uniforms.end())
             {
                 u_it->second.first = false;
                 u_it->second.second = uniform;
             }
             else
                 this->uniforms[name] = std::make_pair(false, uniform);
         }
         else if (override & osg::StateAttribute::OVERRIDE)
         {
             if (u_it == this->uniforms.end())
             {
                 this->uniforms[name] = std::make_pair(true, uniform);
             }
             else if (!u_it->second.first)
             {
                 u_it->second = std::make_pair(true, uniform);
             }
         }
         else if (override & osg::StateAttribute::INHERIT)
Esempio n. 2
0
void CountsVisitor::apply(osg::StateSet* stateSet)
{
    if(stateSet == NULL)
        return;
    _stateSets++;
    osg::ref_ptr<osg::Object> ssrp = (osg::Object*)stateSet;
    _uStateSets.insert(ssrp);

    if(osgwTools::isEmpty(*stateSet))
        _emptyStateSets++;

    const osg::StateSet::TextureAttributeList& tal = stateSet->getTextureAttributeList();
    const osg::StateSet::TextureModeList tml = stateSet->getTextureModeList();
    unsigned int idx;
    for(idx=0; idx<tal.size(); idx++)
    {
        if(tal.size() > 0)
        {
            const osg::StateSet::AttributeList& al = tal[ idx ];
            _texAttributes += al.size();
            osg::StateSet::AttributeList::const_iterator ait;
            for(ait=al.begin(); ait!=al.end(); ++ait)
            {
                osg::ref_ptr<osg::Object> arp = (osg::Object*)(ait->second.first.get());
                _uTexAttributes.insert(arp);
            }
        }

        if(tml.size() > 0)
            _texModes += tml[ idx ].size();

        osg::Texture* texture = static_cast< osg::Texture* >(
            stateSet->getTextureAttribute(idx, osg::StateAttribute::TEXTURE));
        if(texture != NULL)
        {
            _textures++;
            osg::ref_ptr<osg::Object> trp = (osg::Object*)texture;
            _uTextures.insert(trp);
        }
    }

    const osg::StateSet::AttributeList& al = stateSet->getAttributeList();
    _attributes += al.size();
    osg::StateSet::AttributeList::const_iterator ait;
    for(ait=al.begin(); ait!=al.end(); ++ait)
    {
        osg::StateAttribute* sa = ait->second.first.get();
        if(_countUserAttr && (sa->getType() == _userAttr))
            _totalUserAttrs++;

        osg::ref_ptr<osg::Object> arp = (osg::Object*)(sa);
        _uAttributes.insert(arp);
    }

    _modes += stateSet->getModeList().size();
    {
        const osg::StateSet::ModeList& ml = stateSet->getModeList();
        osg::StateSet::ModeList::const_iterator it;
        for(it=ml.begin(); it != ml.end(); ++it)
        {
            if(_countUserMode && (it->first == _userMode))
                _totalUserModes++;

            mc[ it->first ] += 1;
        }
    }

    osg::Program* program = static_cast< osg::Program* >(
        stateSet->getAttribute(osg::StateAttribute::PROGRAM));
    if(program != NULL)
    {
        _programs++;
        osg::ref_ptr<osg::Object> prp = (osg::Object*)program;
        _uPrograms.insert(prp);
    }

    const osg::StateSet::UniformList ul = stateSet->getUniformList();
    _uniforms += ul.size();
    osg::StateSet::UniformList::const_iterator it;
    for(it=ul.begin(); it!=ul.end(); ++it)
    {
        osg::ref_ptr<osg::Object> urp = (osg::Object*)(it->second.first.get());
        _uUniforms.insert(urp);
    }
}