FCT
载入中...
搜索中...
未找到
VK_BlendState.cpp
浏览该文件的文档.
1#include "../FCTAPI.h"
2namespace FCT
3{
8
10 {
11 // 清理之前的状态
12 m_attachmentStates.clear();
13 m_attachmentStates.reserve(m_targets.size());
14
15 // 为每个目标创建 attachment state
16 for (const auto& target : m_targets) {
17 vk::PipelineColorBlendAttachmentState attachmentState{};
18 attachmentState.blendEnable = target.enable;
19 attachmentState.srcColorBlendFactor = convertBlendFactor(target.srcColor);
20 attachmentState.dstColorBlendFactor = convertBlendFactor(target.dstColor);
21 attachmentState.colorBlendOp = convertBlendOp(target.colorOp);
22 attachmentState.srcAlphaBlendFactor = convertBlendFactor(target.srcAlpha);
23 attachmentState.dstAlphaBlendFactor = convertBlendFactor(target.dstAlpha);
24 attachmentState.alphaBlendOp = convertBlendOp(target.alphaOp);
25 attachmentState.colorWriteMask = static_cast<vk::ColorComponentFlags>(target.mask);
26
27 m_attachmentStates.push_back(attachmentState);
28 }
29
30 m_createInfo = vk::PipelineColorBlendStateCreateInfo()
31 .setLogicOpEnable(m_logicEnable)
32 .setLogicOp(convertLogicOp(m_logicOp))
33 .setAttachmentCount(static_cast<uint32_t>(m_attachmentStates.size()))
34 .setPAttachments(m_attachmentStates.data())
35 .setBlendConstants({0.0f, 0.0f, 0.0f, 0.0f});
36 }
37
38 vk::BlendFactor VK_BlendState::convertBlendFactor(BlendFactor factor) const
39 {
40 switch (factor)
41 {
42 case BlendFactor::Zero: return vk::BlendFactor::eZero;
43 case BlendFactor::One: return vk::BlendFactor::eOne;
44 case BlendFactor::SrcColor: return vk::BlendFactor::eSrcColor;
45 case BlendFactor::OneMinusSrcColor: return vk::BlendFactor::eOneMinusSrcColor;
46 case BlendFactor::DstColor: return vk::BlendFactor::eDstColor;
47 case BlendFactor::OneMinusDstColor: return vk::BlendFactor::eOneMinusDstColor;
48 case BlendFactor::SrcAlpha: return vk::BlendFactor::eSrcAlpha;
49 case BlendFactor::OneMinusSrcAlpha: return vk::BlendFactor::eOneMinusSrcAlpha;
50 case BlendFactor::DstAlpha: return vk::BlendFactor::eDstAlpha;
51 case BlendFactor::OneMinusDstAlpha: return vk::BlendFactor::eOneMinusDstAlpha;
52 case BlendFactor::ConstantColor: return vk::BlendFactor::eConstantColor;
53 case BlendFactor::OneMinusConstantColor: return vk::BlendFactor::eOneMinusConstantColor;
54 case BlendFactor::Src1Color: return vk::BlendFactor::eSrc1Color;
55 case BlendFactor::OneMinusSrc1Color: return vk::BlendFactor::eOneMinusSrc1Color;
56 case BlendFactor::Src1Alpha: return vk::BlendFactor::eSrc1Alpha;
57 case BlendFactor::OneMinusSrc1Alpha: return vk::BlendFactor::eOneMinusSrc1Alpha;
58 default: return vk::BlendFactor::eOne;
59 }
60 }
61
63 {
64 switch (op)
65 {
66 case BlendOp::Add: return vk::BlendOp::eAdd;
67 case BlendOp::Subtract: return vk::BlendOp::eSubtract;
68 case BlendOp::ReverseSubtract: return vk::BlendOp::eReverseSubtract;
69 case BlendOp::Min: return vk::BlendOp::eMin;
70 case BlendOp::Max: return vk::BlendOp::eMax;
71 default: return vk::BlendOp::eAdd;
72 }
73 }
74
76 {
77 switch (op)
78 {
79 case LogicOp::Clear: return vk::LogicOp::eClear;
80 case LogicOp::And: return vk::LogicOp::eAnd;
81 case LogicOp::AndReverse: return vk::LogicOp::eAndReverse;
82 case LogicOp::Copy: return vk::LogicOp::eCopy;
83 case LogicOp::AndInverted: return vk::LogicOp::eAndInverted;
84 case LogicOp::NoOp: return vk::LogicOp::eNoOp;
85 case LogicOp::Xor: return vk::LogicOp::eXor;
86 case LogicOp::Or: return vk::LogicOp::eOr;
87 case LogicOp::Nor: return vk::LogicOp::eNor;
88 case LogicOp::Equivalent: return vk::LogicOp::eEquivalent;
89 case LogicOp::Invert: return vk::LogicOp::eInvert;
90 case LogicOp::OrReverse: return vk::LogicOp::eOrReverse;
91 case LogicOp::CopyInverted: return vk::LogicOp::eCopyInverted;
92 case LogicOp::OrInverted: return vk::LogicOp::eOrInverted;
93 case LogicOp::Nand: return vk::LogicOp::eNand;
94 case LogicOp::Set: return vk::LogicOp::eSet;
95 default: return vk::LogicOp::eCopy;
96 }
97 }
98}
BlendState & op(BlendOp operation, int target=-1)
std::vector< Target > m_targets
vk::PipelineColorBlendStateCreateInfo m_createInfo
vk::BlendOp convertBlendOp(BlendOp op) const
VK_BlendState(VK_Context *ctx)
vk::LogicOp convertLogicOp(LogicOp op) const
vk::BlendFactor convertBlendFactor(BlendFactor factor) const
std::vector< vk::PipelineColorBlendAttachmentState > m_attachmentStates