generated from Jonathan-Greve/GuildWarsMapBrowser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DepthStencilStateManager.h
61 lines (52 loc) · 1.9 KB
/
DepthStencilStateManager.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
#pragma once
#include <array>
enum class DepthStencilStateType
{
Enabled,
Disabled
};
class DepthStencilStateManager
{
public:
DepthStencilStateManager(ID3D11Device* device, ID3D11DeviceContext* device_context)
: m_device(device)
, m_deviceContext(device_context)
{
// Create depth stencil state for Enabled
D3D11_DEPTH_STENCIL_DESC dsDescEnabled;
ZeroMemory(&dsDescEnabled, sizeof(dsDescEnabled));
dsDescEnabled.DepthEnable = true;
dsDescEnabled.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
dsDescEnabled.DepthFunc = D3D11_COMPARISON_LESS;
ID3D11DepthStencilState* pDSStateEnabled;
m_device->CreateDepthStencilState(&dsDescEnabled, &pDSStateEnabled);
m_depthStencilStates[static_cast<size_t>(DepthStencilStateType::Enabled)] = pDSStateEnabled;
// Create depth stencil state for Disabled
D3D11_DEPTH_STENCIL_DESC dsDescDisabled;
ZeroMemory(&dsDescDisabled, sizeof(dsDescDisabled));
dsDescDisabled.DepthEnable = false;
dsDescDisabled.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
dsDescDisabled.DepthFunc = D3D11_COMPARISON_LESS;
ID3D11DepthStencilState* pDSStateDisabled;
m_device->CreateDepthStencilState(&dsDescDisabled, &pDSStateDisabled);
m_depthStencilStates[static_cast<size_t>(DepthStencilStateType::Disabled)] = pDSStateDisabled;
}
~DepthStencilStateManager()
{
for (auto state : m_depthStencilStates)
{
if (state)
{
state->Release();
}
}
}
void SetDepthStencilState(DepthStencilStateType type)
{
m_deviceContext->OMSetDepthStencilState(m_depthStencilStates[static_cast<size_t>(type)], 1);
}
private:
ID3D11Device* m_device;
ID3D11DeviceContext* m_deviceContext;
std::array<ID3D11DepthStencilState*, 2> m_depthStencilStates;
};