forked from TomohikoMukai/ssdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleApp.h
116 lines (105 loc) · 3.1 KB
/
SampleApp.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
#ifndef SAMPLE_APP_H
#define SAMPLE_APP_H
#pragma once
#include <windows.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#include <DirectXMath.h>
#include <vector>
#include <string>
#include "Object.h"
class SampleApp
{
public:
struct Config
{
UINT swapChainCount;
DXGI_FORMAT swapChainFormat;
DXGI_FORMAT depthStencilFormat;
UINT multiSampleCount;
UINT multiSampleQuality;
UINT width;
UINT height;
wchar_t* title;
FLOAT clearColorR;
FLOAT clearColorG;
FLOAT clearColorB;
FLOAT clearColorA;
Config()
: swapChainCount(2),
swapChainFormat(DXGI_FORMAT_R8G8B8A8_UNORM),
depthStencilFormat(DXGI_FORMAT_D24_UNORM_S8_UINT),
multiSampleCount(1),
multiSampleQuality(0),
width(1280),
height(720),
title(L"BasicApp"),
clearColorR(0.392f),
clearColorG(0.584f),
clearColorB(0.929f),
clearColorA(1.0f)
{
}
};
//
// field
protected:
static const UINT SWAPCHAIN_BUFFER_COUNT = 2;
static const DXGI_FORMAT SWAPCHAIN_BUFFER_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM;
static const DXGI_FORMAT DEPTHSTENCIL_TEXTURE_FORMAT = DXGI_FORMAT_R24G8_TYPELESS;
static const DXGI_FORMAT DEPTHSTENCIL_VIEW_FORMAT = DXGI_FORMAT_D24_UNORM_S8_UINT;
static const DXGI_FORMAT DEPTHSTENCIL_RESOURCE_FORMAT = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
static SampleApp* s_pThis;
HINSTANCE hInstance;
HWND hMainWnd;
D3D_DRIVER_TYPE driverType;
D3D_FEATURE_LEVEL featureLevel;
UINT multiSampleCount;
UINT multiSampleQuality;
UINT multiSampleMaxQuality;
UINT swapChainCount;
DXGI_FORMAT swapChainFormat;
DXGI_FORMAT depthStencilFormat;
ID3D11Device* d3dDevice;
ID3D11DeviceContext* d3dDeviceContext;
IDXGISwapChain* swapChain;
ID3D11RenderTargetView* renderTargetView;
ID3D11DepthStencilView* depthStencilView;
ID3D11Texture2D* renderTargetTexture;
ID3D11Texture2D* depthStencilTexture;
ID3D11ShaderResourceView* renderTargetShaderResourceView;
ID3D11ShaderResourceView* depthStencilShaderResourceView;
FLOAT clearColor[4];
UINT wndWidth;
UINT wndHeight;
FLOAT aspectRatio;
std::wstring wndTitle;
LARGE_INTEGER prevCounter;
LONGLONG counterPerFrame;
std::vector<Object::SharedPtr> object;
public:
bool InitializeApp();
void TerminateApp();
bool OpenWindow();
void CloseWindow();
bool InitializeD3D11();
void TerminateD3D11();
void OnTerminate();
int MainLoop();
bool OnInit();
void OnRender();
void OnResize(const UINT w, const UINT h);
void OnUpdate(LONGLONG elapsed);
void AddObject(Object::SharedPtr obj);
public:
bool CreateDefaultRenderTarget();
bool CreateDefaultDepthStencil();
void ReleaseDefaultRenderTarget();
void ReleaseDefaultDepthStencil();
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
public:
SampleApp(const Config& config);
virtual ~SampleApp();
int Run();
};
#endif //SAMPLE_APP_H