-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRenderStates.cpp
102 lines (81 loc) · 3.55 KB
/
RenderStates.cpp
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
//***************************************************************************************
// RenderStates.cpp by Frank Luna (C) 2011 All Rights Reserved.
//***************************************************************************************
#include "RenderStates.h"
ID3D11RasterizerState* RenderStates::WireframeRS = 0;
ID3D11RasterizerState* RenderStates::NoCullRS = 0;
ID3D11BlendState* RenderStates::AlphaToCoverageBS = 0;
ID3D11BlendState* RenderStates::TransparentBS = 0;
// Depth/stencil states
ID3D11DepthStencilState* RenderStates::MarkMirrorDSS = 0;
void RenderStates::InitAll(ID3D11Device* device)
{
//
// WireframeRS
//
D3D11_RASTERIZER_DESC wireframeDesc;
ZeroMemory(&wireframeDesc, sizeof(D3D11_RASTERIZER_DESC));
wireframeDesc.FillMode = D3D11_FILL_SOLID;
wireframeDesc.CullMode = D3D11_CULL_FRONT;
wireframeDesc.FrontCounterClockwise = false;
wireframeDesc.DepthClipEnable = true;
HR(device->CreateRasterizerState(&wireframeDesc, &WireframeRS));
//
// NoCullRS
//
D3D11_RASTERIZER_DESC noCullDesc;
ZeroMemory(&noCullDesc, sizeof(D3D11_RASTERIZER_DESC));
noCullDesc.FillMode = D3D11_FILL_SOLID;
noCullDesc.CullMode = D3D11_CULL_FRONT;
noCullDesc.FrontCounterClockwise = false;
noCullDesc.DepthClipEnable = false;
HR(device->CreateRasterizerState(&noCullDesc, &NoCullRS));
//
// AlphaToCoverageBS
//
D3D11_BLEND_DESC alphaToCoverageDesc = {0};
alphaToCoverageDesc.AlphaToCoverageEnable = true;
alphaToCoverageDesc.IndependentBlendEnable = false;
alphaToCoverageDesc.RenderTarget[0].BlendEnable = false;
alphaToCoverageDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
HR(device->CreateBlendState(&alphaToCoverageDesc, &AlphaToCoverageBS));
//
// TransparentBS
//
D3D11_BLEND_DESC transparentDesc = {0};
transparentDesc.AlphaToCoverageEnable = false;
transparentDesc.IndependentBlendEnable = false;
transparentDesc.RenderTarget[0].BlendEnable = true;
transparentDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
transparentDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
transparentDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
transparentDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
transparentDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
transparentDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
transparentDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
HR(device->CreateBlendState(&transparentDesc, &TransparentBS));
D3D11_DEPTH_STENCIL_DESC mirrorDesc = { 0 };
mirrorDesc.DepthEnable = true;
mirrorDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
mirrorDesc.DepthFunc = D3D11_COMPARISON_LESS;
/*mirrorDesc.StencilEnable = true;
mirrorDesc.StencilReadMask = 0xff;
mirrorDesc.StencilWriteMask = 0xff;
mirrorDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
mirrorDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// We are not rendering backfacing polygons, so these settings do not matter.
mirrorDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
mirrorDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
mirrorDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;*/
HR(device->CreateDepthStencilState(&mirrorDesc, &MarkMirrorDSS));
}
void RenderStates::DestroyAll()
{
ReleaseCOM(WireframeRS);
ReleaseCOM(NoCullRS);
ReleaseCOM(AlphaToCoverageBS);
ReleaseCOM(TransparentBS);
}