GteDX11DepthStencilState.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
12 DX11DepthStencilState::DX11DepthStencilState(ID3D11Device* device, DepthStencilState const* depthStencilState)
13  :
14  DX11DrawingState(depthStencilState)
15 {
16  // Specify the rasterizer state description.
17  D3D11_DEPTH_STENCIL_DESC desc;
18  desc.DepthEnable = (depthStencilState->depthEnable ? TRUE : FALSE);
19  desc.DepthWriteMask = msWriteMask[depthStencilState->writeMask];
20  desc.DepthFunc = msComparison[depthStencilState->comparison];
21  desc.StencilEnable = (depthStencilState->stencilEnable ? TRUE : FALSE);
22  desc.StencilReadMask = depthStencilState->stencilReadMask;
23  desc.StencilWriteMask = depthStencilState->stencilWriteMask;
24  DepthStencilState::Face front = depthStencilState->frontFace;
25  desc.FrontFace.StencilFailOp = msOperation[front.fail];
26  desc.FrontFace.StencilDepthFailOp = msOperation[front.depthFail];
27  desc.FrontFace.StencilPassOp = msOperation[front.pass];
28  desc.FrontFace.StencilFunc = msComparison[front.comparison];
29  DepthStencilState::Face back = depthStencilState->backFace;
30  desc.BackFace.StencilFailOp = msOperation[back.fail];
31  desc.BackFace.StencilDepthFailOp = msOperation[back.depthFail];
32  desc.BackFace.StencilPassOp = msOperation[back.pass];
33  desc.BackFace.StencilFunc = msComparison[back.comparison];
34 
35  // Create the depth-stencil state.
36  ID3D11DepthStencilState* state = nullptr;
37  HRESULT hr = device->CreateDepthStencilState(&desc, &state);
38  CHECK_HR_RETURN_NONE("Failed to create depth-stencil state");
39  mDXObject = state;
40 }
41 
42 std::shared_ptr<GEObject> DX11DepthStencilState::Create(void* device, GraphicsObject const* object)
43 {
44  if (object->GetType() == GT_DEPTH_STENCIL_STATE)
45  {
46  return std::make_shared<DX11DepthStencilState>(
47  reinterpret_cast<ID3D11Device*>(device),
48  static_cast<DepthStencilState const*>(object));
49  }
50 
51  LogError("Invalid object type.");
52  return nullptr;
53 }
54 
55 void DX11DepthStencilState::Enable(ID3D11DeviceContext* context)
56 {
58  context->OMSetDepthStencilState(GetDXDepthStencilState(), dsState->reference);
59 }
60 
61 
62 D3D11_DEPTH_WRITE_MASK const DX11DepthStencilState::msWriteMask[] =
63 {
64  D3D11_DEPTH_WRITE_MASK_ZERO,
65  D3D11_DEPTH_WRITE_MASK_ALL
66 };
67 
68 D3D11_COMPARISON_FUNC const DX11DepthStencilState::msComparison[] =
69 {
70  D3D11_COMPARISON_NEVER,
71  D3D11_COMPARISON_LESS,
72  D3D11_COMPARISON_EQUAL,
73  D3D11_COMPARISON_LESS_EQUAL,
74  D3D11_COMPARISON_GREATER,
75  D3D11_COMPARISON_NOT_EQUAL,
76  D3D11_COMPARISON_GREATER_EQUAL,
77  D3D11_COMPARISON_ALWAYS
78 };
79 
80 D3D11_STENCIL_OP const DX11DepthStencilState::msOperation[] =
81 {
82  D3D11_STENCIL_OP_KEEP,
83  D3D11_STENCIL_OP_ZERO,
84  D3D11_STENCIL_OP_REPLACE,
85  D3D11_STENCIL_OP_INCR_SAT,
86  D3D11_STENCIL_OP_DECR_SAT,
87  D3D11_STENCIL_OP_INVERT,
88  D3D11_STENCIL_OP_INCR,
89  D3D11_STENCIL_OP_DECR
90 };
#define CHECK_HR_RETURN_NONE(msg)
static D3D11_DEPTH_WRITE_MASK const msWriteMask[]
GraphicsObjectType GetType() const
DepthStencilState * GetDepthStencilState()
static D3D11_COMPARISON_FUNC const msComparison[]
ID3D11DepthStencilState * GetDXDepthStencilState()
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
#define LogError(message)
Definition: GteLogger.h:92
ID3D11DeviceChild * mDXObject
static D3D11_STENCIL_OP const msOperation[]
DX11DepthStencilState(ID3D11Device *device, DepthStencilState const *depthStencilState)
void Enable(ID3D11DeviceContext *context)
GT_DEPTH_STENCIL_STATE


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59