Skip to content

Commit 8905fa8

Browse files
committed
Merge branch 'main_local' of github.com:Themperror/learnd3d11 into main_local
2 parents f723d4c + 95c456f commit 8905fa8

File tree

17 files changed

+276
-403
lines changed

17 files changed

+276
-403
lines changed

src/Cpp/1-getting-started/1-2-3-NamingThings/1-2-3-NamingThings.vcxproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,14 @@ xcopy /Y $(ProjectDir)Assets\Textures\*.* $(OutDir)Assets\Textures\</Command>
111111
</PostBuildEvent>
112112
</ItemDefinitionGroup>
113113
<ItemGroup>
114-
<ClCompile Include="DeviceContext.cpp" />
115114
<ClCompile Include="Main.cpp" />
116115
<ClCompile Include="NamingThingsApplication.cpp" />
117-
<ClCompile Include="Pipeline.cpp" />
118-
<ClCompile Include="PipelineFactory.cpp" />
116+
<ClCompile Include="ShaderCollection.cpp" />
119117
</ItemGroup>
120118
<ItemGroup>
121119
<ClInclude Include="Definitions.hpp" />
122-
<ClInclude Include="DeviceContext.hpp" />
123120
<ClInclude Include="NamingThingsApplication.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-3-NamingThings/1-2-3-NamingThings.vcxproj.filters

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
<ClCompile Include="NamingThingsApplication.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>
@@ -41,13 +35,7 @@
4135
<ClInclude Include="VertexType.hpp">
4236
<Filter>Header Files</Filter>
4337
</ClInclude>
44-
<ClInclude Include="PipelineFactory.hpp">
45-
<Filter>Header Files</Filter>
46-
</ClInclude>
47-
<ClInclude Include="Pipeline.hpp">
48-
<Filter>Header Files</Filter>
49-
</ClInclude>
50-
<ClInclude Include="DeviceContext.hpp">
38+
<ClInclude Include="ShaderCollection.hpp">
5139
<Filter>Header Files</Filter>
5240
</ClInclude>
5341
</ItemGroup>

src/Cpp/1-getting-started/1-2-3-NamingThings/DeviceContext.cpp

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

src/Cpp/1-getting-started/1-2-3-NamingThings/DeviceContext.hpp

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

src/Cpp/1-getting-started/1-2-3-NamingThings/NamingThingsApplication.cpp

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

