GteDX11BlendState.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 DX11BlendState::DX11BlendState (ID3D11Device* device, BlendState const* blendState)
13  :
14  DX11DrawingState(blendState)
15 {
16  // Specify the blend state description.
17  D3D11_BLEND_DESC desc;
18  desc.AlphaToCoverageEnable = (blendState->enableAlphaToCoverage ? TRUE : FALSE);
19  desc.IndependentBlendEnable = (blendState->enableIndependentBlend ? TRUE : FALSE);
20  for (unsigned int i = 0; i < BlendState::NUM_TARGETS; ++i)
21  {
22  D3D11_RENDER_TARGET_BLEND_DESC& out = desc.RenderTarget[i];
23  BlendState::Target const& in = blendState->target[i];
24  out.BlendEnable = (in.enable ? TRUE : FALSE);
25  out.SrcBlend = msMode[in.srcColor];
26  out.DestBlend = msMode[in.dstColor];
27  out.BlendOp = msOperation[in.opColor];
28  out.SrcBlendAlpha = msMode[in.srcAlpha];
29  out.DestBlendAlpha = msMode[in.dstAlpha];
30  out.BlendOpAlpha = msOperation[in.opAlpha];
31  out.RenderTargetWriteMask = in.mask;
32  }
33 
34  // Create the blend state.
35  ID3D11BlendState* state = nullptr;
36  HRESULT hr = device->CreateBlendState(&desc, &state);
37  CHECK_HR_RETURN_NONE("Failed to create blend state");
38  mDXObject = state;
39 }
40 
41 std::shared_ptr<GEObject> DX11BlendState::Create(void* device, GraphicsObject const* object)
42 {
43  if (object->GetType() == GT_BLEND_STATE)
44  {
45  return std::make_shared<DX11BlendState>(
46  reinterpret_cast<ID3D11Device*>(device),
47  static_cast<BlendState const*>(object));
48  }
49 
50  LogError("Invalid object type.");
51  return nullptr;
52 }
53 
54 void DX11BlendState::Enable(ID3D11DeviceContext* context)
55 {
56  BlendState* bState = GetBlendState();
57  context->OMSetBlendState(GetDXBlendState(), &bState->blendColor[0], bState->sampleMask);
58 }
59 
60 
61 D3D11_BLEND const DX11BlendState::msMode[] =
62 {
63  D3D11_BLEND_ZERO,
64  D3D11_BLEND_ONE,
65  D3D11_BLEND_SRC_COLOR,
66  D3D11_BLEND_INV_SRC_COLOR,
67  D3D11_BLEND_SRC_ALPHA,
68  D3D11_BLEND_INV_SRC_ALPHA,
69  D3D11_BLEND_DEST_ALPHA,
70  D3D11_BLEND_INV_DEST_ALPHA,
71  D3D11_BLEND_DEST_COLOR,
72  D3D11_BLEND_INV_DEST_COLOR,
73  D3D11_BLEND_SRC_ALPHA_SAT,
74  D3D11_BLEND_BLEND_FACTOR,
75  D3D11_BLEND_INV_BLEND_FACTOR,
76  D3D11_BLEND_SRC1_COLOR,
77  D3D11_BLEND_INV_SRC1_COLOR,
78  D3D11_BLEND_SRC1_ALPHA,
79  D3D11_BLEND_INV_SRC1_ALPHA
80 };
81 
82 D3D11_BLEND_OP const DX11BlendState::msOperation[] =
83 {
84  D3D11_BLEND_OP_ADD,
85  D3D11_BLEND_OP_SUBTRACT,
86  D3D11_BLEND_OP_REV_SUBTRACT,
87  D3D11_BLEND_OP_MIN,
88  D3D11_BLEND_OP_MAX
89 };
Target target[NUM_TARGETS]
Definition: GteBlendState.h:82
#define CHECK_HR_RETURN_NONE(msg)
DX11BlendState(ID3D11Device *device, BlendState const *blendState)
GraphicsObjectType GetType() const
bool enableAlphaToCoverage
Definition: GteBlendState.h:80
ID3D11BlendState * GetDXBlendState()
#define LogError(message)
Definition: GteLogger.h:92
ID3D11DeviceChild * mDXObject
void Enable(ID3D11DeviceContext *context)
bool enableIndependentBlend
Definition: GteBlendState.h:81
GT_BLEND_STATE
GLuint in
Definition: glext.h:8348
BlendState * GetBlendState()
static std::shared_ptr< GEObject > Create(void *device, GraphicsObject const *object)
static D3D11_BLEND_OP const msOperation[]
unsigned int sampleMask
Definition: GteBlendState.h:84
Vector4< float > blendColor
Definition: GteBlendState.h:83
static D3D11_BLEND const msMode[]


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