use vk;
#[derive(Debug, Clone, PartialEq)]
pub struct Blend {
pub logic_op: Option<LogicOp>,
pub attachments: AttachmentsBlend,
pub blend_constants: Option<[f32; 4]>,
}
impl Blend {
#[inline]
pub fn pass_through() -> Blend {
Blend {
logic_op: None,
attachments: AttachmentsBlend::Collective(AttachmentBlend::pass_through()),
blend_constants: Some([0.0, 0.0, 0.0, 0.0]),
}
}
#[inline]
pub fn alpha_blending() -> Blend {
Blend {
logic_op: None,
attachments: AttachmentsBlend::Collective(AttachmentBlend::alpha_blending()),
blend_constants: Some([0.0, 0.0, 0.0, 0.0]),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AttachmentsBlend {
Collective(AttachmentBlend),
Individual(Vec<AttachmentBlend>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttachmentBlend {
pub enabled: bool,
pub color_op: BlendOp,
pub color_source: BlendFactor,
pub color_destination: BlendFactor,
pub alpha_op: BlendOp,
pub alpha_source: BlendFactor,
pub alpha_destination: BlendFactor,
pub mask_red: bool,
pub mask_green: bool,
pub mask_blue: bool,
pub mask_alpha: bool,
}
impl AttachmentBlend {
#[inline]
pub fn pass_through() -> AttachmentBlend {
AttachmentBlend {
enabled: false,
color_op: BlendOp::Add,
color_source: BlendFactor::Zero,
color_destination: BlendFactor::One,
alpha_op: BlendOp::Add,
alpha_source: BlendFactor::Zero,
alpha_destination: BlendFactor::One,
mask_red: true,
mask_green: true,
mask_blue: true,
mask_alpha: true,
}
}
#[inline]
pub fn ignore_source() -> AttachmentBlend {
AttachmentBlend {
enabled: true,
color_op: BlendOp::Add,
color_source: BlendFactor::Zero,
color_destination: BlendFactor::DstColor,
alpha_op: BlendOp::Add,
alpha_source: BlendFactor::Zero,
alpha_destination: BlendFactor::DstColor,
mask_red: true,
mask_green: true,
mask_blue: true,
mask_alpha: true,
}
}
#[inline]
pub fn alpha_blending() -> AttachmentBlend {
AttachmentBlend {
enabled: true,
color_op: BlendOp::Add,
color_source: BlendFactor::SrcAlpha,
color_destination: BlendFactor::OneMinusSrcAlpha,
alpha_op: BlendOp::Add,
alpha_source: BlendFactor::SrcAlpha,
alpha_destination: BlendFactor::OneMinusSrcAlpha,
mask_red: true,
mask_green: true,
mask_blue: true,
mask_alpha: true,
}
}
#[inline]
pub(crate) fn into_vulkan_state(self) -> vk::PipelineColorBlendAttachmentState {
vk::PipelineColorBlendAttachmentState {
blendEnable: if self.enabled { vk::TRUE } else { vk::FALSE },
srcColorBlendFactor: self.color_source as u32,
dstColorBlendFactor: self.color_destination as u32,
colorBlendOp: self.color_op as u32,
srcAlphaBlendFactor: self.alpha_source as u32,
dstAlphaBlendFactor: self.alpha_destination as u32,
alphaBlendOp: self.alpha_op as u32,
colorWriteMask: {
let mut mask = 0;
if self.mask_red {
mask |= vk::COLOR_COMPONENT_R_BIT;
}
if self.mask_green {
mask |= vk::COLOR_COMPONENT_G_BIT;
}
if self.mask_blue {
mask |= vk::COLOR_COMPONENT_B_BIT;
}
if self.mask_alpha {
mask |= vk::COLOR_COMPONENT_A_BIT;
}
mask
},
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u32)]
pub enum LogicOp {
Clear = vk::LOGIC_OP_CLEAR,
And = vk::LOGIC_OP_AND,
AndReverse = vk::LOGIC_OP_AND_REVERSE,
Copy = vk::LOGIC_OP_COPY,
AndInverted = vk::LOGIC_OP_AND_INVERTED,
Noop = vk::LOGIC_OP_NO_OP,
Xor = vk::LOGIC_OP_XOR,
Or = vk::LOGIC_OP_OR,
Nor = vk::LOGIC_OP_NOR,
Equivalent = vk::LOGIC_OP_EQUIVALENT,
Invert = vk::LOGIC_OP_INVERT,
OrReverse = vk::LOGIC_OP_OR_REVERSE,
CopyInverted = vk::LOGIC_OP_COPY_INVERTED,
OrInverted = vk::LOGIC_OP_OR_INVERTED,
Nand = vk::LOGIC_OP_NAND,
Set = vk::LOGIC_OP_SET,
}
impl Default for LogicOp {
#[inline]
fn default() -> LogicOp {
LogicOp::Noop
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u32)]
pub enum BlendOp {
Add = vk::BLEND_OP_ADD,
Subtract = vk::BLEND_OP_SUBTRACT,
ReverseSubtract = vk::BLEND_OP_REVERSE_SUBTRACT,
Min = vk::BLEND_OP_MIN,
Max = vk::BLEND_OP_MAX,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u32)]
pub enum BlendFactor {
Zero = vk::BLEND_FACTOR_ZERO,
One = vk::BLEND_FACTOR_ONE,
SrcColor = vk::BLEND_FACTOR_SRC_COLOR,
OneMinusSrcColor = vk::BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
DstColor = vk::BLEND_FACTOR_DST_COLOR,
OneMinusDstColor = vk::BLEND_FACTOR_ONE_MINUS_DST_COLOR,
SrcAlpha = vk::BLEND_FACTOR_SRC_ALPHA,
OneMinusSrcAlpha = vk::BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
DstAlpha = vk::BLEND_FACTOR_DST_ALPHA,
OneMinusDstAlpha = vk::BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
ConstantColor = vk::BLEND_FACTOR_CONSTANT_COLOR,
OneMinusConstantColor = vk::BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
ConstantAlpha = vk::BLEND_FACTOR_CONSTANT_ALPHA,
OneMinusConstantAlpha = vk::BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
SrcAlphaSaturate = vk::BLEND_FACTOR_SRC_ALPHA_SATURATE,
Src1Color = vk::BLEND_FACTOR_SRC1_COLOR,
OneMinusSrc1Color = vk::BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
Src1Alpha = vk::BLEND_FACTOR_SRC1_ALPHA,
OneMinusSrc1Alpha = vk::BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
}