void VertexAttributeSet::combineBuffers() { // calculate stride & number of vertices unsigned int stride = 0; unsigned int numberOfVertices = 0; for ( unsigned int index = 0; index < static_cast<unsigned int>(AttributeID::VERTEX_ATTRIB_COUNT); ++index ) { AttributeID id = static_cast<AttributeID>(index); if ( isEnabled( id ) ) { VertexAttribute attribute = getVertexAttribute( id ); stride += attribute.getVertexDataBytes(); if ( !numberOfVertices ) { numberOfVertices = attribute.getVertexDataCount(); } else { DP_ASSERT( numberOfVertices == attribute.getVertexDataCount() ); } } } // create one big buffer with all data BufferSharedPtr newBufferSharedPtr = BufferHost::create(); newBufferSharedPtr->setSize( numberOfVertices * stride ); unsigned int offset = 0; for ( unsigned int index = 0; index < static_cast<unsigned int>(AttributeID::VERTEX_ATTRIB_COUNT); ++index ) { AttributeID id = static_cast<AttributeID>(index); if ( isEnabled( id ) ) { VertexAttribute attributeNew; const VertexAttribute& attributeOld = getVertexAttribute( id ); attributeNew.setData( attributeOld.getVertexDataSize(), attributeOld.getVertexDataType(), newBufferSharedPtr, offset, stride, numberOfVertices ); Buffer::DataReadLock drl(attributeOld.getBuffer()); Buffer::DataWriteLock dwl(attributeNew.getBuffer(), Buffer::MapMode::READWRITE ); dp::util::stridedMemcpy( dwl.getPtr(), attributeNew.getVertexDataOffsetInBytes(), attributeNew.getVertexDataStrideInBytes(), drl.getPtr(), attributeOld.getVertexDataOffsetInBytes(), attributeOld.getVertexDataStrideInBytes(), attributeOld.getVertexDataBytes(), numberOfVertices ); offset += attributeOld.getVertexDataBytes(); setVertexAttribute( id, attributeNew, true ); } } }