-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestApp.h
195 lines (152 loc) · 5.36 KB
/
TestApp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#pragma once
#include "D3Base.h"
#include "RenderItem.h"
#include <DirectXColors.h>
#include "FrameResource.h"
#include "BlurFilter.h"
#include "SobelFilter.h"
#include "Plane.h"
#include "RenderTarget.h"
#include "Mesh.h"
#include "Light.h"
#include "ShadowMap.h"
#include "Camera.h" // temporary!
class TestApp :
public D3Base
{
public:
TestApp(HINSTANCE hInst);
~TestApp();
virtual bool Initialize() override;
private:
virtual void OnResize() override;
virtual void Update(const Timer& t) override;
virtual void Draw(const Timer& t) override;
void DrawRenderItems(ID3D12GraphicsCommandList*, const std::vector<std::shared_ptr<RenderItem>>&);
void DrawFullscreenQuad(ID3D12GraphicsCommandList*);
void DrawShadowMaps();
virtual void OnMouseUp(WPARAM btnState, int x, int y) override;
virtual void OnMouseDown(WPARAM btnState, int x, int y) override;
virtual void OnMouseMove(WPARAM btnState, int x, int y) override;
void OnKeyboardInput(const Timer&);
virtual void OnKeyDown(WPARAM, LPARAM) override;
virtual void OnKeyUp(WPARAM, LPARAM) override;
void ClearInstances(std::shared_ptr<RenderItem>);
void UpdateGeometry(const Timer&);
void UpdateInstanceBuffer(const Timer&, const std::vector<RENDER_ITEM_TYPE>&);
void UpdateMaterialBuffer(const Timer&);
void UpdateMainPassCB(const Timer&);
void UpdateShadowPassCB(size_t lightIndex, UINT passIndex);
void UpdateLights(const Timer&);
void LoadTextures();
void BuildMaterials();
void Pick(float x, float y);
virtual void CreateRtvAndDsvDescriptorHeaps() override;
void BuildDescriptorHeaps();
void BuildDescriptors();
void BuildStaticGeometry();
void BuildRootSignature();
void BuildPostprocessRootSignature();
void BuildBlurRootSignature();
void BuildSobelRootSignature();
void BuildPSOs();
void BuildShadersAndInputLayout();
void InitLights();
void BuildSceneBounds();
void BuildFrameResources();
void BuildRenderItems();
std::array<const CD3DX12_STATIC_SAMPLER_DESC, 7> GetStaticSamplers();
private:
int gIdx = 0;
std::map<RENDER_ITEM_TYPE, std::vector<std::shared_ptr<RenderItem>>> mRenderItems;
std::vector<std::unique_ptr<FrameResource>> mFrameResources;
UINT mNumFrameResources = 3;
FrameResource* mCurrFrameResource = nullptr;
int mCurrFrameResourceIndex = 0;
Microsoft::WRL::ComPtr<ID3D12RootSignature> mRootSignature = nullptr;
Microsoft::WRL::ComPtr<ID3D12RootSignature> mBlurRootSignature = nullptr;
Microsoft::WRL::ComPtr<ID3D12RootSignature> mSobelRootSignature = nullptr;
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> mCbvDescHeap = nullptr;
// Looks like a relic to me; delete.
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> mSrvDescHeap = nullptr;
std::unordered_map<std::string, std::unique_ptr<Mesh>> mGeometries;
std::unordered_map<std::string, std::unique_ptr<Material>> mMaterials;
std::unordered_map<std::string, std::unique_ptr<Texture>> mTextures;
std::unordered_map<std::string, Microsoft::WRL::ComPtr<ID3DBlob>> mShaders;
std::unordered_map<std::string, Microsoft::WRL::ComPtr<ID3D12PipelineState>> mPSOs;
DirectX::BoundingSphere mSceneBoundS;
std::string mLevel = "Level5";
CD3DX12_GPU_DESCRIPTOR_HANDLE mNullSrv;
CD3DX12_GPU_DESCRIPTOR_HANDLE mEnvironmentMapSrv;
std::vector<D3D12_INPUT_ELEMENT_DESC> mInputLayout;
std::vector<std::shared_ptr<LightPovData>> mLights;
UINT mNumDirLights = 0;
UINT mNumSpotLights = 0;
UINT mNumPointLights = 0;
PassConstants mPassCB;
UINT mPassCbvOffset = 0;
PassConstants mShadowPassCB;
UINT mPassShadowOffset = 0;
bool isWireFrame = false;
DirectX::XMFLOAT4X4 mProj = Math::Identity4x4();
std::unique_ptr<BlurFilter> mBlurFilter;
std::unique_ptr<SobelFilter> mSobelFilter;
std::unique_ptr<RenderTarget> mOffscreenRT;
Plane mPlane;
POINT mLastMousePos;
Camera mCamera;
// Settings
std::wstring mProjectPath;
bool mDbgFlag = false;
bool mDebugBoundingBoxesEnabled = true;
const std::vector<RENDER_ITEM_TYPE> mPickableRenderItems = {
RENDER_ITEM_TYPE::OPAQUE_DYNAMIC,
RENDER_ITEM_TYPE::OPAQUE_STATIC,
RENDER_ITEM_TYPE::WIREFRAME_DYNAMIC,
RENDER_ITEM_TYPE::WIREFRAME_STATIC,
RENDER_ITEM_TYPE::TRANSPARENT_DYNAMIC,
RENDER_ITEM_TYPE::TRANSPARENT_STATIC
};
const std::vector<RENDER_ITEM_TYPE> mDynamicRenderItems = {
RENDER_ITEM_TYPE::OPAQUE_DYNAMIC,
RENDER_ITEM_TYPE::TRANSPARENT_DYNAMIC,
RENDER_ITEM_TYPE::WIREFRAME_DYNAMIC,
RENDER_ITEM_TYPE::DEBUG_BOXES
};
const std::vector<RENDER_ITEM_TYPE> mStaticRenderItems = {
RENDER_ITEM_TYPE::ENVIRONMENT_MAP,
RENDER_ITEM_TYPE::OPAQUE_STATIC,
RENDER_ITEM_TYPE::TRANSPARENT_STATIC,
RENDER_ITEM_TYPE::WIREFRAME_STATIC,
RENDER_ITEM_TYPE::DEBUG_QUAD_SHADOWMAP
};
// Member variables belonging to the physics
};
// Entry point
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevInst, PSTR cmdLine, int showCmd)
{
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
try
{
TestApp ta(hInst);
if (!ta.Initialize())
return 0;
return ta.Run();
}
catch (DxException& e)
{
MessageBox(nullptr, e.ToString().c_str(), L"HR Failed", MB_OK);
return 0;
}
}
TestApp::TestApp(HINSTANCE hInst) : D3Base(hInst) {};
TestApp::~TestApp() {};
void TestApp::OnResize()
{
D3Base::OnResize();
// The window resized, so update the aspect ratio and recompute the projection matrix.
DirectX::XMMATRIX P = DirectX::XMMatrixPerspectiveFovLH(0.25f * Math::Pi, AspectRatio(), 1.0f, 3000.0f);
DirectX::XMStoreFloat4x4(&mProj, P);
}