Skip to content

Commit 4cae36b

Browse files
Code refactoring: don't use auto where unnecessary
1 parent b5d1cc8 commit 4cae36b

File tree

20 files changed

+188
-188
lines changed

20 files changed

+188
-188
lines changed

AssetLoader/src/DXSDKMeshLoader.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,25 +54,25 @@ void DXSDKMesh::ComputeBoundingBoxes()
5454
{
5555
for (Uint32 i = 0; i < m_pMeshHeader->NumMeshes; i++)
5656
{
57-
auto& Mesh = m_pMeshArray[i];
57+
DXSDKMESH_MESH& Mesh = m_pMeshArray[i];
5858

5959
float3 Min{+FLT_MAX, +FLT_MAX, +FLT_MAX};
6060
float3 Max{-FLT_MAX, -FLT_MAX, -FLT_MAX};
6161

62-
const auto& VertexData = m_pVertexBufferArray[Mesh.VertexBuffers[0]];
63-
auto* PosDecl = VertexData.Decl;
62+
const DXSDKMESH_VERTEX_BUFFER_HEADER& VertexData = m_pVertexBufferArray[Mesh.VertexBuffers[0]];
63+
const DXSDKMESH_VERTEX_ELEMENT* PosDecl = VertexData.Decl;
6464
while (PosDecl->Stream != 0xFF && PosDecl->Usage != DXSDKMESH_VERTEX_SEMANTIC_POSITION)
6565
++PosDecl;
6666
VERIFY(PosDecl->Stream != 0xFF, "Position semantic not found in this buffer");
6767
VERIFY(PosDecl->Type == DXSDKMESH_VERTEX_DATA_TYPE_FLOAT3, "Vertex is expected to be a 3-component float vector");
6868

69-
auto IndexType = GetIndexType(i);
70-
const auto* Vertices = GetRawVerticesAt(Mesh.VertexBuffers[0]);
71-
const auto* Indices = GetRawIndicesAt(Mesh.IndexBuffer);
72-
auto Stride = GetVertexStride(Mesh.VertexBuffers[0]);
69+
DXSDKMESH_INDEX_TYPE IndexType = GetIndexType(i);
70+
const Uint8* Vertices = GetRawVerticesAt(Mesh.VertexBuffers[0]);
71+
const Uint8* Indices = GetRawIndicesAt(Mesh.IndexBuffer);
72+
Uint32 Stride = GetVertexStride(Mesh.VertexBuffers[0]);
7373
for (Uint32 subsetIdx = 0; subsetIdx < Mesh.NumSubsets; ++subsetIdx)
7474
{
75-
auto& Subset = m_pSubsetArray[Mesh.pSubsets[subsetIdx]];
75+
DXSDKMESH_SUBSET& Subset = m_pSubsetArray[Mesh.pSubsets[subsetIdx]];
7676

7777
for (Uint32 v = 0; v < Subset.IndexCount; ++v)
7878
{
@@ -97,7 +97,7 @@ bool DXSDKMesh::CreateFromMemory(const Uint8* pData, Uint32 DataUint8s)
9797
memcpy(m_StaticMeshData.data(), pData, DataUint8s);
9898

9999
// Pointer fixup
100-
auto* pStaticMeshData = m_StaticMeshData.data();
100+
Uint8* pStaticMeshData = m_StaticMeshData.data();
101101
// clang-format off
102102
m_pMeshHeader = reinterpret_cast<DXSDKMESH_HEADER*> (pStaticMeshData);
103103
m_pVertexBufferArray = reinterpret_cast<DXSDKMESH_VERTEX_BUFFER_HEADER*>(pStaticMeshData + m_pMeshHeader->VertexStreamHeadersOffset);
@@ -110,7 +110,7 @@ bool DXSDKMesh::CreateFromMemory(const Uint8* pData, Uint32 DataUint8s)
110110

111111
for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
112112
{
113-
auto& Mat = m_pMaterialArray[i];
113+
DXSDKMESH_MATERIAL& Mat{m_pMaterialArray[i]};
114114
Mat.pDiffuseTexture = nullptr;
115115
Mat.pNormalTexture = nullptr;
116116
Mat.pSpecularTexture = nullptr;
@@ -193,7 +193,7 @@ void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* p
193193
std::vector<StateTransitionDesc> Barriers;
194194
for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
195195
{
196-
auto& Mat = m_pMaterialArray[i];
196+
DXSDKMESH_MATERIAL& Mat = m_pMaterialArray[i];
197197
if (Mat.DiffuseTexture[0] != 0)
198198
{
199199
LoadTexture(pDevice, ResourceDirectory, Mat.DiffuseTexture, true, &Mat.pDiffuseTexture, &Mat.pDiffuseRV, Barriers);
@@ -213,7 +213,7 @@ void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* p
213213
m_VertexBuffers.resize(m_pMeshHeader->NumVertexBuffers);
214214
for (Uint32 i = 0; i < m_pMeshHeader->NumVertexBuffers; i++)
215215
{
216-
const auto& VBArr = m_pVertexBufferArray[i];
216+
const DXSDKMESH_VERTEX_BUFFER_HEADER& VBArr = m_pVertexBufferArray[i];
217217

218218
std::stringstream ss;
219219
ss << "DXSDK Mesh vertex buffer #" << i;
@@ -234,7 +234,7 @@ void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* p
234234
m_IndexBuffers.resize(m_pMeshHeader->NumIndexBuffers);
235235
for (Uint32 i = 0; i < m_pMeshHeader->NumIndexBuffers; i++)
236236
{
237-
const auto& IBArr = m_pIndexBufferArray[i];
237+
const DXSDKMESH_INDEX_BUFFER_HEADER& IBArr = m_pIndexBufferArray[i];
238238

239239
std::stringstream ss;
240240
ss << "DXSDK Mesh index buffer #" << i;
@@ -278,7 +278,7 @@ void DXSDKMesh::Destroy()
278278
{
279279
for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
280280
{
281-
auto& Mat = m_pMaterialArray[i];
281+
DXSDKMESH_MATERIAL& Mat = m_pMaterialArray[i];
282282
if (Mat.pDiffuseTexture)
283283
Mat.pDiffuseTexture->Release();
284284

AssetLoader/src/GLTFBuilder.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ size_t ModelBuilder::PrimitiveKey::Hasher::operator()(const PrimitiveKey& Key) c
5151
if (Key.Hash == 0)
5252
{
5353
Key.Hash = ComputeHash(Key.AccessorIds.size());
54-
for (auto Id : Key.AccessorIds)
54+
for (int Id : Key.AccessorIds)
5555
HashCombine(Key.Hash, Id);
5656
}
5757
return Key.Hash;
@@ -79,7 +79,7 @@ inline Uint8 ConvertElement<Uint8, false, float>(float Src)
7979
template <>
8080
inline Int8 ConvertElement<Int8, true, float>(float Src)
8181
{
82-
auto r = Src > 0.f ? +0.5f : -0.5f;
82+
float r = Src > 0.f ? +0.5f : -0.5f;
8383
return static_cast<Int8>(clamp(Src * 127.f + r, -127.f, 127.f));
8484
}
8585

@@ -128,7 +128,7 @@ inline void WriteGltfData(const void* pSrc,
128128
{
129129
for (size_t elem = 0; elem < NumElements; ++elem)
130130
{
131-
const auto* pSrcCmp = reinterpret_cast<const SrcType*>(static_cast<const Uint8*>(pSrc) + SrcElemStride * elem);
131+
const SrcType* pSrcCmp = reinterpret_cast<const SrcType*>(static_cast<const Uint8*>(pSrc) + SrcElemStride * elem);
132132

133133
auto comp_it = dst_it + DstElementStride * elem;
134134
for (Uint32 cmp = 0; cmp < NumComponents; ++cmp, comp_it += sizeof(DstType))
@@ -140,7 +140,7 @@ inline void WriteGltfData(const void* pSrc,
140140

141141
void ModelBuilder::WriteGltfData(const WriteGltfDataAttribs& Attribs)
142142
{
143-
const auto NumComponentsToCopy = std::min(Attribs.NumSrcComponents, Attribs.NumDstComponents);
143+
const Uint32 NumComponentsToCopy = std::min(Attribs.NumSrcComponents, Attribs.NumDstComponents);
144144

145145
#define INNER_CASE(SrcType, DstType) \
146146
case DstType: \
@@ -205,7 +205,7 @@ void ModelBuilder::WriteDefaultAttibuteValue(const void* pDefau
205205
Uint32 DstElementStride,
206206
Uint32 NumElements)
207207
{
208-
auto ElementSize = GetValueSize(DstType) * NumDstComponents;
208+
Uint32 ElementSize = GetValueSize(DstType) * NumDstComponents;
209209
VERIFY(DstElementStride >= ElementSize, "Destination element stride is too small");
210210
for (size_t elem = 0; elem < NumElements; ++elem)
211211
{
@@ -216,13 +216,13 @@ void ModelBuilder::WriteDefaultAttibuteValue(const void* pDefau
216216

217217
void ModelBuilder::WriteDefaultAttibutes(Uint32 BufferId, size_t StartOffset, size_t EndOffset)
218218
{
219-
const auto VertexStride = m_Model.VertexData.Strides[BufferId];
219+
const Uint32 VertexStride = m_Model.VertexData.Strides[BufferId];
220220
VERIFY(StartOffset % VertexStride == 0, "Start offset is not aligned to vertex stride");
221221
VERIFY(EndOffset % VertexStride == 0, "End offset is not aligned to vertex stride");
222-
const auto NumVertices = static_cast<Uint32>((EndOffset - StartOffset) / VertexStride);
222+
const Uint32 NumVertices = static_cast<Uint32>((EndOffset - StartOffset) / VertexStride);
223223
for (Uint32 i = 0; i < m_Model.GetNumVertexAttributes(); ++i)
224224
{
225-
const auto& Attrib = m_Model.VertexAttributes[i];
225+
const VertexAttributeDesc& Attrib = m_Model.VertexAttributes[i];
226226
if (BufferId != Attrib.BufferId || Attrib.pDefaultValue == nullptr)
227227
continue;
228228

@@ -244,14 +244,14 @@ void ModelBuilder::InitIndexBuffer(IRenderDevice* pDevice)
244244
VERIFY_EXPR((m_IndexData.size() % m_Model.IndexData.IndexSize) == 0);
245245
VERIFY(!m_Model.IndexData.pBuffer && !m_Model.IndexData.pAllocation, "Index buffer has already been initialized");
246246

247-
const auto DataSize = static_cast<Uint32>(m_IndexData.size());
247+
const Uint32 DataSize = static_cast<Uint32>(m_IndexData.size());
248248
if (m_CI.pResourceManager != nullptr)
249249
{
250250
m_Model.IndexData.pAllocation = m_CI.pResourceManager->AllocateIndices(DataSize, 4);
251251

252252
if (m_Model.IndexData.pAllocation)
253253
{
254-
auto pBuffInitData = BufferInitData::Create();
254+
RefCntAutoPtr<BufferInitData> pBuffInitData = BufferInitData::Create();
255255
pBuffInitData->Data.emplace_back(std::move(m_IndexData));
256256
m_Model.IndexData.pAllocation->SetUserData(pBuffInitData);
257257

@@ -265,8 +265,8 @@ void ModelBuilder::InitIndexBuffer(IRenderDevice* pDevice)
265265
}
266266
else
267267
{
268-
const auto BindFlags = m_CI.IndBufferBindFlags != BIND_NONE ? m_CI.IndBufferBindFlags : BIND_INDEX_BUFFER;
269-
BufferDesc BuffDesc{"GLTF index buffer", DataSize, BindFlags, USAGE_IMMUTABLE};
268+
const BIND_FLAGS BindFlags = m_CI.IndBufferBindFlags != BIND_NONE ? m_CI.IndBufferBindFlags : BIND_INDEX_BUFFER;
269+
BufferDesc BuffDesc{"GLTF index buffer", DataSize, BindFlags, USAGE_IMMUTABLE};
270270
if (BuffDesc.BindFlags & (BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS))
271271
{
272272
BuffDesc.Mode = BUFFER_MODE_FORMATTED;
@@ -286,7 +286,7 @@ void ModelBuilder::InitVertexBuffers(IRenderDevice* pDevice)
286286
return;
287287
}
288288

289-
const auto VBCount = m_Model.GetVertexBufferCount();
289+
const size_t VBCount = m_Model.GetVertexBufferCount();
290290
VERIFY_EXPR(m_VertexData.size() == VBCount);
291291

292292
size_t NumVertices = 0;
@@ -317,16 +317,16 @@ void ModelBuilder::InitVertexBuffers(IRenderDevice* pDevice)
317317
LayoutKey.Elements.reserve(VBCount);
318318
for (Uint32 i = 0; i < VBCount; ++i)
319319
{
320-
const auto BindFlags = m_CI.VertBufferBindFlags[i] != BIND_NONE ? m_CI.VertBufferBindFlags[i] : BIND_VERTEX_BUFFER;
320+
const BIND_FLAGS BindFlags = m_CI.VertBufferBindFlags[i] != BIND_NONE ? m_CI.VertBufferBindFlags[i] : BIND_VERTEX_BUFFER;
321321
LayoutKey.Elements.emplace_back(m_Model.VertexData.Strides[i], BindFlags);
322322
}
323323

324324
VERIFY(!m_Model.VertexData.pAllocation, "This vertex buffer has already been initialized");
325325
m_Model.VertexData.pAllocation = m_CI.pResourceManager->AllocateVertices(LayoutKey, static_cast<Uint32>(NumVertices));
326326
if (m_Model.VertexData.pAllocation)
327327
{
328-
auto pBuffInitData = BufferInitData::Create();
329-
pBuffInitData->Data = std::move(m_VertexData);
328+
RefCntAutoPtr<BufferInitData> pBuffInitData = BufferInitData::Create();
329+
pBuffInitData->Data = std::move(m_VertexData);
330330
m_Model.VertexData.pAllocation->SetUserData(pBuffInitData);
331331
m_Model.VertexData.PoolId = m_CI.pResourceManager->GetVertexPoolIndex(LayoutKey, m_Model.VertexData.pAllocation->GetPool());
332332
VERIFY_EXPR(m_Model.VertexData.PoolId != ~0u);
@@ -342,16 +342,16 @@ void ModelBuilder::InitVertexBuffers(IRenderDevice* pDevice)
342342
m_Model.VertexData.Buffers.resize(VBCount);
343343
for (Uint32 i = 0; i < VBCount; ++i)
344344
{
345-
const auto& Data = m_VertexData[i];
345+
const std::vector<Uint8>& Data = m_VertexData[i];
346346
if (Data.empty())
347347
continue;
348348

349-
const auto DataSize = static_cast<Uint32>(Data.size());
350-
const auto Name = std::string{"GLTF vertex buffer "} + std::to_string(i);
351-
const auto BindFlags = m_CI.VertBufferBindFlags[i] != BIND_NONE ? m_CI.VertBufferBindFlags[i] : BIND_VERTEX_BUFFER;
352-
BufferDesc BuffDesc{Name.c_str(), DataSize, BindFlags, USAGE_IMMUTABLE};
349+
const Uint32 DataSize = static_cast<Uint32>(Data.size());
350+
const std::string Name = std::string{"GLTF vertex buffer "} + std::to_string(i);
351+
const BIND_FLAGS BindFlags = m_CI.VertBufferBindFlags[i] != BIND_NONE ? m_CI.VertBufferBindFlags[i] : BIND_VERTEX_BUFFER;
352+
BufferDesc BuffDesc{Name.c_str(), DataSize, BindFlags, USAGE_IMMUTABLE};
353353

354-
const auto ElementStride = m_Model.VertexData.Strides[i];
354+
const Uint32 ElementStride = m_Model.VertexData.Strides[i];
355355
VERIFY_EXPR(ElementStride > 0);
356356
VERIFY_EXPR(Data.size() % ElementStride == 0);
357357

AssetLoader/src/GLTFResourceManager.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,8 +41,8 @@ namespace GLTF
4141

4242
size_t ResourceManager::VertexLayoutKey::Hasher::operator()(const VertexLayoutKey& Key) const
4343
{
44-
auto Hash = ComputeHash(Key.Elements.size());
45-
for (const auto& Elem : Key.Elements)
44+
size_t Hash = ComputeHash(Key.Elements.size());
45+
for (const ElementDesc& Elem : Key.Elements)
4646
HashCombine(Hash, Elem.Size, Elem.BindFlags);
4747
return Hash;
4848
}
@@ -88,13 +88,13 @@ ResourceManager::ResourceManager(IReferenceCounters* pRefCounters,
8888
m_VertexPoolCIs.reserve(CI.NumVertexPools);
8989
for (Uint32 pool = 0; pool < CI.NumVertexPools; ++pool)
9090
{
91-
const auto& PoolCI = CI.pVertexPoolCIs[pool];
91+
const VertexPoolCreateInfo& PoolCI = CI.pVertexPoolCIs[pool];
9292

9393
VertexLayoutKey Key;
9494
Key.Elements.reserve(PoolCI.Desc.NumElements);
9595
for (size_t i = 0; i < PoolCI.Desc.NumElements; ++i)
9696
{
97-
const auto& PoolElem = PoolCI.Desc.pElements[i];
97+
const VertexPoolElementDesc& PoolElem = PoolCI.Desc.pElements[i];
9898
Key.Elements.emplace_back(PoolElem.Size, PoolElem.BindFlags);
9999
}
100100

@@ -112,7 +112,7 @@ ResourceManager::ResourceManager(IReferenceCounters* pRefCounters,
112112
m_Atlases.reserve(CI.NumTexAtlases);
113113
for (Uint32 i = 0; i < CI.NumTexAtlases; ++i)
114114
{
115-
const auto& AtlasCI = CI.pTexAtlasCIs[i];
115+
const DynamicTextureAtlasCreateInfo& AtlasCI = CI.pTexAtlasCIs[i];
116116

117117
RefCntAutoPtr<IDynamicTextureAtlas> pAtlas;
118118
CreateDynamicTextureAtlas(pDevice, AtlasCI, &pAtlas);
@@ -171,8 +171,8 @@ RefCntAutoPtr<ITextureAtlasSuballocation> ResourceManager::AllocateTextureSpace(
171171
return {};
172172
}
173173

174-
auto AtalsCreateInfo = m_DefaultAtlasDesc;
175-
AtalsCreateInfo.Desc.Format = Fmt;
174+
DynamicTextureAtlasCreateInfo AtalsCreateInfo = m_DefaultAtlasDesc;
175+
AtalsCreateInfo.Desc.Format = Fmt;
176176

177177
RefCntAutoPtr<IDynamicTextureAtlas> pAtlas;
178178
CreateDynamicTextureAtlas(nullptr, AtalsCreateInfo, &pAtlas);
@@ -257,7 +257,7 @@ RefCntAutoPtr<IVertexPool> ResourceManager::CreateVertexPoolForLayout(const Vert
257257
std::vector<VertexPoolElementDesc> PoolElems(Key.Elements.size());
258258
for (size_t i = 0; i < PoolElems.size(); ++i)
259259
{
260-
auto& ElemDesc = PoolElems[i];
260+
VertexPoolElementDesc& ElemDesc = PoolElems[i];
261261

262262
ElemDesc.Size = Key.Elements[i].Size;
263263
ElemDesc.BindFlags = Key.Elements[i].BindFlags;
@@ -284,7 +284,7 @@ RefCntAutoPtr<IVertexPoolAllocation> ResourceManager::AllocateVertices(const Ver
284284
{
285285
#ifdef DILIGENT_DEVELOPMENT
286286
DEV_CHECK_ERR(!LayoutKey.Elements.empty(), "The key must not be empty.");
287-
for (const auto& Elem : LayoutKey.Elements)
287+
for (const VertexLayoutKey::ElementDesc& Elem : LayoutKey.Elements)
288288
{
289289
DEV_CHECK_ERR(Elem.Size != 0, "Element size must not be zero.");
290290
DEV_CHECK_ERR(Elem.BindFlags != BIND_NONE, "Bind flags must not be NONE.");

HLSL2GLSLConverter/src/HLSL2GLSLConverterApp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int HLSL2GLSLConverterApp::ParseCmdLine(int argc, char** argv)
119119

120120
m_InputPath = InputArg.Get();
121121
m_OutputPath = OutputArg.Get();
122-
for (const auto& Dir : SearDirsArg.Get())
122+
for (const std::string& Dir : SearDirsArg.Get())
123123
{
124124
if (!m_SearchDirectories.empty())
125125
m_SearchDirectories.push_back(';');
@@ -162,10 +162,10 @@ int HLSL2GLSLConverterApp::Convert(IRenderDevice* pDevice)
162162
{
163163
return -1;
164164
}
165-
auto pHLSLSourceBlob = DataBlobImpl::Create();
165+
RefCntAutoPtr<DataBlobImpl> pHLSLSourceBlob = DataBlobImpl::Create();
166166
pInputFileStream->ReadBlob(pHLSLSourceBlob);
167167
char* HLSLSource = pHLSLSourceBlob->GetDataPtr<char>();
168-
auto SourceLen = static_cast<Int32>(pHLSLSourceBlob->GetSize());
168+
Int32 SourceLen = static_cast<Int32>(pHLSLSourceBlob->GetSize());
169169

170170
RefCntAutoPtr<IHLSL2GLSLConverter> pConverter;
171171
CreateHLSL2GLSLConverter(&pConverter);

HLSL2GLSLConverter/src/HLSL2GLSLConverterAppWin32.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -76,7 +76,7 @@ int main(int argc, char** argv)
7676
HLSL2GLSLConverterApp Converter;
7777

7878
{
79-
auto ret = Converter.ParseCmdLine(argc, argv);
79+
int ret = Converter.ParseCmdLine(argc, argv);
8080
if (ret != 0)
8181
return ret;
8282
}
@@ -108,7 +108,7 @@ int main(int argc, char** argv)
108108
SwapChainDesc SCDesc;
109109
EngineCI.Window.hWnd = wnd;
110110

111-
auto* pFactory = Converter.GetFactoryGL();
111+
IEngineFactoryOpenGL* pFactory = Converter.GetFactoryGL();
112112
pFactory->CreateDeviceAndSwapChainGL(
113113
EngineCI, &pDevice, &pContext, SCDesc, &pSwapChain);
114114
if (!pDevice)

0 commit comments

Comments
 (0)