void ResourceVertexAttributeSet::update()
          {
            /** copy over vertex data **/
            dp::rix::core::Renderer *renderer = m_resourceManager->getRenderer();

            std::vector<dp::rix::core::VertexFormatInfo>  vertexInfos;
            dp::rix::core::VertexDataSharedHandle vertexData = renderer->vertexDataCreate();

            unsigned int numVertices = m_vertexAttributeSet->getVertexAttribute( 0 ).getVertexDataCount();

            std::vector<ResourceBufferSharedPtr> resourceBuffers;

            unsigned int currentStream = 0;

            std::vector<dp::sg::core::BufferSharedPtr> streams;
      
            for ( unsigned int i = 0; i < 16; ++i ) // FIXME Must match MAX_ATTRIBUTES, but that is only defined in inc\RendererAPI\RendererGL.h
            {
              dp::sg::core::VertexAttribute va = m_vertexAttributeSet->getVertexAttribute( i );

              if ( va.getBuffer() && va.getVertexDataCount() == numVertices )
              {
                ResourceBufferSharedPtr resourceBuffer = ResourceBuffer::get(va.getBuffer(), m_resourceManager );
                //resourceVertexAttributeSet->m_resourceBuffers.push_back( resourceBuffer );
                resourceBuffers.push_back( resourceBuffer );
          
                std::vector<dp::sg::core::BufferSharedPtr>::iterator it = std::find( streams.begin(), streams.end(), va.getBuffer() );
                if ( it == streams.end() )
                {
                  currentStream = static_cast<unsigned int>(streams.size());
                  streams.push_back( va.getBuffer() );
                }
                else
                {
                  currentStream = static_cast<unsigned int>(std::distance( streams.begin(), it ));
                }

                vertexInfos.push_back( dp::rix::core::VertexFormatInfo( i, va.getVertexDataType(), va.getVertexDataSize(), false, currentStream, va.getVertexDataOffsetInBytes(), va.getVertexDataStrideInBytes()));

                renderer->vertexDataSet( vertexData, currentStream, resourceBuffer->m_bufferHandle, 0, numVertices );
              }

            }
            dp::rix::core::VertexFormatDescription vertexFormatDescription(vertexInfos.empty() ? nullptr : &vertexInfos[0], vertexInfos.size());
            dp::rix::core::VertexFormatSharedHandle vertexFormat = renderer->vertexFormatCreate( vertexFormatDescription );

            renderer->vertexAttributesSet( m_vertexAttributesHandle, vertexData, vertexFormat );
            // keep a reference to the new resourceBuffers and remove reference to the old ones
            m_resourceBuffers.swap( resourceBuffers );
          }
Пример #2
0
GeometrySharedHandle generateGeometry( dp::util::generator::SmartGeometryData& meshIn, dp::rix::core::Renderer* m_rix )
{
    unsigned int attrMask = 0;

    for( map<dp::util::generator::AttributeID, dp::util::generator::AttributeData>::iterator it = meshIn->m_attributes.begin(); it != meshIn->m_attributes.end(); ++it )
    {
        attrMask |= it->first;
    }

    map<dp::util::generator::AttributeID, BufferSharedHandle> vbuffers;
    vector<VertexFormatInfo> vfis;

    BufferSharedHandle ibuffer;
    if( !meshIn->m_indices.empty() )
    {
        ibuffer = m_rix->bufferCreate();
        size_t bufferSize = meshIn->m_indices.size() * sizeof(unsigned int);
        m_rix->bufferSetSize( ibuffer, bufferSize );
        m_rix->bufferUpdateData( ibuffer, 0, &meshIn->m_indices[0], bufferSize );
    }

    VertexDataSharedHandle vertexData = m_rix->vertexDataCreate();
    for(unsigned int i = 0; i < NUM_ATTRIBS; i++)
    {
        dp::util::generator::AttributeID curAttr = (dp::util::generator::AttributeID)(1 << i);
        if( attrMask & curAttr )
        {
            vbuffers[curAttr] = m_rix->bufferCreate();
            m_rix->bufferSetSize( vbuffers[curAttr], meshIn->m_attributes[curAttr].m_data.size() * sizeof(float) );
            m_rix->bufferUpdateData( vbuffers[curAttr], 0, &meshIn->m_attributes[curAttr].m_data[0], meshIn->m_attributes[curAttr].m_data.size() * sizeof(float) );

            dp::util::Uint8 streamId = dp::util::checked_cast<dp::util::Uint8>( vfis.size() );

            vfis.push_back( VertexFormatInfo( i, dp::util::DT_FLOAT_32, meshIn->m_attributes[curAttr].m_dimensionality, false,
                                              streamId, 0, meshIn->m_attributes[curAttr].m_dimensionality * sizeof(float)) );

            m_rix->vertexDataSet( vertexData, streamId, vbuffers[curAttr], 0, meshIn->m_attributes[curAttr].m_data.size() / meshIn->m_attributes[curAttr].m_dimensionality );
        }
    }

    VertexFormatDescription vertexFormatDescription( &vfis[0], vfis.size() );
    VertexFormatSharedHandle vertexFormat = m_rix->vertexFormatCreate( vertexFormatDescription );

    VertexAttributesSharedHandle vertexAttributes = m_rix->vertexAttributesCreate();
    m_rix->vertexAttributesSet( vertexAttributes, vertexData, vertexFormat );

    IndicesSharedHandle indices = 0;
    if( !meshIn->m_indices.empty() )
    {
        indices = m_rix->indicesCreate();
        m_rix->indicesSetData( indices, dp::util::DT_UNSIGNED_INT_32, ibuffer, 0, meshIn->m_indices.size() );
    }

    GeometryDescriptionSharedHandle geometryDescription = m_rix->geometryDescriptionCreate();
    m_rix->geometryDescriptionSet( geometryDescription, meshIn->m_gpt );

    GeometrySharedHandle geometry = m_rix->geometryCreate();
    m_rix->geometrySetData( geometry, geometryDescription, vertexAttributes, indices );

    return geometry;

}