FCT
载入中...
搜索中...
未找到
BlendState.h
浏览该文件的文档.
2#include <vector>
3
4#ifndef BLENDSTATE_H
5#define BLENDSTATE_H
6
7namespace FCT {
14
16
21
23 public:
24 virtual ~BlendState() override = default;
25 virtual void create() = 0;
26
27 BlendState& enable(bool enable, int target = -1) {
28 setForTargets(target, [=](auto& t) { t.enable = enable; });
29 return *this;
30 }
31
32 BlendState& factors(BlendFactor src, BlendFactor dst, int target = -1) {
33 setForTargets(target, [=](auto& t) {
34 t.srcColor = t.srcAlpha = src;
35 t.dstColor = t.dstAlpha = dst;
36 });
37 return *this;
38 }
39
40 BlendState& colorFactors(BlendFactor src, BlendFactor dst, int target = -1) {
41 setForTargets(target, [=](auto& t) { t.srcColor = src; t.dstColor = dst; });
42 return *this;
43 }
44
45 BlendState& alphaFactors(BlendFactor src, BlendFactor dst, int target = -1) {
46 setForTargets(target, [=](auto& t) { t.srcAlpha = src; t.dstAlpha = dst; });
47 return *this;
48 }
49
50 BlendState& op(BlendOp operation, int target = -1) {
51 setForTargets(target, [=](auto& t) { t.colorOp = t.alphaOp = operation; });
52 return *this;
53 }
54
55 BlendState& mask(uint8_t writeMask, int target = -1) {
56 setForTargets(target, [=](auto& t) { t.mask = writeMask; });
57 return *this;
58 }
59
60 BlendState& logic(LogicOp logicOp, bool enable = true) {
61 m_logicOp = logicOp;
63 return *this;
64 }
65
66 BlendState& alpha(int target = -1) {
67 return enable(true, target)
69 .op(BlendOp::Add, target);
70 }
71
72 BlendState& additive(int target = -1) {
73 return enable(true, target)
76 .op(BlendOp::Add, target);
77 }
78
79 BlendState& multiply(int target = -1) {
80 return enable(true, target)
82 .op(BlendOp::Add, target);
83 }
84
85 BlendState& opaque(int target = -1) {
86 return enable(false, target)
88 }
89
91 m_targets.resize(count);
92 return *this;
93 }
94
95 bool blendEnable() const { return m_targets.empty() ? false : m_targets[0].enable; }
96 BlendFactor srcColorBlendFactor() const { return m_targets.empty() ? BlendFactor::One : m_targets[0].srcColor; }
97
99
100 protected:
108
109 std::vector<Target> m_targets{1};
110 bool m_logicEnable = false;
112
113 template<typename Func>
114 void setForTargets(int target, Func func) {
115 if (target == -1) {
116 for (auto& t : m_targets) func(t);
117 } else if (target < m_targets.size()) {
118 func(m_targets[target]);
119 }
120 }
121 };
122}
123
124#endif //BLENDSTATE_H
BlendState & mask(uint8_t writeMask, int target=-1)
BlendFactor srcColorBlendFactor() const
virtual void create()=0
BlendState & enable(bool enable, int target=-1)
BlendState & op(BlendOp operation, int target=-1)
void setForTargets(int target, Func func)
BlendState & logic(LogicOp logicOp, bool enable=true)
BlendState & colorFactors(BlendFactor src, BlendFactor dst, int target=-1)
BlendState & alpha(int target=-1)
BlendState & additive(int target=-1)
BlendState & factors(BlendFactor src, BlendFactor dst, int target=-1)
BlendState & targets(int count)
BlendState & opaque(int target=-1)
bool blendEnable() const
BlendState & multiply(int target=-1)
virtual ~BlendState() override=default
PipelineResourceType getType() const override
BlendState & alphaFactors(BlendFactor src, BlendFactor dst, int target=-1)
std::vector< Target > m_targets