Skip to content

FinalizeVB

Chuck Walbourn edited this page Jan 21, 2022 · 7 revisions
DirectXMesh

Finishes mesh optimization by reordering vertices and/or adding duplicated vertices for the vertex buffer.

HRESULT FinalizeVB(
   const void* vbin, size_t stride, size_t nVerts,
   const uint32_t* dupVerts, size_t nDupVerts,
   const uint32_t* vertexRemap, void* vbout );

HRESULT FinalizeVB(
   void* vb, size_t stride, size_t nVerts,
   const uint32_t* vertexRemap );

Parameters

The vbin buffer (or vb for in-place finalize) must be nVerts*stride bytes.

The vbout buffer must be (nVerts+nDupVerts)*stride bytes.

A vertexRemap is an array with nVerts+nDupVerts elements that describes how to reorder the vertices of the original mesh: oldLoc = vertexRemap[newLoc]. See OptimizeVertices. It can be nullptr for an 'identity' remap when just performing duplication.

dupVerts contains nDupVerts elements indicating vertices that need duplicating. Each entry indicates the index of the original vbin vertex buffer to duplicate. The vertexRemap array also indicates reorder information for the duplicated vertices. dupVerts can be nullptr if nDupVerts is 0.

Remarks

This is the pseudo-code for applying a vertex remap to a vertex buffer:

for each j in nVerts
    srcIndex = vertexRemap[ j ]
    if ( srcIndex != -1 )
       memcpy( newVB + j * stride,
               oldVB + srcIndex * stride,
               stride )

for each j in nVerts
    vertexRemapInverse[ vertexRemap[ j ] ] = j

for each j in nDupVerts
   newIndex = vertexRemapInverse[ j + nVerts ]
   if ( newIndex != -1 )
       memcpy( newVB + newIndex * stride,
               oldVB + dup[ j ] * stride,
               stride )

After applying the vertex remap, any point reps are invalid as the vertices have been moved. To maintain a point reps array, use FinalizeVBAndPointReps

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • GCC 10.5, 11.4, 12.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXTex

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally