Skip to content

Commit f723d4c

Browse files
committed
Refactor DebugLayer
1 parent 3c7b085 commit f723d4c

12 files changed

+264
-392
lines changed

src/Cpp/1-getting-started/1-2-2-DebugLayer/1-2-2-DebugLayer.vcxproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,13 @@ xcopy /Y $(ProjectDir)Assets\Textures\*.* $(OutDir)Assets\Textures\</Command>
112112
</ItemDefinitionGroup>
113113
<ItemGroup>
114114
<ClCompile Include="DebugLayerApplication.cpp" />
115-
<ClCompile Include="DeviceContext.cpp" />
116115
<ClCompile Include="Main.cpp" />
117-
<ClCompile Include="Pipeline.cpp" />
118-
<ClCompile Include="PipelineFactory.cpp" />
116+
<ClCompile Include="ShaderCollection.cpp" />
119117
</ItemGroup>
120118
<ItemGroup>
121119
<ClInclude Include="DebugLayerApplication.hpp" />
122120
<ClInclude Include="Definitions.hpp" />
123-
<ClInclude Include="DeviceContext.hpp" />
124-
<ClInclude Include="Pipeline.hpp" />
125-
<ClInclude Include="PipelineFactory.hpp" />
121+
<ClInclude Include="ShaderCollection.hpp" />
126122
<ClInclude Include="VertexType.hpp" />
127123
</ItemGroup>
128124
<ItemGroup>

src/Cpp/1-getting-started/1-2-2-DebugLayer/1-2-2-DebugLayer.vcxproj.filters

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
<ClCompile Include="DebugLayerApplication.cpp">
2222
<Filter>Source Files</Filter>
2323
</ClCompile>
24-
<ClCompile Include="PipelineFactory.cpp">
25-
<Filter>Source Files</Filter>
26-
</ClCompile>
27-
<ClCompile Include="DeviceContext.cpp">
28-
<Filter>Source Files</Filter>
29-
</ClCompile>
30-
<ClCompile Include="Pipeline.cpp">
24+
<ClCompile Include="ShaderCollection.cpp">
3125
<Filter>Source Files</Filter>
3226
</ClCompile>
3327
</ItemGroup>
@@ -38,16 +32,10 @@
3832
<ClInclude Include="Definitions.hpp">
3933
<Filter>Header Files</Filter>
4034
</ClInclude>
41-
<ClInclude Include="Pipeline.hpp">
42-
<Filter>Header Files</Filter>
43-
</ClInclude>
44-
<ClInclude Include="PipelineFactory.hpp">
45-
<Filter>Header Files</Filter>
46-
</ClInclude>
47-
<ClInclude Include="DeviceContext.hpp">
35+
<ClInclude Include="VertexType.hpp">
4836
<Filter>Header Files</Filter>
4937
</ClInclude>
50-
<ClInclude Include="VertexType.hpp">
38+
<ClInclude Include="ShaderCollection.hpp">
5139
<Filter>Header Files</Filter>
5240
</ClInclude>
5341
</ItemGroup>

src/Cpp/1-getting-started/1-2-2-DebugLayer/DebugLayerApplication.cpp

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#include "DebugLayerApplication.hpp"
2-
#include "DeviceContext.hpp"
3-
#include "Pipeline.hpp"
4-
#include "PipelineFactory.hpp"
52
#include "VertexType.hpp"
63

74
#include <GLFW/glfw3.h>
@@ -29,12 +26,11 @@ DebugLayerApplication::~DebugLayerApplication()
2926
{
3027
_deviceContext->Flush();
3128
_triangleVertices.Reset();
32-
_pipeline.reset();
33-
_pipelineFactory.reset();
3429
DestroySwapchainResources();
3530
_swapChain.Reset();
3631
_dxgiFactory.Reset();
37-
_deviceContext.reset();
32+
_shaderCollection.Destroy();
33+
_deviceContext.Reset();
3834
#if !defined(NDEBUG)
3935
_debug->ReportLiveDeviceObjects(D3D11_RLDO_FLAGS::D3D11_RLDO_DETAIL);
4036
_debug.Reset();
@@ -85,7 +81,7 @@ bool DebugLayerApplication::Initialize()
8581
return false;
8682
}
8783

88-
_deviceContext = std::make_unique<DeviceContext>(std::move(deviceContext));
84+
_deviceContext = deviceContext;
8985

9086
DXGI_SWAP_CHAIN_DESC1 swapChainDescriptor = {};
9187
swapChainDescriptor.Width = GetWindowWidth();
@@ -116,28 +112,17 @@ bool DebugLayerApplication::Initialize()
116112

117113
CreateSwapchainResources();
118114

119-
_pipelineFactory = std::make_unique<PipelineFactory>(_device);
120-
121115
return true;
122116
}
123117

