Diligent Engine  v.2.4.g
BlendState.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 // clang-format off
31 
34 
35 #include "../../../Primitives/interface/BasicTypes.h"
36 #include "Constants.h"
37 
39 
40 
41 
51 {
54 
58 
62 
66 
70 
74 
78 
82 
86 
90 
94 
99 
103 
107 
111 
115 
119 
123 
126 };
127 
128 
130 
139 {
142 
146 
150 
154 
158 
162 
165 };
166 
167 
169 
173 {
176 
179 
182 
185 
188 
191 };
192 
193 
195 
202 {
206 
210 
214 
218 
222 
226 
230 
234 
238 
242 
246 
250 
254 
258 
262 
266 
269 };
270 
271 
273 
277 {
279  Bool BlendEnable DEFAULT_INITIALIZER(False);
280 
282  Bool LogicOperationEnable DEFAULT_INITIALIZER(False);
283 
287 
291 
296 
301 
306 
311 
315 
318  Uint8 RenderTargetWriteMask DEFAULT_INITIALIZER(COLOR_MASK_ALL);
319 
320 #if DILIGENT_CPP_INTERFACE
321 
323 
324  explicit
326  Bool _LogicOperationEnable = RenderTargetBlendDesc{}.LogicOperationEnable ,
334  Uint8 _RenderTargetWriteMask = RenderTargetBlendDesc{}.RenderTargetWriteMask) :
335  BlendEnable {_BlendEnable },
336  LogicOperationEnable {_LogicOperationEnable },
337  SrcBlend {_SrcBlend },
338  DestBlend {_DestBlend },
339  BlendOp {_BlendOp },
340  SrcBlendAlpha {_SrcBlendAlpha },
341  DestBlendAlpha {_DestBlendAlpha },
342  BlendOpAlpha {_BlendOpAlpha },
343  LogicOp {_LogicOp },
344  RenderTargetWriteMask{_RenderTargetWriteMask}
345  {}
346 
348 
353  bool operator == (const RenderTargetBlendDesc& rhs)const
354  {
355  return BlendEnable == rhs.BlendEnable &&
356  LogicOperationEnable == rhs.LogicOperationEnable &&
357  SrcBlend == rhs.SrcBlend &&
358  DestBlend == rhs.DestBlend &&
359  BlendOp == rhs.BlendOp &&
360  SrcBlendAlpha == rhs.SrcBlendAlpha &&
361  DestBlendAlpha == rhs.DestBlendAlpha &&
362  BlendOpAlpha == rhs.BlendOpAlpha &&
363  LogicOp == rhs.LogicOp &&
364  RenderTargetWriteMask == rhs.RenderTargetWriteMask;
365  }
366 #endif
367 };
369 
370 
372 
375 {
378  Bool AlphaToCoverageEnable DEFAULT_INITIALIZER(False);
379 
382  Bool IndependentBlendEnable DEFAULT_INITIALIZER(False);
383 
387 
388 #if DILIGENT_CPP_INTERFACE
389  // We have to explicitly define constructors because otherwise Apple's clang fails to compile the following legitimate code:
390  // BlendStateDesc{False, False}
391 
392  BlendStateDesc() noexcept {}
393 
394  BlendStateDesc(Bool _AlphaToCoverageEnable,
395  Bool _IndependentBlendEnable,
396  const RenderTargetBlendDesc& RT0 = RenderTargetBlendDesc{}) noexcept :
397  AlphaToCoverageEnable {_AlphaToCoverageEnable },
398  IndependentBlendEnable {_IndependentBlendEnable},
399  RenderTargets {RT0}
400  {
401  }
402 
404 
413  bool operator==(const BlendStateDesc& RHS) const
414  {
415  bool bRTsEqual = true;
416  for (size_t i = 0; i < MAX_RENDER_TARGETS; ++i)
417  {
418  if (!(RenderTargets[i] == RHS.RenderTargets[i]))
419  {
420  bRTsEqual = false;
421  break;
422  }
423  }
424 
425  return bRTsEqual &&
426  AlphaToCoverageEnable == RHS.AlphaToCoverageEnable &&
427  IndependentBlendEnable == RHS.IndependentBlendEnable;
428  }
429 #endif
430 };
432 
433 DILIGENT_END_NAMESPACE // namespace Diligent
Diligent::RenderTargetBlendDesc::SrcBlend
BLEND_FACTOR SrcBlend
Specifies the blend factor to apply to the RGB value output from the pixel shader Default value: Dili...
Definition: BlendState.h:286
Diligent::RenderTargetBlendDesc
Describes a blend state for a single render target.
Definition: BlendState.h:276
Diligent::BLEND_OPERATION_REV_SUBTRACT
@ BLEND_OPERATION_REV_SUBTRACT
Subtract source color components from destination color components. Direct3D counterpart: D3D11_BLEN...
Definition: BlendState.h:153
Diligent::RenderTargetBlendDesc::LogicOp
LOGIC_OPERATION LogicOp
Defines logical operation for the render target. Default value: Diligent::LOGIC_OP_NOOP.
Definition: BlendState.h:314
Diligent::LOGIC_OP_INVERT
@ LOGIC_OP_INVERT
Invert the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_INVERT.
Definition: BlendState.h:225
Diligent::BlendStateDesc::IndependentBlendEnable
Bool IndependentBlendEnable
Specifies whether to enable independent blending in simultaneous render targets. If set to False,...
Definition: BlendState.h:382
Diligent::BLEND_FACTOR_INV_BLEND_FACTOR
@ BLEND_FACTOR_INV_BLEND_FACTOR
The blend factor is one minus constant blend factor set with IDeviceContext::SetBlendFactors()....
Definition: BlendState.h:106
Diligent::BLEND_FACTOR_INV_SRC1_ALPHA
@ BLEND_FACTOR_INV_SRC1_ALPHA
The blend factor is 1-A, where A is the second alpha data output from a pixel shader....
Definition: BlendState.h:122
Diligent::BLEND_FACTOR_NUM_FACTORS
@ BLEND_FACTOR_NUM_FACTORS
Helper value that stores the total number of blend factors in the enumeration.
Definition: BlendState.h:125
Diligent::BlendStateDesc::AlphaToCoverageEnable
Bool AlphaToCoverageEnable
Specifies whether to use alpha-to-coverage as a multisampling technique when setting a pixel to a ren...
Definition: BlendState.h:378
Diligent::BLEND_OPERATION_NUM_OPERATIONS
@ BLEND_OPERATION_NUM_OPERATIONS
Helper value that stores the total number of blend operations in the enumeration.
Definition: BlendState.h:164
Diligent::BLEND_OPERATION_UNDEFINED
@ BLEND_OPERATION_UNDEFINED
Undefined blend operation.
Definition: BlendState.h:141
Diligent::LOGIC_OP_NOR
@ LOGIC_OP_NOR
Perform a logical NOR operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_NOR.
Definition: BlendState.h:241
Diligent::RenderTargetBlendDesc::RenderTargetBlendDesc
RenderTargetBlendDesc() noexcept
Definition: BlendState.h:322
Diligent::BLEND_FACTOR_SRC_ALPHA_SAT
@ BLEND_FACTOR_SRC_ALPHA_SAT
The blend factor is (f,f,f,1), where f = min(As, 1-Ad), As is alpha data from a pixel shader,...
Definition: BlendState.h:98
Diligent::LOGIC_OP_OR
@ LOGIC_OP_OR
Perform a logical OR operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_OR.
Definition: BlendState.h:237
Diligent::LOGIC_OP_AND_REVERSE
@ LOGIC_OP_AND_REVERSE
Perform a logical AND and reverse operation on the render target. Direct3D12 counterpart: D3D12_LOGI...
Definition: BlendState.h:253
Diligent::operator==
bool operator==(const Plane3D &p1, const Plane3D &p2)
Definition: AdvancedMath.hpp:442
Diligent::LOGIC_OP_NUM_OPERATIONS
@ LOGIC_OP_NUM_OPERATIONS
Helper value that stores the total number of logical operations in the enumeration.
Definition: BlendState.h:268
Diligent::BLEND_OPERATION_ADD
@ BLEND_OPERATION_ADD
Add source and destination color components. Direct3D counterpart: D3D11_BLEND_OP_ADD/D3D12_BLEND_OP...
Definition: BlendState.h:145
Diligent::LOGIC_OP_SET
@ LOGIC_OP_SET
Set the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_SET.
Definition: BlendState.h:209
Diligent::RenderTargetBlendDesc::LogicOperationEnable
Bool LogicOperationEnable
Enable or disable a logical operation for this render target. Default value: False.
Definition: BlendState.h:282
Diligent::COLOR_MASK_RED
@ COLOR_MASK_RED
Allow data to be stored in the red component.
Definition: BlendState.h:178
Constants.h
Diligent::BLEND_FACTOR_INV_DEST_COLOR
@ BLEND_FACTOR_INV_DEST_COLOR
The blend factor is 1-RGB, where RGB is the data from a render target. Direct3D counterpart: D3D11_B...
Definition: BlendState.h:93
Diligent::BLEND_OPERATION_MIN
@ BLEND_OPERATION_MIN
Compute the minimum of source and destination color components. Direct3D counterpart: D3D11_BLEND_OP...
Definition: BlendState.h:157
Diligent::COLOR_MASK_ALL
@ COLOR_MASK_ALL
Allow data to be stored in all components.
Definition: BlendState.h:190
Diligent::LOGIC_OP_OR_REVERSE
@ LOGIC_OP_OR_REVERSE
Perform a logical OR and reverse operation on the render target. Direct3D12 counterpart: D3D12_LOGIC...
Definition: BlendState.h:261
Diligent::BLEND_FACTOR
BLEND_FACTOR
Blend factors.
Definition: BlendState.h:50
Diligent::BlendStateDesc::BlendStateDesc
BlendStateDesc() noexcept
Definition: BlendState.h:392
Diligent::BLEND_FACTOR_INV_SRC1_COLOR
@ BLEND_FACTOR_INV_SRC1_COLOR
The blend factor is 1-RGB, where RGB is the second RGB data output from a pixel shader....
Definition: BlendState.h:114
Diligent::Int8
int8_t Int8
8-bit signed integer
Definition: BasicTypes.h:48
Diligent::RenderTargetBlendDesc::BlendEnable
Bool BlendEnable
Enable or disable blending for this render target. Default value: False.
Definition: BlendState.h:279
Diligent::LOGIC_OP_NAND
@ LOGIC_OP_NAND
Perform a logical NAND operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_NAND.
Definition: BlendState.h:233
Diligent::BLEND_FACTOR_UNDEFINED
@ BLEND_FACTOR_UNDEFINED
Undefined blend factor.
Definition: BlendState.h:53
Diligent::BLEND_FACTOR_SRC_ALPHA
@ BLEND_FACTOR_SRC_ALPHA
The blend factor is alpha (A) data from a pixel shader. Direct3D counterpart: D3D11_BLEND_SRC_ALPHA/...
Definition: BlendState.h:73
DILIGENT_END_NAMESPACE
#define DILIGENT_END_NAMESPACE
Definition: CommonDefinitions.h:86
Diligent::BlendStateDesc::RenderTargets
RenderTargetBlendDesc RenderTargets[DILIGENT_MAX_RENDER_TARGETS]
An array of RenderTargetBlendDesc structures that describe the blend states for render targets.
Definition: BlendState.h:386
Diligent::BLEND_OPERATION_SUBTRACT
@ BLEND_OPERATION_SUBTRACT
Subtract destination color components from source color components. Direct3D counterpart: D3D11_BLEN...
Definition: BlendState.h:149
Diligent::LOGIC_OP_XOR
@ LOGIC_OP_XOR
Perform a logical XOR operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_XOR.
Definition: BlendState.h:245
Diligent::BLEND_FACTOR_ONE
@ BLEND_FACTOR_ONE
The blend factor is one. Direct3D counterpart: D3D11_BLEND_ONE/D3D12_BLEND_ONE. OpenGL counterpart: ...
Definition: BlendState.h:61
Diligent::LOGIC_OP_AND_INVERTED
@ LOGIC_OP_AND_INVERTED
Perform a logical AND and invert operation on the render target. Direct3D12 counterpart: D3D12_LOGIC...
Definition: BlendState.h:257
DEFAULT_INITIALIZER
#define DEFAULT_INITIALIZER(x)
Definition: CommonDefinitions.h:93
Diligent::Bool
bool Bool
Boolean.
Definition: BasicTypes.h:59
Diligent::BLEND_FACTOR_ZERO
@ BLEND_FACTOR_ZERO
The blend factor is zero. Direct3D counterpart: D3D11_BLEND_ZERO/D3D12_BLEND_ZERO....
Definition: BlendState.h:57
Diligent::BLEND_FACTOR_INV_DEST_ALPHA
@ BLEND_FACTOR_INV_DEST_ALPHA
The blend factor is 1-A, where A is alpha data from a render target. Direct3D counterpart: D3D11_BLE...
Definition: BlendState.h:85
Diligent::BLEND_FACTOR_SRC_COLOR
@ BLEND_FACTOR_SRC_COLOR
The blend factor is RGB data from a pixel shader. Direct3D counterpart: D3D11_BLEND_SRC_COLOR/D3D12_...
Definition: BlendState.h:65
Diligent::LOGIC_OP_COPY_INVERTED
@ LOGIC_OP_COPY_INVERTED
Perform an inverted-copy of the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_COPY_INVERTED.
Definition: BlendState.h:217
Diligent::BLEND_FACTOR_DEST_ALPHA
@ BLEND_FACTOR_DEST_ALPHA
The blend factor is alpha (A) data from a render target. Direct3D counterpart: D3D11_BLEND_DEST_ALPH...
Definition: BlendState.h:81
Diligent::RenderTargetBlendDesc::SrcBlendAlpha
BLEND_FACTOR SrcBlendAlpha
Specifies the blend factor to apply to the alpha value output from the pixel shader....
Definition: BlendState.h:300
Diligent::BLEND_FACTOR_INV_SRC_ALPHA
@ BLEND_FACTOR_INV_SRC_ALPHA
The blend factor is 1-A, where A is alpha data from a pixel shader. Direct3D counterpart: D3D11_BLEN...
Definition: BlendState.h:77
Diligent::BLEND_FACTOR_BLEND_FACTOR
@ BLEND_FACTOR_BLEND_FACTOR
The blend factor is the constant blend factor set with IDeviceContext::SetBlendFactors()....
Definition: BlendState.h:102
Diligent::LOGIC_OPERATION
LOGIC_OPERATION
Logic operation.
Definition: BlendState.h:201
Diligent::RenderTargetBlendDesc::DestBlend
BLEND_FACTOR DestBlend
Specifies the blend factor to apply to the RGB value in the render target Default value: Diligent::BL...
Definition: BlendState.h:290
Diligent::RenderTargetBlendDesc::BlendOp
BLEND_OPERATION BlendOp
Defines how to combine the source and destination RGB values after applying the SrcBlend and DestBlen...
Definition: BlendState.h:295
Diligent::COLOR_MASK
COLOR_MASK
Color component write flags.
Definition: BlendState.h:172
Diligent::BLEND_FACTOR_SRC1_ALPHA
@ BLEND_FACTOR_SRC1_ALPHA
The blend factor is the second alpha (A) data output from a pixel shader. Direct3D counterpart: D3D1...
Definition: BlendState.h:118
Diligent::BLEND_FACTOR_SRC1_COLOR
@ BLEND_FACTOR_SRC1_COLOR
The blend factor is the second RGB data output from a pixel shader. Direct3D counterpart: D3D11_BLEN...
Definition: BlendState.h:110
Diligent::RenderTargetBlendDesc::RenderTargetWriteMask
Uint8 RenderTargetWriteMask
Render target write mask. Default value: Diligent::COLOR_MASK_ALL.
Definition: BlendState.h:318
Diligent::BLEND_OPERATION_MAX
@ BLEND_OPERATION_MAX
Compute the maximum of source and destination color components. Direct3D counterpart: D3D11_BLEND_OP...
Definition: BlendState.h:161
DILIGENT_TYPED_ENUM
#define DILIGENT_TYPED_ENUM(EnumName, EnumType)
Definition: CommonDefinitions.h:88
Diligent::BLEND_FACTOR_DEST_COLOR
@ BLEND_FACTOR_DEST_COLOR
The blend factor is RGB data from a render target. Direct3D counterpart: D3D11_BLEND_DEST_COLOR/D3D1...
Definition: BlendState.h:89
Diligent::LOGIC_OP_NOOP
@ LOGIC_OP_NOOP
No operation is performed on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_NOOP.
Definition: BlendState.h:221
Diligent::BlendStateDesc::BlendStateDesc
BlendStateDesc(Bool _AlphaToCoverageEnable, Bool _IndependentBlendEnable, const RenderTargetBlendDesc &RT0=RenderTargetBlendDesc{}) noexcept
Definition: BlendState.h:394
Diligent::LOGIC_OP_OR_INVERTED
@ LOGIC_OP_OR_INVERTED
Perform a logical OR and invert operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_...
Definition: BlendState.h:265
Diligent::COLOR_MASK_GREEN
@ COLOR_MASK_GREEN
Allow data to be stored in the green component.
Definition: BlendState.h:181
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
Diligent::RenderTargetBlendDesc::BlendOpAlpha
BLEND_OPERATION BlendOpAlpha
Defines how to combine the source and destination alpha values after applying the SrcBlendAlpha and D...
Definition: BlendState.h:310
Diligent::BLEND_OPERATION
BLEND_OPERATION
Blending operation.
Definition: BlendState.h:138
DILIGENT_BEGIN_NAMESPACE
#define DILIGENT_BEGIN_NAMESPACE(Name)
Definition: CommonDefinitions.h:82
Diligent::LOGIC_OP_COPY
@ LOGIC_OP_COPY
Copy the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_COPY.
Definition: BlendState.h:213
Diligent::BLEND_FACTOR_INV_SRC_COLOR
@ BLEND_FACTOR_INV_SRC_COLOR
The blend factor is 1-RGB, where RGB is the data from a pixel shader. Direct3D counterpart: D3D11_BL...
Definition: BlendState.h:69
Diligent::RenderTargetBlendDesc
struct RenderTargetBlendDesc RenderTargetBlendDesc
Definition: BlendState.h:368
Diligent::COLOR_MASK_NONE
@ COLOR_MASK_NONE
Do not store any components.
Definition: BlendState.h:175
Diligent::RenderTargetBlendDesc::DestBlendAlpha
BLEND_FACTOR DestBlendAlpha
Specifies the blend factor to apply to the alpha value in the render target. Blend factors that end i...
Definition: BlendState.h:305
Diligent::LOGIC_OP_CLEAR
@ LOGIC_OP_CLEAR
Clear the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_CLEAR.
Definition: BlendState.h:205
Diligent::COLOR_MASK_ALPHA
@ COLOR_MASK_ALPHA
Allow data to be stored in the alpha component.
Definition: BlendState.h:187
Diligent::LOGIC_OP_EQUIV
@ LOGIC_OP_EQUIV
Perform a logical equal operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_EQUIV...
Definition: BlendState.h:249
Diligent::COLOR_MASK_BLUE
@ COLOR_MASK_BLUE
Allow data to be stored in the blue component.
Definition: BlendState.h:184
DILIGENT_MAX_RENDER_TARGETS
#define DILIGENT_MAX_RENDER_TARGETS
The maximum number of simultaneous render targets.
Definition: Constants.h:42
Diligent::RenderTargetBlendDesc::RenderTargetBlendDesc
RenderTargetBlendDesc(Bool _BlendEnable, Bool _LogicOperationEnable=RenderTargetBlendDesc{}.LogicOperationEnable, BLEND_FACTOR _SrcBlend=RenderTargetBlendDesc{}.SrcBlend, BLEND_FACTOR _DestBlend=RenderTargetBlendDesc{}.DestBlend, BLEND_OPERATION _BlendOp=RenderTargetBlendDesc{}.BlendOp, BLEND_FACTOR _SrcBlendAlpha=RenderTargetBlendDesc{}.SrcBlendAlpha, BLEND_FACTOR _DestBlendAlpha=RenderTargetBlendDesc{}.DestBlendAlpha, BLEND_OPERATION _BlendOpAlpha=RenderTargetBlendDesc{}.BlendOpAlpha, LOGIC_OPERATION _LogicOp=RenderTargetBlendDesc{}.LogicOp, Uint8 _RenderTargetWriteMask=RenderTargetBlendDesc{}.RenderTargetWriteMask)
Definition: BlendState.h:325
Diligent::LOGIC_OP_AND
@ LOGIC_OP_AND
Perform a logical AND operation on the render target. Direct3D12 counterpart: D3D12_LOGIC_OP_AND.
Definition: BlendState.h:229
Diligent::BlendStateDesc
Blend state description.
Definition: BlendState.h:374
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::BlendStateDesc::operator==
bool operator==(const BlendStateDesc &RHS) const
Comparison operator tests if two structures are equivalent.
Definition: BlendState.h:413