示例#1
0
    EffectSpec::EffectSpec( const std::string & name, Type type, const ParameterGroupSpecsContainer & specs, bool transparent )
      : m_name( name )
      , m_type( type )
      , m_transparent( transparent )
      , m_specs( specs )
    {
#if !defined(NDEBUG)
      std::set<string> nameSet;
      for ( iterator it = m_specs.begin() ; it != m_specs.end() ; ++it )
      {
        DP_ASSERT( nameSet.insert( (*it)->getName() ).second );
      }
#endif
      sort( m_specs.begin(), m_specs.end(), specSorter );

      HashGeneratorMurMur hg;
      // don't hash the name
      hg.update( reinterpret_cast<const unsigned char *>(&m_type), sizeof(m_type) );
      hg.update( reinterpret_cast<const unsigned char *>(&m_transparent), sizeof(m_transparent) );
      for ( iterator it = m_specs.begin() ; it != m_specs.end() ; ++it )
      {
        HashKey hk = (*it)->getHashKey();
        hg.update( reinterpret_cast<const unsigned char *>(&hk), sizeof(hk) );
      }
      hg.finalize( (unsigned int *)&m_hashKey );
    }
示例#2
0
    ParameterGroupSpec::ParameterGroupSpec( const string & name
                                          , const vector<ParameterSpec> & specs )
      : m_dataSize(0)
      , m_name(name)
    {
#if !defined(NDEBUG)
      // check that no parameter name occurs more than once
      std::set<string> nameSet;
      for ( vector<ParameterSpec>::const_iterator it = specs.begin() ; it != specs.end() ; ++it )
      {
        DP_ASSERT( nameSet.insert( it->getName() ).second );
      }
#endif

      // order the specs by their base parameter size first, and name second
      vector<vector<ParameterSpec>::const_iterator> orderedSpecs;
      orderedSpecs.reserve( specs.size() );
      for ( vector<ParameterSpec>::const_iterator it = specs.begin() ; it != specs.end() ; ++it )
      {
        orderedSpecs.push_back( it );
      }
      sort( orderedSpecs.begin(), orderedSpecs.end(), specSorter );

      // get the pairs of ParameterSpec and offset
      m_specs.reserve( specs.size() );
      for ( vector<vector<ParameterSpec>::const_iterator>::const_iterator it = orderedSpecs.begin() ; it != orderedSpecs.end() ; ++it )
      {
        DP_ASSERT( m_dataSize % getParameterAlignment( (*it)->getType() ) == 0 );
        m_specs.push_back( make_pair( **it, m_dataSize ) );
        m_dataSize += (*it)->getSizeInByte();
      }

      HashGeneratorMurMur hg;
      // don't hash the name
      for ( iterator it = m_specs.begin() ; it != m_specs.end() ; ++it )
      {
        if ( ! it->first.getName().empty() )
        {
          hg.update( reinterpret_cast<const unsigned char *>(&it->first.getName()[0]), dp::checked_cast<unsigned int>(it->first.getName().size()) );
        }
        unsigned int tmp = it->first.getType();
        hg.update( reinterpret_cast<const unsigned char *>(&tmp), sizeof(tmp) );
        tmp = it->first.getArraySize();
        hg.update( reinterpret_cast<const unsigned char *>(&tmp), sizeof(tmp) );
      }
      hg.finalize( (unsigned int *)&m_hashKey );
    }