Constify uvatlastool

This commit is contained in:
Chuck Walbourn 2022-03-12 17:27:59 -08:00
parent 1a4c3e5748
commit 3e5ab8767c
4 changed files with 52 additions and 53 deletions

View File

@ -59,7 +59,7 @@ namespace
inline HRESULT write_file_string(HANDLE hFile, const wchar_t* value)
{
UINT length = (value) ? static_cast<UINT>(wcslen(value) + 1) : 1;
const UINT length = (value) ? static_cast<UINT>(wcslen(value) + 1) : 1;
DWORD bytesWritten;
if (!WriteFile(hFile, &length, static_cast<DWORD>(sizeof(UINT)), &bytesWritten, nullptr))
@ -70,7 +70,7 @@ namespace
if (length > 0)
{
auto bytes = static_cast<DWORD>(sizeof(wchar_t) * length);
auto const bytes = static_cast<DWORD>(sizeof(wchar_t) * length);
if (!WriteFile(hFile, value, bytes, &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
@ -80,7 +80,7 @@ namespace
}
else
{
wchar_t nul = 0;
constexpr wchar_t nul = 0;
if (!WriteFile(hFile, &nul, sizeof(wchar_t), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
@ -91,7 +91,7 @@ namespace
return S_OK;
}
inline UINT64 roundup4k(UINT64 value)
constexpr UINT64 roundup4k(UINT64 value)
{
return ((value + 4095) / 4096) * 4096;
}
@ -238,7 +238,7 @@ HRESULT Mesh::SetIndexData(size_t nFaces, const uint32_t* indices, const uint32_
//--------------------------------------------------------------------------------------
HRESULT Mesh::SetVertexData(_Inout_ DirectX::VBReader& reader, _In_ size_t nVerts) noexcept
HRESULT Mesh::SetVertexData(const DirectX::VBReader& reader, _In_ size_t nVerts) noexcept
{
if (!nVerts)
return E_INVALIDARG;
@ -419,7 +419,7 @@ HRESULT Mesh::Clean(_In_ bool breakBowties) noexcept
return S_OK;
}
size_t nNewVerts = mnVerts + dups.size();
const size_t nNewVerts = mnVerts + dups.size();
std::unique_ptr<XMFLOAT3[]> pos(new (std::nothrow) XMFLOAT3[nNewVerts]);
if (!pos)
@ -1039,7 +1039,7 @@ bool Mesh::Is16BitIndexBuffer() const noexcept
const uint32_t* iptr = mIndices.get();
for (size_t j = 0; j < (mnFaces * 3); ++j)
{
uint32_t index = *(iptr++);
const uint32_t index = *(iptr++);
if (index != uint32_t(-1)
&& (index >= UINT16_MAX))
{
@ -1062,7 +1062,7 @@ std::unique_ptr<uint16_t[]> Mesh::GetIndexBuffer16() const noexcept
if ((uint64_t(mnFaces) * 3) >= UINT32_MAX)
return ib;
size_t count = mnFaces * 3;
const size_t count = mnFaces * 3;
ib.reset(new (std::nothrow) uint16_t[count]);
if (!ib)
@ -1092,7 +1092,7 @@ std::unique_ptr<uint16_t[]> Mesh::GetIndexBuffer16() const noexcept
//--------------------------------------------------------------------------------------
HRESULT Mesh::GetVertexBuffer(_Inout_ DirectX::VBWriter& writer) const noexcept
HRESULT Mesh::GetVertexBuffer(const DirectX::VBWriter& writer) const noexcept
{
if (!mnVerts || !mPositions)
return E_UNEXPECTED;
@ -1106,7 +1106,7 @@ HRESULT Mesh::GetVertexBuffer(_Inout_ DirectX::VBWriter& writer) const noexcept
auto e = writer.GetElement11("NORMAL", 0);
if (e)
{
bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
const bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
hr = writer.Write(mNormals.get(), "NORMAL", 0, mnVerts, x2bias);
if (FAILED(hr))
return hr;
@ -1118,7 +1118,7 @@ HRESULT Mesh::GetVertexBuffer(_Inout_ DirectX::VBWriter& writer) const noexcept
auto e = writer.GetElement11("TANGENT", 0);
if (e)
{
bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
const bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
hr = writer.Write(mTangents.get(), "TANGENT", 0, mnVerts, x2bias);
if (FAILED(hr))
return hr;
@ -1130,7 +1130,7 @@ HRESULT Mesh::GetVertexBuffer(_Inout_ DirectX::VBWriter& writer) const noexcept
auto e = writer.GetElement11("BINORMAL", 0);
if (e)
{
bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
const bool x2bias = (e->Format == DXGI_FORMAT_R11G11B10_FLOAT);
hr = writer.Write(mBiTangents.get(), "BINORMAL", 0, mnVerts, x2bias);
if (FAILED(hr))
return hr;
@ -1298,7 +1298,7 @@ HRESULT Mesh::ExportToVBO(const wchar_t* szFileName) const noexcept
if (FAILED(hr))
return hr;
auto vertSize = static_cast<DWORD>(sizeof(vertex_t) * header.numVertices);
auto const vertSize = static_cast<DWORD>(sizeof(vertex_t) * header.numVertices);
DWORD bytesWritten;
if (!WriteFile(hFile.get(), vb.get(), vertSize, &bytesWritten, nullptr))
@ -1307,7 +1307,7 @@ HRESULT Mesh::ExportToVBO(const wchar_t* szFileName) const noexcept
if (bytesWritten != vertSize)
return E_FAIL;
auto indexSize = static_cast<DWORD>(sizeof(uint16_t) * header.numIndices);
auto const indexSize = static_cast<DWORD>(sizeof(uint16_t) * header.numIndices);
if (!WriteFile(hFile.get(), ib.get(), indexSize, &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
@ -1380,7 +1380,7 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
if (!vb || !ib)
return E_OUTOFMEMORY;
auto vertSize = static_cast<DWORD>(sizeof(vertex_t) * header.numVertices);
auto const vertSize = static_cast<DWORD>(sizeof(vertex_t) * header.numVertices);
if (!ReadFile(hFile.get(), vb.get(), vertSize, &bytesRead, nullptr))
{
@ -1390,7 +1390,7 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
if (bytesRead != vertSize)
return E_FAIL;
auto indexSize = static_cast<DWORD>(sizeof(uint16_t) * header.numIndices);
auto const indexSize = static_cast<DWORD>(sizeof(uint16_t) * header.numIndices);
if (!ReadFile(hFile.get(), ib.get(), indexSize, &bytesRead, nullptr))
{
@ -1524,7 +1524,7 @@ namespace VSD3DStarter
DirectX::XMFLOAT4X4 UVTransform;
};
const uint32_t MAX_TEXTURE = 8;
constexpr uint32_t MAX_TEXTURE = 8;
struct SubMesh
{
@ -1535,7 +1535,7 @@ namespace VSD3DStarter
UINT PrimCount;
};
const uint32_t NUM_BONE_INFLUENCES = 4;
constexpr uint32_t NUM_BONE_INFLUENCES = 4;
struct Vertex
{
@ -1618,7 +1618,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
if (mnVerts >= UINT16_MAX)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
UINT nIndices = static_cast<UINT>(mnFaces * 3);
const UINT nIndices = static_cast<UINT>(mnFaces * 3);
// Setup vertices/indices for CMO
std::unique_ptr<Vertex[]> vb(new (std::nothrow) Vertex[mnVerts]);
@ -1645,7 +1645,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
if (mColors)
{
XMVECTOR icolor = XMLoadFloat4(&mColors[j]);
const XMVECTOR icolor = XMLoadFloat4(&mColors[j]);
PackedVector::XMUBYTEN4 rgba;
PackedVector::XMStoreUByteN4(&rgba, icolor);
vptr->color = rgba.v;
@ -1660,7 +1660,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
{
for (size_t j = 0; j < mnVerts; ++j, ++sptr)
{
XMVECTOR v = XMLoadFloat4(&mBlendIndices[j]);
const XMVECTOR v = XMLoadFloat4(&mBlendIndices[j]);
XMStoreUInt4(reinterpret_cast<XMUINT4*>(&sptr->boneIndex[0]), v);
const XMFLOAT4* w = &mBlendWeights[j];
@ -1783,7 +1783,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
mdata.Emissive.z = m.emissiveColor.z;
mdata.Emissive.w = 1.f;
XMMATRIX id = XMMatrixIdentity();
const XMMATRIX id = XMMatrixIdentity();
XMStoreFloat4x4(&mdata.UVTransform, id);
hr = write_file(hFile.get(), mdata);
@ -1813,7 +1813,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
}
}
BYTE sd = 0; // No skeleton/animation data
constexpr BYTE sd = 0; // No skeleton/animation data
hr = write_file(hFile.get(), sd);
if (FAILED(hr))
return hr;
@ -1878,7 +1878,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
if (FAILED(hr))
return hr;
auto indexSize = static_cast<DWORD>(sizeof(uint16_t) * nIndices);
auto const indexSize = static_cast<DWORD>(sizeof(uint16_t) * nIndices);
DWORD bytesWritten;
if (!WriteFile(hFile.get(), ib.get(), indexSize, &bytesWritten, nullptr))
@ -1898,7 +1898,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
if (FAILED(hr))
return hr;
auto vertSize = static_cast<DWORD>(sizeof(Vertex) * mnVerts);
auto const vertSize = static_cast<DWORD>(sizeof(Vertex) * mnVerts);
if (!WriteFile(hFile.get(), vb.get(), vertSize, &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
@ -1919,7 +1919,7 @@ HRESULT Mesh::ExportToCMO(const wchar_t* szFileName, size_t nMaterials, const Ma
if (FAILED(hr))
return hr;
auto skinVertSize = static_cast<DWORD>(sizeof(SkinningVertex) * mnVerts);
auto const skinVertSize = static_cast<DWORD>(sizeof(SkinningVertex) * mnVerts);
if (!WriteFile(hFile.get(), vbSkin.get(), skinVertSize, &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
@ -2256,7 +2256,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->name.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->name.c_str(), -1,
m2->Name, MAX_MATERIAL_NAME, nullptr, FALSE);
if (!result)
@ -2269,7 +2269,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->texture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->texture.c_str(), -1,
m2->AlbedoTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2287,7 +2287,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
_splitpath_s(m2->AlbedoTexture, drive, dir, fname, ext);
std::string basename = fname;
size_t pos = basename.find_last_of('_');
const size_t pos = basename.find_last_of('_');
if (pos != std::string::npos)
{
basename = basename.substr(0, pos);
@ -2315,7 +2315,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
// Allow normal texture material property to override derived name
if (!m0->normalTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->normalTexture.c_str(), -1,
m2->NormalTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2327,7 +2327,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
// Allow emissive texture material property to override drived name
if (!m0->emissiveTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->emissiveTexture.c_str(), -1,
m2->EmissiveTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2339,7 +2339,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
// Allow RMA texture material property to override drived name
if (!m0->rmaTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->rmaTexture.c_str(), -1,
m2->RMATexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2378,7 +2378,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->name.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->name.c_str(), -1,
m->Name, MAX_MATERIAL_NAME, nullptr, FALSE);
if (!result)
@ -2389,7 +2389,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->texture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->texture.c_str(), -1,
m->DiffuseTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2400,7 +2400,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->normalTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->normalTexture.c_str(), -1,
m->NormalTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2411,7 +2411,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
if (!m0->specularTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
const int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->specularTexture.c_str(), -1,
m->SpecularTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
@ -2512,7 +2512,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
header.HeaderSize = sizeof(SDKMESH_HEADER) + sizeof(SDKMESH_VERTEX_BUFFER_HEADER) + sizeof(SDKMESH_INDEX_BUFFER_HEADER);
size_t staticDataSize = sizeof(SDKMESH_MESH)
const size_t staticDataSize = sizeof(SDKMESH_MESH)
+ header.NumTotalSubsets * sizeof(SDKMESH_SUBSET)
+ sizeof(SDKMESH_FRAME)
+ header.NumMaterials * sizeof(SDKMESH_MATERIAL);
@ -2589,7 +2589,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
strcpy_s(frame.Name, "root");
frame.ParentFrame = frame.ChildFrame = frame.SiblingFrame = DWORD(-1);
frame.AnimationDataIndex = INVALID_ANIMATION_DATA;
XMMATRIX id = XMMatrixIdentity();
const XMMATRIX id = XMMatrixIdentity();
XMStoreFloat4x4(&frame.Matrix, id);
hr = write_file(hFile.get(), frame);
@ -2615,7 +2615,7 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName,
// Write frame influence list
assert(meshHeader.NumFrameInfluences == 1);
UINT frameIndex = 0;
constexpr UINT frameIndex = 0;
hr = write_file(hFile.get(), frameIndex);
if (FAILED(hr))
return hr;

View File

@ -47,7 +47,7 @@ public:
HRESULT SetIndexData(_In_ size_t nFaces, _In_reads_(nFaces * 3) const uint16_t* indices, _In_reads_opt_(nFaces) const uint32_t* attributes = nullptr) noexcept;
HRESULT SetIndexData(_In_ size_t nFaces, _In_reads_(nFaces * 3) const uint32_t* indices, _In_reads_opt_(nFaces) const uint32_t* attributes = nullptr) noexcept;
HRESULT SetVertexData(_Inout_ DirectX::VBReader& reader, _In_ size_t nVerts) noexcept;
HRESULT SetVertexData(const DirectX::VBReader& reader, _In_ size_t nVerts) noexcept;
HRESULT Validate(_In_ DirectX::VALIDATE_FLAGS flags, _In_opt_ std::wstring* msgs) const noexcept;
@ -93,7 +93,7 @@ public:
const uint32_t* GetIndexBuffer() const noexcept { return mIndices.get(); }
std::unique_ptr<uint16_t[]> GetIndexBuffer16() const noexcept;
HRESULT GetVertexBuffer(_Inout_ DirectX::VBWriter& writer) const noexcept;
HRESULT GetVertexBuffer(const DirectX::VBWriter& writer) const noexcept;
// Save mesh to file
struct Material

View File

@ -237,7 +237,7 @@ void Mesh::ExportToOBJ(std::wostream& os, size_t nMaterials, const Material* mat
os << L"f ";
for (size_t point = 0; point < 3; ++point)
{
uint32_t i = mIndices[face * 3 + point] + 1;
const uint32_t i = mIndices[face * 3 + point] + 1;
os << i << L"/";
if (mTexCoords)

View File

@ -417,7 +417,7 @@ namespace
{
while (pValue->name)
{
size_t cchName = wcslen(pValue->name);
const size_t cchName = wcslen(pValue->name);
if (cch + cchName + 2 >= 80)
{
@ -440,7 +440,7 @@ namespace
wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, static_cast<DWORD>(std::size(appName))))
{
DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
const DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0)
{
auto verInfo = std::make_unique<uint8_t[]>(size);
@ -535,7 +535,7 @@ namespace
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
@ -546,9 +546,8 @@ namespace
swprintf_s(desc, L": %ls", errorText);
size_t len = wcslen(desc);
if (len >= 2)
if (len >= 1)
{
desc[len - 2] = 0;
desc[len - 1] = 0;
}
@ -564,7 +563,7 @@ namespace
{
static ULONGLONG s_lastTick = 0;
ULONGLONG tick = GetTickCount64();
const ULONGLONG tick = GetTickCount64();
if ((tick - s_lastTick) > 1000)
{
@ -639,7 +638,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (*pValue)
*pValue++ = 0;
uint64_t dwOption = LookupByName(pArg, g_pOptions);
const uint64_t dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption || (dwOptions & (uint64_t(1) << dwOption)))
{
@ -939,7 +938,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else if (wcspbrk(pArg, L"?*") != nullptr)
{
size_t count = conversion.size();
const size_t count = conversion.size();
SearchForFiles(pArg, conversion, (dwOptions & (uint64_t(1) << OPT_RECURSIVE)) != 0);
if (conversion.size() <= count)
{
@ -1024,7 +1023,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
size_t nVerts = inMesh->GetVertexCount();
size_t nFaces = inMesh->GetFaceCount();
const size_t nFaces = inMesh->GetFaceCount();
if (!nVerts || !nFaces)
{
@ -1073,7 +1072,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Prepare mesh for processing
{
// Adjacency
float epsilon = (dwOptions & (uint64_t(1) << OPT_GEOMETRIC_ADJ)) ? 1e-5f : 0.f;
const float epsilon = (dwOptions & (uint64_t(1) << OPT_GEOMETRIC_ADJ)) ? 1e-5f : 0.f;
hr = inMesh->GenerateAdjacency(epsilon);
if (FAILED(hr))
@ -1102,7 +1101,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else
{
size_t nNewVerts = inMesh->GetVertexCount();
const size_t nNewVerts = inMesh->GetVertexCount();
if (nVerts != nNewVerts)
{
wprintf(L" [%zu vertex dups] ", nNewVerts - nVerts);