124118
bool DebugLayerApplication::Load()
125119
{
126-
PipelineDescriptor pipelineDescriptor = {};
127-
pipelineDescriptor.VertexFilePath = L"Assets/Shaders/Main.vs.hlsl";
128-
pipelineDescriptor.PixelFilePath = L"Assets/Shaders/Main.ps.hlsl";
129-
pipelineDescriptor.VertexType = VertexType::PositionColor;
130-
if (!_pipelineFactory->CreatePipeline(pipelineDescriptor, _pipeline))
131-
{
132-
std::cout << "PipelineFactory: Failed to create pipeline\n";
133-
return false;
134-
}
120+
ShaderCollectionDescriptor shaderDescriptor = {};
121+
shaderDescriptor.VertexShaderFilePath = L"Assets/Shaders/Main.vs.hlsl";
122+
shaderDescriptor.PixelShaderFilePath = L"Assets/Shaders/Main.ps.hlsl";
123+
shaderDescriptor.VertexType = VertexType::PositionColor;
135124

136-
_pipeline->SetViewport(
137-
0.0f,
138-
0.0f,
139-
static_cast<float>(GetWindowWidth()),
140-
static_cast<float>(GetWindowHeight()));
125+
_shaderCollection = ShaderCollection::CreateShaderCollection(shaderDescriptor, _device.Get());
141126

142127
constexpr VertexPositionColor vertices[] = {
143128
{ Position{ 0.0f, 0.5f, 0.0f }, Color{ 0.25f, 0.39f, 0.19f }},
@@ -223,11 +208,37 @@ void DebugLayerApplication::Update()
223208
void DebugLayerApplication::Render()
224209
{
225210
float clearColor[] = { 0.1f, 0.1f, 0.1f, 1.0f };
211+
ID3D11RenderTargetView* nullRTV = nullptr;
226212
constexpr uint32_t vertexOffset = 0;
227213

228-
_deviceContext->Clear(_renderTarget.Get(), clearColor);
229-
_deviceContext->SetPipeline(_pipeline.get());
230-
_deviceContext->SetVertexBuffer(_triangleVertices.Get(), vertexOffset);
231-
_deviceContext->Draw();
214+
D3D11_VIEWPORT viewport = {
215+
0.0f,
216+
0.0f,
217+
static_cast<float>(GetWindowWidth()),
218+
static_cast<float>(GetWindowHeight()),
219+
0.0f,
220+
1.0f
221+
};
222+
223+
_deviceContext->RSSetViewports(1, &viewport);
224+
_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
225+
226+
_shaderCollection.ApplyToContext(_deviceContext.Get());
227+
228+
_deviceContext->OMSetRenderTargets(1, &nullRTV, nullptr);
229+
230+
_deviceContext->ClearRenderTargetView(_renderTarget.Get(), clearColor);
231+
_deviceContext->OMSetRenderTargets(1, _renderTarget.GetAddressOf(), nullptr);
232+
233+
UINT stride = _shaderCollection.GetLayoutByteSize(VertexType::PositionColor);
234+
_deviceContext->IASetVertexBuffers(
235+
0,
236+
1,
237+
_triangleVertices.GetAddressOf(),
238+
&stride,
239+
&vertexOffset);
240+
241+
_deviceContext->Draw(3, 0);
242+
232243
_swapChain->Present(1, 0);
233244
}

src/Cpp/1-getting-started/1-2-2-DebugLayer/DebugLayerApplication.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
#include "Definitions.hpp"
44
#include <Application.hpp>
5+
#include "ShaderCollection.hpp"
56

67
#include <d3d11_2.h>
78

89
#include <memory>
910

10-
class DeviceContext;
11-
class Pipeline;
12-
class PipelineFactory;
13-
1411
class DebugLayerApplication final : public Application
1512
{
1613
public:
@@ -30,11 +27,10 @@ class DebugLayerApplication final : public Application
3027
bool CreateSwapchainResources();
3128
void DestroySwapchainResources();
3229

33-
std::unique_ptr<DeviceContext> _deviceContext = nullptr;
34-
std::unique_ptr<Pipeline> _pipeline = nullptr;
35-
std::unique_ptr<PipelineFactory> _pipelineFactory = nullptr;
30+
ShaderCollection _shaderCollection;
3631

3732
WRL::ComPtr<ID3D11Device> _device = nullptr;
33+
WRL::ComPtr<ID3D11DeviceContext> _deviceContext = nullptr;
3834
WRL::ComPtr<IDXGIFactory2> _dxgiFactory = nullptr;
3935
WRL::ComPtr<IDXGISwapChain1> _swapChain = nullptr;
4036
WRL::ComPtr<ID3D11RenderTargetView> _renderTarget = nullptr;

src/Cpp/1-getting-started/1-2-2-DebugLayer/DeviceContext.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Cpp/1-getting-started/1-2-2-DebugLayer/DeviceContext.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Cpp/1-getting-started/1-2-2-DebugLayer/Pipeline.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Cpp/1-getting-started/1-2-2-DebugLayer/Pipeline.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)