74
#include <GLFW/glfw3.h>
@@ -35,12 +32,10 @@ NamingThingsApplication::~NamingThingsApplication()
3532
{
3633
_deviceContext->Flush();
3734
_triangleVertices.Reset();
38-
_pipeline.reset();
39-
_pipelineFactory.reset();
4035
DestroySwapchainResources();
4136
_swapChain.Reset();
4237
_dxgiFactory.Reset();
43-
_deviceContext.reset();
38+
_deviceContext.Reset();
4439
#if !defined(NDEBUG)
4540
_debug->ReportLiveDeviceObjects(D3D11_RLDO_FLAGS::D3D11_RLDO_DETAIL);
4641
_debug.Reset();
@@ -90,7 +85,7 @@ bool NamingThingsApplication::Initialize()
9085
_device->SetPrivateData(WKPDID_D3DDebugObjectName, sizeof(deviceName), deviceName);
9186
SetDebugName(deviceContext.Get(), "CTX_Main");
9287

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

9590
if (FAILED(_device.As(&_debug)))
9691
{
@@ -127,28 +122,17 @@ bool NamingThingsApplication::Initialize()
127122

128123
CreateSwapchainResources();
129124

130-
_pipelineFactory = std::make_unique<PipelineFactory>(_device);
131125

132126
return true;
133127
}
134128

135129
bool NamingThingsApplication::Load()
136130
{
137-
PipelineDescriptor pipelineDescriptor = {};
138-
pipelineDescriptor.VertexFilePath = L"Assets/Shaders/Main.vs.hlsl";
139-
pipelineDescriptor.PixelFilePath = L"Assets/Shaders/Main.ps.hlsl";
140-
pipelineDescriptor.VertexType = VertexType::PositionColor;
141-
if (!_pipelineFactory->CreatePipeline(pipelineDescriptor, _pipeline))
142-
{
143-
std::cout << "PipelineFactory: Failed to create pipeline\n";
144-
return false;
145-
}
146-
147-
_pipeline->SetViewport(
148-
0.0f,
149-
0.0f,
150-
static_cast<float>(GetWindowWidth()),
151-
static_cast<float>(GetWindowHeight()));
131+
ShaderCollectionDescriptor shaderCollectionDescriptor = {};
132+
shaderCollectionDescriptor.VertexShaderFilePath = L"Assets/Shaders/Main.vs.hlsl";
133+
shaderCollectionDescriptor.PixelShaderFilePath = L"Assets/Shaders/Main.ps.hlsl";
134+
shaderCollectionDescriptor.VertexType = VertexType::PositionColor;
135+
_shaderCollection = ShaderCollection::CreateShaderCollection(shaderCollectionDescriptor, _device.Get());
152136

153137
constexpr VertexPositionColor vertices[] = {
154138
{ Position{ 0.0f, 0.5f, 0.0f }, Color{ 0.25f, 0.39f, 0.19f }},
@@ -234,11 +218,38 @@ void NamingThingsApplication::Update()
234218
void NamingThingsApplication::Render()
235219
{
236220
float clearColor[] = { 0.1f, 0.1f, 0.1f, 1.0f };
221+
ID3D11RenderTargetView* nullRTV = nullptr;
237222
constexpr uint32_t vertexOffset = 0;
238223

239-
_deviceContext->Clear(_renderTarget.Get(), clearColor);
240-
_deviceContext->SetPipeline(_pipeline.get());
241-
_deviceContext->SetVertexBuffer(_triangleVertices.Get(), vertexOffset);
242-
_deviceContext->Draw();
224+
D3D11_VIEWPORT viewport = {
225+
0.0f,
226+
0.0f,
227+
static_cast<float>(GetWindowWidth()),
228+
static_cast<float>(GetWindowHeight()),
229+
0.0f,
230+
1.0f
231+
};
232+
233+
_deviceContext->RSSetViewports(1, &viewport);
234+
_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
235+
236+
_shaderCollection.ApplyToContext(_deviceContext.Get());
237+
238+
239+
_deviceContext->OMSetRenderTargets(1, &nullRTV, nullptr);
240+
241+
_deviceContext->ClearRenderTargetView(_renderTarget.Get(), clearColor);
242+
_deviceContext->OMSetRenderTargets(1, _renderTarget.GetAddressOf(), nullptr);
243+
244+
UINT stride = _shaderCollection.GetLayoutByteSize(VertexType::PositionColor);
245+
246+
_deviceContext->IASetVertexBuffers(
247+
0,
248+
1,
249+
_triangleVertices.GetAddressOf(),
250+
&stride,
251+
&vertexOffset);
252+
253+
_deviceContext->Draw(3, 0);
243254
_swapChain->Present(1, 0);
244255
}

src/Cpp/1-getting-started/1-2-3-NamingThings/NamingThingsApplication.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
#include <memory>
99

10-
class DeviceContext;
11-
class Pipeline;
12-
class PipelineFactory;
10+
#include "ShaderCollection.hpp"
1311

1412
class NamingThingsApplication final : public Application
1513
{
@@ -30,14 +28,13 @@ class NamingThingsApplication final : public Application
3028
bool CreateSwapchainResources();
3129
void DestroySwapchainResources();
3230

33-
std::unique_ptr<DeviceContext> _deviceContext = nullptr;
34-
std::unique_ptr<Pipeline> _pipeline = nullptr;
35-
std::unique_ptr<PipelineFactory> _pipelineFactory = nullptr;
36-
31+
WRL::ComPtr<ID3D11DeviceContext> _deviceContext = nullptr;
3732
WRL::ComPtr<ID3D11Device> _device = nullptr;
3833
WRL::ComPtr<IDXGIFactory2> _dxgiFactory = nullptr;
3934
WRL::ComPtr<IDXGISwapChain1> _swapChain = nullptr;
4035
WRL::ComPtr<ID3D11RenderTargetView> _renderTarget = nullptr;
4136
WRL::ComPtr<ID3D11Buffer> _triangleVertices = nullptr;
4237
WRL::ComPtr<ID3D11Debug> _debug = nullptr;
38+
39+
ShaderCollection _shaderCollection;
4340
};

src/Cpp/1-getting-started/1-2-3-NamingThings/Pipeline.cpp

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

src/Cpp/1-getting-started/1-2-3-NamingThings/Pipeline.hpp

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

0 commit comments

Comments
 (0)