Reorders vertices in order of use by the index buffer which optimizes for the vertex shader pre-transform cache.

HRESULT OptimizeVertices(
   _In_reads_(nFaces*3) const uint16_t* indices,
   _In_ size_t nFaces, _In_ size_t nVerts,
   _Out_writes_(nVerts) uint32_t* vertexRemap );

HRESULT OptimizeVertices(
   _In_reads_(nFaces*3) const uint32_t* indices,
   _In_ size_t nFaces, _In_ size_t nVerts,
   _Out_writes_(nVerts) uint32_t* vertexRemap );

Parameters

vertexRemap is an array describing the reordering. See FinalizeIB, FinalizeVB, and FinalizeVBAndPointReps for details.

Note this matches the D3DXMesh::Optimize method and D3DXOptimizeVertices function definitions of the vertex remap array.

Remarks

Any 'unused' vertices are eliminated and the extra space is left at the end of the vertex buffer when applied.

Example

std::unique_ptr<WaveFrontReader<uint16_t>> mesh( new WaveFrontReader<uint16_t>() );

if ( FAILED( mesh->Load( L"test.obj" ) ) )
   // Error

size_t nFaces = mesh->indices.size() / 3;
size_t nVerts = mesh->vertices.size();

std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
for( size_t j = 0; j < nVerts; ++j )
   pos[ j ] = mesh->vertices[ j ].position;

std::unique_ptr<uint32_t[]> adj( new uint32_t[ mesh->indices.size() ] );
if ( FAILED( GenerateAdjacencyAndPointReps( &mesh->indices.front(), nFaces,
   pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
   // Error

std::unique_ptr<uint32_t[]> faceRemap( new uint32_t[ nFaces ] );
if ( FAILED( OptimizeFaces( &mesh->indices.front(), nFaces, adj.get(),
   faceRemap.get() ) ) )
   // Error

std::unique_ptr<uint16_t[]> newIndices( new uint16_t[ nFaces * 3 ] );
if ( FAILED( ReorderIB( &mesh->indices.front(), nFaces,
   faceRemap.get(), newIndices.get() ) ) )
   // Error

std::unique_ptr<uint32_t[]> vertRemap( new uint32_t[ nVerts ] );
if ( FAILED( OptimizeVertices( newIndices.get(), nFaces, nVerts, vertRemap.get() ) ) )
   // Error

if ( FAILED( FinalizeIB( newIndices.get(), nFaces, vertRemap.get(), nVerts ) ) )
   // Error

std::unique_ptr<WaveFrontReader<uint16_t>::Vertex> vb(
   new WaveFrontReader<uint16_t>::Vertex[ nVerts ] );

if ( FAILED( FinalizeVB( &mesh->vertices.front(),
   sizeof(WaveFrontReader<uint16_t>::Vertex),
   nVerts, nullptr, 0, vertRemap.get(), vb.get() ) ) )
   // Error

Last edited Nov 20, 2014 at 6:56 PM by walbourn, version 19