|
1 | 1 | #include "DebugLayerApplication.hpp" |
2 | | -#include "DeviceContext.hpp" |
3 | | -#include "Pipeline.hpp" |
4 | | -#include "PipelineFactory.hpp" |
5 | 2 | #include "VertexType.hpp" |
6 | 3 |
|
7 | 4 | #include <GLFW/glfw3.h> |
@@ -29,12 +26,11 @@ DebugLayerApplication::~DebugLayerApplication() |
29 | 26 | { |
30 | 27 | _deviceContext->Flush(); |
31 | 28 | _triangleVertices.Reset(); |
32 | | - _pipeline.reset(); |
33 | | - _pipelineFactory.reset(); |
34 | 29 | DestroySwapchainResources(); |
35 | 30 | _swapChain.Reset(); |
36 | 31 | _dxgiFactory.Reset(); |
37 | | - _deviceContext.reset(); |
| 32 | + _shaderCollection.Destroy(); |
| 33 | + _deviceContext.Reset(); |
38 | 34 | #if !defined(NDEBUG) |
39 | 35 | _debug->ReportLiveDeviceObjects(D3D11_RLDO_FLAGS::D3D11_RLDO_DETAIL); |
40 | 36 | _debug.Reset(); |
@@ -85,7 +81,7 @@ bool DebugLayerApplication::Initialize() |
85 | 81 | return false; |
86 | 82 | } |
87 | 83 |
|
88 | | - _deviceContext = std::make_unique<DeviceContext>(std::move(deviceContext)); |
| 84 | + _deviceContext = deviceContext; |
89 | 85 |
|
90 | 86 | DXGI_SWAP_CHAIN_DESC1 swapChainDescriptor = {}; |
91 | 87 | swapChainDescriptor.Width = GetWindowWidth(); |
@@ -116,28 +112,17 @@ bool DebugLayerApplication::Initialize() |
116 | 112 |
|
117 | 113 | CreateSwapchainResources(); |
118 | 114 |
|
119 | | - _pipelineFactory = std::make_unique<PipelineFactory>(_device); |
120 | | - |
121 | 115 | return true; |
122 | 116 | } |
123 | 117 |
|
124 | 118 | bool DebugLayerApplication::Load() |
125 | 119 | { |
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; |
135 | 124 |
|
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()); |
141 | 126 |
|
142 | 127 | constexpr VertexPositionColor vertices[] = { |
143 | 128 | { Position{ 0.0f, 0.5f, 0.0f }, Color{ 0.25f, 0.39f, 0.19f }}, |
@@ -223,11 +208,37 @@ void DebugLayerApplication::Update() |
223 | 208 | void DebugLayerApplication::Render() |
224 | 209 | { |
225 | 210 | float clearColor[] = { 0.1f, 0.1f, 0.1f, 1.0f }; |
| 211 | + ID3D11RenderTargetView* nullRTV = nullptr; |
226 | 212 | constexpr uint32_t vertexOffset = 0; |
227 | 213 |
|
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 | + |
232 | 243 | _swapChain->Present(1, 0); |
233 | 244 | } |
0 commit comments