Skip to content

Commit f8fc896

Browse files
Tutorials: don't use auto where unnecessary
1 parent 46a7437 commit f8fc896

File tree

35 files changed

+544
-538
lines changed

35 files changed

+544
-538
lines changed

Tutorials/Tutorial00_HelloWin32/src/Tutorial00_HelloWin32.cpp

Lines changed: 13 additions & 13 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");
@@ -147,9 +147,9 @@ class Tutorial00App
147147
EngineD3D11CreateInfo EngineCI;
148148
# if ENGINE_DLL
149149
// Load the dll and import GetEngineFactoryD3D11() function
150-
auto* GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
150+
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
151151
# endif
152-
auto* pFactoryD3D11 = GetEngineFactoryD3D11();
152+
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
153153
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &m_pDevice, &m_pImmediateContext);
154154
Win32NativeWindow Window{hWnd};
155155
pFactoryD3D11->CreateSwapChainD3D11(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain);
@@ -163,11 +163,11 @@ class Tutorial00App
163163
{
164164
# if ENGINE_DLL
165165
// Load the dll and import GetEngineFactoryD3D12() function
166-
auto GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
166+
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
167167
# endif
168168
EngineD3D12CreateInfo EngineCI;
169169

170-
auto* pFactoryD3D12 = GetEngineFactoryD3D12();
170+
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
171171
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &m_pDevice, &m_pImmediateContext);
172172
Win32NativeWindow Window{hWnd};
173173
pFactoryD3D12->CreateSwapChainD3D12(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain);
@@ -181,9 +181,9 @@ class Tutorial00App
181181
{
182182
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
183183
// Load the dll and import GetEngineFactoryOpenGL() function
184-
auto GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
184+
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
185185
# endif
186-
auto* pFactoryOpenGL = GetEngineFactoryOpenGL();
186+
IEngineFactoryOpenGL* pFactoryOpenGL = GetEngineFactoryOpenGL();
187187

188188
EngineGLCreateInfo EngineCI;
189189
EngineCI.Window.hWnd = hWnd;
@@ -199,11 +199,11 @@ class Tutorial00App
199199
{
200200
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
201201
// Load the dll and import GetEngineFactoryVk() function
202-
auto GetEngineFactoryVk = LoadGraphicsEngineVk();
202+
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
203203
# endif
204204
EngineVkCreateInfo EngineCI;
205205

206-
auto* pFactoryVk = GetEngineFactoryVk();
206+
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
207207
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &m_pDevice, &m_pImmediateContext);
208208

209209
if (!m_pSwapChain && hWnd != nullptr)
@@ -232,7 +232,7 @@ class Tutorial00App
232232
const char* Keys[] = {"--mode ", "--mode=", "-m "};
233233
for (size_t i = 0; i < _countof(Keys); ++i)
234234
{
235-
const auto* Key = Keys[i];
235+
const char* Key = Keys[i];
236236
if ((mode = strstr(CmdLine, Key)) != nullptr)
237237
{
238238
mode += strlen(Key);
@@ -367,8 +367,8 @@ class Tutorial00App
367367
{
368368
// Set render targets before issuing any draw command.
369369
// Note that Present() unbinds the back buffer if it is set as render target.
370-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
371-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
370+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
371+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
372372
m_pImmediateContext->SetRenderTargets(1, &pRTV, pDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
373373

374374
// Clear the back buffer
@@ -424,7 +424,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
424424

425425
g_pTheApp.reset(new Tutorial00App);
426426

427-
const auto* cmdLine = GetCommandLineA();
427+
LPSTR cmdLine = GetCommandLineA();
428428
if (!g_pTheApp->ProcessCommandLine(cmdLine))
429429
return -1;
430430

Tutorials/Tutorial01_HelloTriangle/src/Tutorial01_HelloTriangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ void Tutorial01_HelloTriangle::Render()
155155
// Clear the back buffer
156156
const float ClearColor[] = {0.350f, 0.350f, 0.350f, 1.0f};
157157
// Let the engine perform required state transitions
158-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
159-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
158+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
159+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
160160
m_pImmediateContext->ClearRenderTarget(pRTV, ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
161161
m_pImmediateContext->ClearDepthStencil(pDSV, CLEAR_DEPTH_FLAG, 1.f, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
162162

Tutorials/Tutorial02_Cube/src/Tutorial02_Cube.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ void Tutorial02_Cube::Initialize(const SampleInitInfo& InitInfo)
236236
// Render a frame
237237
void Tutorial02_Cube::Render()
238238
{
239-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
240-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
239+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
240+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
241241
// Clear the back buffer
242242
float4 ClearColor = {0.350f, 0.350f, 0.350f, 1.0f};
243243
if (m_ConvertPSOutputToGamma)
@@ -285,10 +285,10 @@ void Tutorial02_Cube::Update(double CurrTime, double ElapsedTime, bool DoUpdateU
285285
float4x4 View = float4x4::Translation(0.f, 0.0f, 5.0f);
286286

287287
// Get pretransform matrix that rotates the scene according the surface orientation
288-
auto SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
288+
float4x4 SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
289289

290290
// Get projection matrix adjusted to the current screen orientation
291-
auto Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
291+
float4x4 Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
292292

293293
// Compute world-view-projection matrix
294294
m_WorldViewProjMatrix = CubeModelTransform * View * SrfPreTransform * Proj;

Tutorials/Tutorial03_Texturing/src/Tutorial03_Texturing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ void Tutorial03_Texturing::Initialize(const SampleInitInfo& InitInfo)
294294
// Render a frame
295295
void Tutorial03_Texturing::Render()
296296
{
297-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
298-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
297+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
298+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
299299
// Clear the back buffer
300300
float4 ClearColor = {0.350f, 0.350f, 0.350f, 1.0f};
301301
if (m_ConvertPSOutputToGamma)
@@ -343,10 +343,10 @@ void Tutorial03_Texturing::Update(double CurrTime, double ElapsedTime, bool DoUp
343343
float4x4 View = float4x4::Translation(0.f, 0.0f, 5.0f);
344344

345345
// Get pretransform matrix that rotates the scene according the surface orientation
346-
auto SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
346+
float4x4 SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
347347

348348
// Get projection matrix adjusted to the current screen orientation
349-
auto Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
349+
float4x4 Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
350350

351351
// Compute world-view-projection matrix
352352
m_WorldViewProjMatrix = CubeModelTransform * View * SrfPreTransform * Proj;

Tutorials/Tutorial04_Instancing/src/Tutorial04_Instancing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void Tutorial04_Instancing::Initialize(const SampleInitInfo& InitInfo)
144144
void Tutorial04_Instancing::PopulateInstanceBuffer()
145145
{
146146
// Populate instance data buffer
147-
const auto zGridSize = static_cast<size_t>(m_GridSize);
147+
const size_t zGridSize = static_cast<size_t>(m_GridSize);
148148
std::vector<float4x4> InstanceData(zGridSize * zGridSize * zGridSize);
149149

150150
float fGridSize = static_cast<float>(m_GridSize);
@@ -189,8 +189,8 @@ void Tutorial04_Instancing::PopulateInstanceBuffer()
189189
// Render a frame
190190
void Tutorial04_Instancing::Render()
191191
{
192-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
193-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
192+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
193+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
194194
// Clear the back buffer
195195
float4 ClearColor = {0.350f, 0.350f, 0.350f, 1.0f};
196196
if (m_ConvertPSOutputToGamma)
@@ -237,10 +237,10 @@ void Tutorial04_Instancing::Update(double CurrTime, double ElapsedTime, bool DoU
237237
float4x4 View = float4x4::RotationX(-0.6f) * float4x4::Translation(0.f, 0.f, 4.0f);
238238

239239
// Get pretransform matrix that rotates the scene according the surface orientation
240-
auto SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
240+
float4x4 SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
241241

242242
// Get projection matrix adjusted to the current screen orientation
243-
auto Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
243+
float4x4 Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
244244

245245
// Compute view-projection matrix
246246
m_ViewProjMatrix = View * SrfPreTransform * Proj;

Tutorials/Tutorial05_TextureArray/src/Tutorial05_TextureArray.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ void Tutorial05_TextureArray::LoadTextures()
144144
VERIFY(tex == 0 || TexLoaders[tex]->GetTextureDesc() == TexLoaders[0]->GetTextureDesc(), "All textures must be same size");
145145
}
146146

147-
auto TexArrDesc = TexLoaders[0]->GetTextureDesc();
148-
TexArrDesc.ArraySize = NumTextures;
149-
TexArrDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
150-
TexArrDesc.Usage = USAGE_DEFAULT;
151-
TexArrDesc.BindFlags = BIND_SHADER_RESOURCE;
147+
TextureDesc TexArrDesc = TexLoaders[0]->GetTextureDesc();
148+
TexArrDesc.ArraySize = NumTextures;
149+
TexArrDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
150+
TexArrDesc.Usage = USAGE_DEFAULT;
151+
TexArrDesc.BindFlags = BIND_SHADER_RESOURCE;
152152

153153
// Prepare initialization data
154154
std::vector<TextureSubResData> SubresData(TexArrDesc.ArraySize * TexArrDesc.MipLevels);
@@ -201,8 +201,8 @@ void Tutorial05_TextureArray::Initialize(const SampleInitInfo& InitInfo)
201201
void Tutorial05_TextureArray::PopulateInstanceBuffer()
202202
{
203203
// Populate instance data buffer
204-
const auto zGridSize = static_cast<size_t>(m_GridSize);
205-
std::vector<InstanceData> InstanceData(zGridSize * zGridSize * zGridSize);
204+
const size_t zGridSize = static_cast<size_t>(m_GridSize);
205+
std::vector<InstanceData> Instances(zGridSize * zGridSize * zGridSize);
206206

207207
float fGridSize = static_cast<float>(m_GridSize);
208208

@@ -233,25 +233,26 @@ void Tutorial05_TextureArray::PopulateInstanceBuffer()
233233
rotation *= float4x4::RotationY(rot_distr(gen));
234234
rotation *= float4x4::RotationZ(rot_distr(gen));
235235
// Combine rotation, scale and translation
236-
float4x4 matrix = rotation * float4x4::Scale(scale, scale, scale) * float4x4::Translation(xOffset, yOffset, zOffset);
237-
auto& CurrInst = InstanceData[instId++];
238-
CurrInst.Matrix = matrix;
236+
float4x4 matrix = rotation * float4x4::Scale(scale, scale, scale) * float4x4::Translation(xOffset, yOffset, zOffset);
237+
238+
InstanceData& CurrInst = Instances[instId++];
239+
CurrInst.Matrix = matrix;
239240
// Texture array index
240241
CurrInst.TextureInd = static_cast<float>(tex_distr(gen));
241242
}
242243
}
243244
}
244245
// Update instance data buffer
245-
Uint32 DataSize = static_cast<Uint32>(sizeof(InstanceData[0]) * InstanceData.size());
246-
m_pImmediateContext->UpdateBuffer(m_InstanceBuffer, 0, DataSize, InstanceData.data(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
246+
Uint32 DataSize = static_cast<Uint32>(sizeof(Instances[0]) * Instances.size());
247+
m_pImmediateContext->UpdateBuffer(m_InstanceBuffer, 0, DataSize, Instances.data(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
247248
}
248249

249250

250251
// Render a frame
251252
void Tutorial05_TextureArray::Render()
252253
{
253-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
254-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
254+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
255+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
255256
// Clear the back buffer
256257
float4 ClearColor = {0.350f, 0.350f, 0.350f, 1.0f};
257258
if (m_ConvertPSOutputToGamma)
@@ -298,10 +299,10 @@ void Tutorial05_TextureArray::Update(double CurrTime, double ElapsedTime, bool D
298299
float4x4 View = float4x4::RotationX(-0.6f) * float4x4::Translation(0.f, 0.f, 4.0f);
299300

300301
// Get pretransform matrix that rotates the scene according the surface orientation
301-
auto SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
302+
float4x4 SrfPreTransform = GetSurfacePretransformMatrix(float3{0, 0, 1});
302303

303304
// Get projection matrix adjusted to the current screen orientation
304-
auto Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
305+
float4x4 Proj = GetAdjustedProjectionMatrix(PI_F / 4.0f, 0.1f, 100.f);
305306

306307
// Compute view-projection matrix
307308
m_ViewProjMatrix = View * SrfPreTransform * Proj;

Tutorials/Tutorial06_Multithreading/readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Every worker thread starts by waiting for the signal from the main thread (a neg
153153
value is an exit signal):
154154

155155
```cpp
156-
auto SignaledValue = pThis->m_RenderSubsetSignal.Wait(true, pThis->m_NumWorkerThreads);
156+
int SignaledValue = pThis->m_RenderSubsetSignal.Wait(true, pThis->m_NumWorkerThreads);
157157
if (SignaledValue < 0)
158158
return;
159159
```
@@ -194,8 +194,8 @@ Subset rendering procedure is generally the same as in previous tutorials. Few d
194194
so every context should set the default render target:
195195

196196
```cpp
197-
auto* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
198-
auto* pDSV = m_pSwapChain->GetDepthBufferDSV();
197+
ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV();
198+
ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV();
199199
pCtx->SetRenderTargets(1, &pRTV, pDSV, RESOURCE_STATE_TRANSITION_MODE_VERIFY);
200200
```
201201
@@ -222,7 +222,7 @@ DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL;
222222
pCtx->SetPipelineState(m_pPSO);
223223
for (size_t inst = StartInst; inst < EndInst; ++inst)
224224
{
225-
const auto& CurrInstData = m_InstanceData[inst];
225+
const InstanceData& CurrInstData = m_Instances[inst];
226226
// Shader resources have been explicitly transitioned to correct states, so
227227
// RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode is not needed.
228228
// Instead, we use RESOURCE_STATE_TRANSITION_MODE_VERIFY mode to
@@ -237,4 +237,4 @@ for (size_t inst = StartInst; inst < EndInst; ++inst)
237237
238238
pCtx->DrawIndexed(DrawAttrs);
239239
}
240-
```
240+
```

0 commit comments

Comments
 (0)