Skip to content

Commit 1010fbc

Browse files
GLTF Viewer: don't use auto where unnecessary
1 parent 969dc69 commit 1010fbc

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

Samples/GLTFViewer/src/GLTFViewer.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void GLTFViewer::LoadModel(const char* Path)
182182
m_CameraId = 0;
183183
m_CameraNodes.clear();
184184
m_LightNodes.clear();
185-
for (const auto* node : m_Model->Scenes[m_RenderParams.SceneIndex].LinearNodes)
185+
for (const GLTF::Node* node : m_Model->Scenes[m_RenderParams.SceneIndex].LinearNodes)
186186
{
187187
if (node->pCamera != nullptr && node->pCamera->Type == GLTF::Camera::Projection::Perspective)
188188
m_CameraNodes.push_back(node);
@@ -235,7 +235,7 @@ void GLTFViewer::UpdateScene()
235235
MaxDim = std::max(MaxDim, ModelDim.z);
236236

237237
m_SceneScale = (1.0f / std::max(MaxDim, 0.01f)) * 0.5f;
238-
auto Translate = -m_ModelAABB.Min - 0.5f * ModelDim;
238+
float3 Translate = -m_ModelAABB.Min - 0.5f * ModelDim;
239239
float4x4 InvYAxis = float4x4::Identity();
240240
InvYAxis._22 = -1;
241241

@@ -257,7 +257,7 @@ void GLTFViewer::UpdateModelsList(const std::string& Dir)
257257
#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_MACOS
258258
if (!Dir.empty())
259259
{
260-
auto SearchRes = FileSystem::SearchRecursive(Dir.c_str(), "*.gltf");
260+
FileSystem::SearchFilesResult SearchRes = FileSystem::SearchRecursive(Dir.c_str(), "*.gltf");
261261
for (const auto& File : SearchRes)
262262
{
263263
m_Models.push_back(ModelInfo{File.Name, Dir + FileSystem::SlashSymbol + File.Name});
@@ -289,13 +289,13 @@ GLTFViewer::CommandLineStatus GLTFViewer::ProcessCommandLine(int argc, const cha
289289

290290
void GLTFViewer::CreateGLTFResourceCache()
291291
{
292-
auto InputLayout = GLTF::VertexAttributesToInputLayout(GLTF::DefaultVertexAttributes.data(), static_cast<Uint32>(GLTF::DefaultVertexAttributes.size()));
293-
auto Strides = InputLayout.ResolveAutoOffsetsAndStrides();
292+
InputLayoutDescX InputLayout = GLTF::VertexAttributesToInputLayout(GLTF::DefaultVertexAttributes.data(), static_cast<Uint32>(GLTF::DefaultVertexAttributes.size()));
293+
std::vector<Uint32> Strides = InputLayout.ResolveAutoOffsetsAndStrides();
294294

295295
std::vector<VertexPoolElementDesc> VtxPoolElems;
296296
VtxPoolElems.reserve(Strides.size());
297297
m_CacheUseInfo.VtxLayoutKey.Elements.reserve(Strides.size());
298-
for (const auto& Stride : Strides)
298+
for (const Uint32& Stride : Strides)
299299
{
300300
VtxPoolElems.emplace_back(Stride, BIND_VERTEX_BUFFER);
301301
m_CacheUseInfo.VtxLayoutKey.Elements.emplace_back(Stride, BIND_VERTEX_BUFFER);
@@ -363,7 +363,7 @@ static RefCntAutoPtr<ITextureView> CreateWhiteFurnaceEnvMap(IRenderDevice* pDevi
363363

364364
std::vector<Uint32> Data(6 * TexDesc.Width * TexDesc.Height, 0xFFFFFFFFu);
365365
std::vector<TextureSubResData> SubResData(6);
366-
for (auto& Subres : SubResData)
366+
for (TextureSubResData& Subres : SubResData)
367367
{
368368
Subres.pData = Data.data();
369369
Subres.Stride = TexDesc.Width * sizeof(Uint32);
@@ -570,8 +570,8 @@ void GLTFViewer::CreateGLTFRenderer()
570570
// Reset environment map in GLTF renderer
571571
if (m_pCurrentEnvMapSRV != nullptr)
572572
{
573-
auto* pEnvMap = m_pCurrentEnvMapSRV;
574-
m_pCurrentEnvMapSRV = nullptr;
573+
ITextureView* pEnvMap = m_pCurrentEnvMapSRV;
574+
m_pCurrentEnvMapSRV = nullptr;
575575
SetEnvironmentMap(pEnvMap);
576576
}
577577
}
@@ -749,8 +749,8 @@ void GLTFViewer::ApplyPosteffects::Initialize(IRenderDevice* pDevice, TEXTURE_FO
749749
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
750750
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_PACK_MATRIX_ROW_MAJOR;
751751

752-
auto pCompoundSourceFactory = CreateCompoundShaderSourceFactory(pDevice);
753-
ShaderCI.pShaderSourceStreamFactory = pCompoundSourceFactory;
752+
RefCntAutoPtr<IShaderSourceInputStreamFactory> pCompoundSourceFactory = CreateCompoundShaderSourceFactory(pDevice);
753+
ShaderCI.pShaderSourceStreamFactory = pCompoundSourceFactory;
754754

755755
ShaderMacroHelper Macros;
756756
Macros.Add("CONVERT_OUTPUT_TO_SRGB", RTVFormat == TEX_FORMAT_RGBA8_UNORM || RTVFormat == TEX_FORMAT_BGRA8_UNORM);
@@ -834,7 +834,7 @@ void GLTFViewer::UpdateUI()
834834
FileDialogAttribs OpenDialogAttribs{FILE_DIALOG_TYPE_OPEN};
835835
OpenDialogAttribs.Title = "Select GLTF file";
836836
OpenDialogAttribs.Filter = "glTF files\0*.gltf;*.glb\0";
837-
auto FileName = FileSystem::FileDialog(OpenDialogAttribs);
837+
std::string FileName = FileSystem::FileDialog(OpenDialogAttribs);
838838
if (!FileName.empty())
839839
{
840840
LoadModel(FileName.c_str());
@@ -846,7 +846,7 @@ void GLTFViewer::UpdateUI()
846846
FileDialogAttribs OpenDialogAttribs{FILE_DIALOG_TYPE_OPEN};
847847
OpenDialogAttribs.Title = "Select HDR file";
848848
OpenDialogAttribs.Filter = "HDR files (*.hdr)\0*.hdr;\0All files\0*.*\0\0";
849-
auto FileName = FileSystem::FileDialog(OpenDialogAttribs);
849+
std::string FileName = FileSystem::FileDialog(OpenDialogAttribs);
850850
if (!FileName.empty())
851851
LoadEnvironmentMap(FileName.data());
852852
}
@@ -870,7 +870,7 @@ void GLTFViewer::UpdateUI()
870870
CamList.emplace_back(0, "default");
871871
for (Uint32 i = 0; i < m_CameraNodes.size(); ++i)
872872
{
873-
const auto& Cam = *m_CameraNodes[i]->pCamera;
873+
const GLTF::Camera& Cam = *m_CameraNodes[i]->pCamera;
874874
CamList.emplace_back(i + 1, Cam.Name.empty() ? std::to_string(i) : Cam.Name);
875875
}
876876

@@ -880,7 +880,7 @@ void GLTFViewer::UpdateUI()
880880

881881
if (m_CameraId == 0)
882882
{
883-
auto ModelRotation = m_Camera.GetSecondaryRotation();
883+
QuaternionF ModelRotation = m_Camera.GetSecondaryRotation();
884884
if (ImGui::gizmo3D("Model Rotation", ModelRotation, ImGui::GetTextLineHeight() * 10))
885885
m_Camera.SetSecondaryRotation(ModelRotation);
886886
ImGui::SameLine();
@@ -894,7 +894,7 @@ void GLTFViewer::UpdateUI()
894894
m_Camera.ResetDefaults();
895895
}
896896

897-
auto CameraDist = m_Camera.GetDist();
897+
float CameraDist = m_Camera.GetDist();
898898
if (ImGui::SliderFloat("Camera distance", &CameraDist, m_Camera.GetMinDist(), m_Camera.GetMaxDist()))
899899
m_Camera.SetDist(CameraDist);
900900
}
@@ -1166,10 +1166,10 @@ void GLTFViewer::Render()
11661166
}
11671167

11681168

1169-
const auto& CurrCamAttribs = m_CameraAttribs[m_CurrentFrameNumber & 0x01];
1170-
const auto& PrevCamAttribs = m_CameraAttribs[(m_CurrentFrameNumber + 1) & 0x01];
1171-
const auto& CurrTransforms = m_Transforms[m_CurrentFrameNumber & 0x01];
1172-
const auto& PrevTransforms = m_Transforms[(m_CurrentFrameNumber + 1) & 0x01];
1169+
const HLSL::CameraAttribs& CurrCamAttribs = m_CameraAttribs[m_CurrentFrameNumber & 0x01];
1170+
const HLSL::CameraAttribs& PrevCamAttribs = m_CameraAttribs[(m_CurrentFrameNumber + 1) & 0x01];
1171+
const GLTF::ModelTransforms& CurrTransforms = m_Transforms[m_CurrentFrameNumber & 0x01];
1172+
const GLTF::ModelTransforms& PrevTransforms = m_Transforms[(m_CurrentFrameNumber + 1) & 0x01];
11731173

11741174
{
11751175
MapHelper<HLSL::PBRFrameAttribs> FrameAttribs{m_pImmediateContext, m_FrameAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD};
@@ -1202,8 +1202,8 @@ void GLTFViewer::Render()
12021202
}
12031203
else if (m_BoundBoxMode == BoundBoxMode::Global)
12041204
{
1205-
auto TransformedBB = m_ModelAABB.Transform(m_RenderParams.ModelTransform);
1206-
m_BoundBoxTransform = float4x4::Scale(TransformedBB.Max - TransformedBB.Min) * float4x4::Translation(TransformedBB.Min);
1205+
BoundBox TransformedBB = m_ModelAABB.Transform(m_RenderParams.ModelTransform);
1206+
m_BoundBoxTransform = float4x4::Scale(TransformedBB.Max - TransformedBB.Min) * float4x4::Translation(TransformedBB.Min);
12071207
}
12081208
else
12091209
{
@@ -1218,14 +1218,14 @@ void GLTFViewer::Render()
12181218
# error PBR_MAX_LIGHTS should not be defined here
12191219
#endif
12201220
// Light data follows the render attributes
1221-
auto* Lights = reinterpret_cast<HLSL::PBRLightAttribs*>(FrameAttribs + 1);
1221+
HLSL::PBRLightAttribs* Lights = reinterpret_cast<HLSL::PBRLightAttribs*>(FrameAttribs + 1);
12221222
if (!m_LightNodes.empty())
12231223
{
12241224
LightCount = std::min(static_cast<Uint32>(m_LightNodes.size()), m_GLTFRenderer->GetSettings().MaxLightCount);
12251225
for (int i = 0; i < LightCount; ++i)
12261226
{
1227-
const auto& LightNode = *m_LightNodes[i];
1228-
const auto LightGlobalTransform = m_Transforms[m_CurrentFrameNumber & 0x01].NodeGlobalMatrices[LightNode.Index] * m_RenderParams.ModelTransform;
1227+
const GLTF::Node& LightNode = *m_LightNodes[i];
1228+
const float4x4 LightGlobalTransform = m_Transforms[m_CurrentFrameNumber & 0x01].NodeGlobalMatrices[LightNode.Index] * m_RenderParams.ModelTransform;
12291229

12301230
// The light direction is along the negative Z axis of the light's local space.
12311231
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual#adding-light-instances-to-nodes
@@ -1242,7 +1242,7 @@ void GLTFViewer::Render()
12421242
}
12431243
}
12441244
{
1245-
auto& Renderer = FrameAttribs->Renderer;
1245+
HLSL::PBRRendererShaderParameters& Renderer = FrameAttribs->Renderer;
12461246
m_GLTFRenderer->SetInternalShaderParameters(Renderer);
12471247

12481248
Renderer.OcclusionStrength = m_ShaderAttribs.OcclusionStrength;
@@ -1269,7 +1269,7 @@ void GLTFViewer::Render()
12691269
}
12701270

12711271
auto RenderModel = [&](GLTF_PBR_Renderer::RenderInfo::ALPHA_MODE_FLAGS AlphaModes) {
1272-
const auto OrigAlphaModes = m_RenderParams.AlphaModes;
1272+
const GLTF_PBR_Renderer::RenderInfo::ALPHA_MODE_FLAGS OrigAlphaModes = m_RenderParams.AlphaModes;
12731273

12741274
m_RenderParams.AlphaModes &= AlphaModes;
12751275
if (m_RenderParams.AlphaModes != GLTF_PBR_Renderer::RenderInfo::ALPHA_MODE_FLAG_NONE)
@@ -1449,9 +1449,9 @@ void GLTFViewer::Update(double CurrTime, double ElapsedTime)
14491449
}
14501450
else
14511451
{
1452-
const auto* pCameraNode = m_CameraNodes[m_CameraId - 1];
1453-
const auto* pCamera = pCameraNode->pCamera;
1454-
const auto& CameraGlobalTransform = m_Transforms[m_CurrentFrameNumber & 0x01].NodeGlobalMatrices[pCameraNode->Index];
1452+
const GLTF::Node* pCameraNode = m_CameraNodes[m_CameraId - 1];
1453+
const GLTF::Camera* pCamera = pCameraNode->pCamera;
1454+
const float4x4& CameraGlobalTransform = m_Transforms[m_CurrentFrameNumber & 0x01].NodeGlobalMatrices[pCameraNode->Index];
14551455

14561456
// GLTF camera is defined such that the local +X axis is to the right,
14571457
// the lens looks towards the local -Z axis, and the top of the camera
@@ -1475,14 +1475,14 @@ void GLTFViewer::Update(double CurrTime, double ElapsedTime)
14751475
float4x4 CameraWorld = CameraView.Inverse();
14761476

14771477
// Get projection matrix adjusted to the current screen orientation
1478-
const auto CameraProj = GetAdjustedProjectionMatrix(YFov, ZNear, ZFar);
1479-
const auto CameraViewProj = CameraView * CameraProj;
1478+
const float4x4 CameraProj = GetAdjustedProjectionMatrix(YFov, ZNear, ZFar);
1479+
const float4x4 CameraViewProj = CameraView * CameraProj;
14801480

14811481
float3 CameraWorldPos = float3::MakeVector(CameraWorld[3]);
14821482

1483-
auto& CurrCamAttribs = m_CameraAttribs[m_CurrentFrameNumber & 0x01];
1483+
HLSL::CameraAttribs& CurrCamAttribs = m_CameraAttribs[m_CurrentFrameNumber & 0x01];
14841484

1485-
const auto& SCDesc = m_pSwapChain->GetDesc();
1485+
const SwapChainDesc& SCDesc = m_pSwapChain->GetDesc();
14861486

14871487
CurrCamAttribs.f4ViewportSize = float4{static_cast<float>(SCDesc.Width), static_cast<float>(SCDesc.Height), 1.f / SCDesc.Width, 1.f / SCDesc.Height};
14881488
CurrCamAttribs.fNearPlaneZ = ZNear;

0 commit comments

Comments
 (0)