aboutsummaryrefslogtreecommitdiff
path: root/src/States_DX11.cpp
blob: 75dab26119d500a60cd4af082be745ddf86534c0 (plain) (blame)
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
/* 
* Copyright (c) 2008-2016, NVIDIA CORPORATION. All rights reserved. 
* 
* NVIDIA CORPORATION and its licensors retain all intellectual property 
* and proprietary rights in and to this software, related documentation 
* and any modifications thereto. Any use, reproduction, disclosure or 
* distribution of this software and related documentation without an express 
* license agreement from NVIDIA CORPORATION is strictly prohibited. 
*/

#if SUPPORT_D3D11

#include "States_DX11.h"

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::CreateBlendStates(ID3D11Device* pD3DDevice)
{
    //
    // Create BlendState_Disabled
    //

    D3D11_BLEND_DESC BlendStateDesc;
    BlendStateDesc.AlphaToCoverageEnable = FALSE;
    BlendStateDesc.IndependentBlendEnable = TRUE;

    for (UINT i = 0; i < SIZEOF_ARRAY(BlendStateDesc.RenderTarget); ++i)
    {
        BlendStateDesc.RenderTarget[i].BlendEnable = FALSE;
        BlendStateDesc.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
    }

    SAFE_D3D_CALL( pD3DDevice->CreateBlendState(&BlendStateDesc, &m_pBlendState_Disabled) );

    //
    // Create BlendState_Multiply_PreserveAlpha
    //

    BlendStateDesc.RenderTarget[0].BlendEnable = TRUE;
    BlendStateDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
    BlendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ZERO;
    BlendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_SRC_COLOR;
    BlendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
    BlendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
    BlendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
    BlendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;

    SAFE_D3D_CALL( pD3DDevice->CreateBlendState(&BlendStateDesc, &m_pBlendState_Multiply_PreserveAlpha) );

    //
    // Create BlendState_Disabled_PreserveAlpha
    //

    BlendStateDesc.RenderTarget[0].BlendEnable = FALSE;

    SAFE_D3D_CALL( pD3DDevice->CreateBlendState(&BlendStateDesc, &m_pBlendState_Disabled_PreserveAlpha) );
}

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::CreateDepthStencilStates(ID3D11Device* pD3DDevice)
{
    //
    // Create DepthStencilState_Disabled
    //

    static D3D11_DEPTH_STENCIL_DESC DepthStencilDesc = 
    {0x0, //DepthEnable
     D3D11_DEPTH_WRITE_MASK_ZERO, //DepthWriteMask
     D3D11_COMPARISON_NEVER, //DepthFunc
     0x0, //StencilEnable
     0xFF, //StencilReadMask
     0xFF, //StencilWriteMask
     
    {D3D11_STENCIL_OP_KEEP, //StencilFailOp
     D3D11_STENCIL_OP_KEEP, //StencilDepthFailOp
     D3D11_STENCIL_OP_KEEP, //StencilPassOp
     D3D11_COMPARISON_ALWAYS  //StencilFunc
    }, //FrontFace
     
    {D3D11_STENCIL_OP_KEEP, //StencilFailOp
     D3D11_STENCIL_OP_KEEP, //StencilDepthFailOp
     D3D11_STENCIL_OP_KEEP, //StencilPassOp
     D3D11_COMPARISON_ALWAYS  //StencilFunc
    }  //BackFace
    };

    SAFE_D3D_CALL( pD3DDevice->CreateDepthStencilState(&DepthStencilDesc, &m_pDepthStencilState_Disabled) );
}

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::CreateRasterizerStates(ID3D11Device* pD3DDevice)
{
    //
    // Create RasterizerState_Fullscreen_NoScissor
    //

    static D3D11_RASTERIZER_DESC D3D11_RASTERIZER_DESC_0 = 
    {D3D11_FILL_SOLID, //FillMode
     D3D11_CULL_BACK, //CullMode
     0x0, //FrontCounterClockwise
     0x0/*0.000000f*/, //DepthBias
                   0.f, //DepthBiasClamp
                   0.f, //SlopeScaledDepthBias
     0x1, //DepthClipEnable
     0x0, //ScissorEnable
     0x0, //MultisampleEnable
     0x0  //AntialiasedLineEnable
    };

    SAFE_D3D_CALL( pD3DDevice->CreateRasterizerState(&D3D11_RASTERIZER_DESC_0, &m_pRasterizerState_Fullscreen_NoScissor) );
}

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::CreateSamplerStates(ID3D11Device* pD3DDevice)
{
    //
    // Create SamplerState_PointClamp
    //

    D3D11_SAMPLER_DESC SamplerDesc;
    memset(&SamplerDesc, 0, sizeof(SamplerDesc));
    SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
    SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
    SamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
    SamplerDesc.MipLODBias = 0.0f;
    SamplerDesc.MaxAnisotropy = 1;
    SamplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    SamplerDesc.BorderColor[0] = -D3D11_FLOAT32_MAX;
    SamplerDesc.MinLOD = 0;
    SamplerDesc.MaxLOD = 0;

    SAFE_D3D_CALL( pD3DDevice->CreateSamplerState(&SamplerDesc, &m_pSamplerState_PointClamp) );

    //
    // Create SamplerState_PointBorder
    //

    SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
    SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;

    SAFE_D3D_CALL( pD3DDevice->CreateSamplerState(&SamplerDesc, &m_pSamplerState_PointBorder) );

    //
    // Create SamplerState_LinearClamp
    //

    SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
    SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
    SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;

    SAFE_D3D_CALL( pD3DDevice->CreateSamplerState(&SamplerDesc, &m_pSamplerState_LinearClamp) );

#if ENABLE_DEBUG_MODES
    //
    // Create SamplerState_PointWrap
    //

    SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;

    SAFE_D3D_CALL( pD3DDevice->CreateSamplerState(&SamplerDesc, &m_pSamplerState_PointWrap) );
#endif
}

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::Create(ID3D11Device* pD3DDevice)
{
    CreateBlendStates(pD3DDevice);
    CreateDepthStencilStates(pD3DDevice);
    CreateRasterizerStates(pD3DDevice);
    CreateSamplerStates(pD3DDevice);
}

//--------------------------------------------------------------------------------
void GFSDK::SSAO::D3D11::States::Release()
{
    SAFE_RELEASE(m_pBlendState_Disabled);
    SAFE_RELEASE(m_pBlendState_Multiply_PreserveAlpha);
    SAFE_RELEASE(m_pBlendState_Disabled_PreserveAlpha);
    SAFE_RELEASE(m_pDepthStencilState_Disabled);
    SAFE_RELEASE(m_pRasterizerState_Fullscreen_NoScissor);
    SAFE_RELEASE(m_pSamplerState_PointClamp);
    SAFE_RELEASE(m_pSamplerState_PointBorder);
    SAFE_RELEASE(m_pSamplerState_LinearClamp);
#if ENABLE_DEBUG_MODES
    SAFE_RELEASE(m_pSamplerState_PointWrap);
#endif
}

#endif // SUPPORT_D3D11