Updated for make_unique<[]>
Родитель
65d811d63f
Коммит
a8118a7c75
6
Clean.md
6
Clean.md
|
@ -51,16 +51,16 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<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() ] );
|
||||
auto adj = std::make_unique<uint32_t[]>(mesh->indices.size());
|
||||
if ( FAILED( GenerateAdjacencyAndPointReps( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint16_t[]> indices( new uint16_t[ nFaces * 3 ] );
|
||||
auto indices = std::make_unique<uint16_t[]>(nFaces * 3);
|
||||
memcpy( indices.get(), mesh->indices.data(), sizeof(uint16_t) * nFaces * 3 ) );
|
||||
|
||||
std::vector<uint32_t> dupVerts;
|
||||
|
|
|
@ -39,15 +39,13 @@ After applying the vertex remap, any point reps are invalid as the vertices have
|
|||
```cpp
|
||||
// newIndices is created by some operation that leaves vertices unused.
|
||||
|
||||
std::unique_ptr<uint32_t[]> vertRemap( new uint32_t[ nVerts ] );
|
||||
auto vertRemap = std::make_unique<uint32_t[]>(nVerts);
|
||||
size_t trailingUnused = 0;
|
||||
if ( FAILED( OptimizeVertices( newIndices, nFaces, nVerts,
|
||||
vertRemap.get(), &trailingUnused ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<WaveFrontReader<uint16_t>::Vertex> vb(
|
||||
new WaveFrontReader<uint16_t>::Vertex[ nVerts - trailingUnused ] );
|
||||
|
||||
auto vb = std::make_unique<WaveFrontReader<uint16_t>::Vertex>(nVerts - trailingUnused);
|
||||
if ( FAILED( CompactVB( mesh->vertices.data(),
|
||||
sizeof(WaveFrontReader<uint16_t>::Vertex),
|
||||
nVerts, trailingUnused, vertRemap.get(), vb.get() ) ) )
|
||||
|
|
|
@ -47,7 +47,7 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
pos[ j ] = mesh->vertices[ j ].position;
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
pos[ j ] = mesh->vertices[ j ].position;
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ if ( mesh->hasNormals )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
pos[ j ] = mesh->vertices[ j ].position;
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> normals( new XMFLOAT3[ nVerts ] );
|
||||
auto normals = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
if ( FAILED( ComputeNormals( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, CNORM_DEFAULT, normals.get() ) ) )
|
||||
// Error
|
||||
|
|
|
@ -62,10 +62,10 @@ In the overloads that take both _tangents_ and _bitangents_, either but not both
|
|||
|
||||
Note that _bi-normal_ is another common term used for _bi-tangent_, although technically a bi-normal only applies in 2D and not 3D. The Direct3D HLSL semantic name for the _bi-tangent_ is ``BINORMAL``.
|
||||
|
||||
Due to the C++ overload resolution rules, if you want to call ComputeTangentFrame for only the binormal output and not the tangent output, you need to use an explicit cast on the nullptr parameter:
|
||||
Due to the C++ overload resolution rules, if you want to call ``ComputeTangentFrame`` for only the binormal output and not the tangent output, you need to use an explicit cast on the nullptr parameter:
|
||||
|
||||
```cpp
|
||||
std::unique_ptr<XMFLOAT3[]> bitangents( new XMFLOAT3[ nVerts ] );
|
||||
auto bitangents = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
|
||||
if ( FAILED( ComputeTangentFrame( mesh->indices.data(), nFaces,
|
||||
pos.get(), normals.get(), texcoords.get(), nVerts,
|
||||
|
@ -87,12 +87,11 @@ if ( mesh->hasNormals )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
pos[ j ] = mesh->vertices[ j ].position;
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> normals( new XMFLOAT3[ nVerts ] );
|
||||
|
||||
auto normals = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
if ( FAILED( ComputeNormals( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, CNORM_DEFAULT, normals.get() ) ) )
|
||||
// Error
|
||||
|
@ -100,12 +99,12 @@ if ( FAILED( ComputeNormals( mesh->indices.data(), nFaces,
|
|||
if ( !mesh->hasTexcoords )
|
||||
// Skip next computation
|
||||
|
||||
std::unique_ptr<XMFLOAT2[]> texcoords( new XMFLOAT2[ nVerts ] );
|
||||
auto texcoords = std::make_unique<XMFLOAT2[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
texcoords[ j ] = mesh->vertices[ j ].textureCoordinate;
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> tangents( new XMFLOAT3[ nVerts ] );
|
||||
std::unique_ptr<XMFLOAT3[]> bitangents( new XMFLOAT3[ nVerts ] );
|
||||
auto tangents = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
auto bitangents = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
|
||||
if ( FAILED( ComputeTangentFrame( mesh->indices.data(), nFaces,
|
||||
pos.get(), normals.get(), texcoords.get(), nVerts,
|
||||
|
|
|
@ -39,11 +39,11 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<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() ] );
|
||||
auto adj = std::make_unique<uint32_t[]>(mesh->indices.size());
|
||||
if ( FAILED ( GenerateAdjacencyAndPointReps(
|
||||
mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
|
||||
|
|
|
@ -66,21 +66,21 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<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() ] );
|
||||
auto adj = std::make_unique<uint32_t[]>(mesh->indices.size());
|
||||
if ( FAILED( GenerateAdjacencyAndPointReps( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint32_t[]> faceRemap( new uint32_t[ nFaces ] );
|
||||
auto faceRemap = std::make_unique<uint32_t[]>(nFaces);
|
||||
if ( FAILED( OptimizeFaces( mesh->indices.data(), nFaces, adj.get(),
|
||||
faceRemap.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint16_t[]> newIndices( new uint16_t[ nFaces * 3 ] );
|
||||
auto newIndices = std::make_unique<uint16_t[]>(nFaces * 3);
|
||||
if ( FAILED( ReorderIB( mesh->indices.data(), nFaces, faceRemap.get(),
|
||||
newIndices.get() ) ) )
|
||||
// Error
|
||||
|
|
|
@ -56,12 +56,12 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
|
||||
size_t nFaces = mesh->indices.size() / 3;
|
||||
|
||||
std::unique_ptr<uint32_t[]> faceRemap( new uint32_t[ nFaces ] );
|
||||
auto faceRemap = std::make_unique<uint32_t[]>(nFaces);
|
||||
if ( FAILED( OptimizeFacesLRU( mesh->indices.data(), nFaces,
|
||||
faceRemap.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint16_t[]> newIndices( new uint16_t[ nFaces * 3 ] );
|
||||
auto newIndices = std::make_unique<uint16_t[]>(nFaces * 3);
|
||||
if ( FAILED( ReorderIB( mesh->indices.data(), nFaces, faceRemap.get(),
|
||||
newIndices.get() ) ) )
|
||||
// Error
|
||||
|
|
|
@ -31,26 +31,26 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<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() ] );
|
||||
auto adj = std::make_unique<uint32_t[]>(mesh->indices.size());
|
||||
if ( FAILED( GenerateAdjacencyAndPointReps( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, 0.f, nullptr, adj.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint32_t[]> faceRemap( new uint32_t[ nFaces ] );
|
||||
auto faceRemap = std::make_unique<uint32_t[]>(nFaces);
|
||||
if ( FAILED( OptimizeFaces( mesh->indices.data(), nFaces, adj.get(),
|
||||
faceRemap.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint16_t[]> newIndices( new uint16_t[ nFaces * 3 ] );
|
||||
auto newIndices = std::make_unique<uint16_t[]>(nFaces * 3);
|
||||
if ( FAILED( ReorderIB( mesh->indices.data(), nFaces,
|
||||
faceRemap.get(), newIndices.get() ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint32_t[]> vertRemap( new uint32_t[ nVerts ] );
|
||||
auto vertRemap = std::make_unique<uint32_t[]>(nVerts);
|
||||
if ( FAILED( OptimizeVertices( newIndices.get(), nFaces, nVerts, vertRemap.get() ) ) )
|
||||
// Error
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ if ( FAILED( writer->Initialize( layout, 2 ) ) )
|
|||
// D3D12_INPUT_LAYOUT_DESC desc = { layout, 2 };
|
||||
// if ( FAILED( reader->Initialize( desc ) ) )
|
||||
|
||||
std::unique_ptr<uint8_t[]> vb( new uint8_t[ sizeof(Vertex) * nVerts ] );
|
||||
auto vb = std::make_unique<uint8_t[]>(sizeof(Vertex) * nVerts);
|
||||
|
||||
// We are creating a new VB, so a good practice would be to zero-fill it.
|
||||
memset( vb.get(), 0, sizeof(Vertex) * nVerts );
|
||||
|
|
|
@ -42,16 +42,16 @@ if ( FAILED( mesh->Load( L"test.obj" ) ) )
|
|||
size_t nFaces = mesh->indices.size() / 3;
|
||||
size_t nVerts = mesh->vertices.size();
|
||||
|
||||
std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
|
||||
auto pos = std::make_unique<XMFLOAT3[]>(nVerts);
|
||||
for( size_t j = 0; j < nVerts; ++j )
|
||||
pos[ j ] = mesh->vertices[ j ].position;
|
||||
|
||||
std::unique_ptr<uint32_t[]> preps( new uint32_t[ nVerts ] );
|
||||
auto preps = std::make_unique<uint32_t[]>(nVerts);
|
||||
if ( FAILED( GenerateAdjacencyAndPointReps( mesh->indices.data(), nFaces,
|
||||
pos.get(), nVerts, 0.f, preps.get(), nullptr ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint16_t[]> newIndices( new uint16_t[ nFaces * 3 ] );
|
||||
auto newIndices = std::make_unique<uint16_t[]>(nFaces * 3);
|
||||
memcpy(newIndices.get(), mesh->indices.data(), sizeof(uint16_t) * nFaces * 3);
|
||||
|
||||
if ( FAILED( WeldVertices(newIndices.get(), nFaces, nVerts, preps.get(), nullptr,
|
||||
|
@ -81,15 +81,13 @@ if ( FAILED( WeldVertices(newIndices.get(), nFaces, nVerts, preps.get(), nullptr
|
|||
}) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<uint32_t[]> vertRemap( new uint32_t[ nVerts ] );
|
||||
auto vertRemap = std::make_unique<uint32_t[]>(nVerts);
|
||||
size_t trailingUnused = 0;
|
||||
if ( FAILED( OptimizeVertices( newIndices.get(), nFaces, nVerts,
|
||||
vertRemap.get(), &trailingUnused ) ) )
|
||||
// Error
|
||||
|
||||
std::unique_ptr<WaveFrontReader<uint16_t>::Vertex> vb(
|
||||
new WaveFrontReader<uint16_t>::Vertex[ nVerts - trailingUnused ] );
|
||||
|
||||
auto vb = std::make_unique<WaveFrontReader<uint16_t>::Vertex>(nVerts - trailingUnused);
|
||||
if ( FAILED( CompactVB( mesh->vertices.data(),
|
||||
sizeof(WaveFrontReader<uint16_t>::Vertex),
|
||||
nVerts, trailingUnused, vertRemap.get(), vb.get() ) ) )
|
||||
|
|
Загрузка…
Ссылка в новой задаче