#[derive(Copy, Clone, Debug, PartialEq)]
pub struct BlendMode {
pub equation: BlendEquation,
pub function: BlendFunction,
pub global_color: [f32; 4],
}
impl Default for BlendMode {
fn default() -> BlendMode {
BlendMode {
equation: BlendEquation::default(),
function: BlendFunction::default(),
global_color: [0.0; 4],
}
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendEquation {
Same(BlendOperation),
Separate {
color: BlendOperation,
alpha: BlendOperation,
},
}
impl Default for BlendEquation {
fn default() -> BlendEquation {
BlendEquation::Same(BlendOperation::Add)
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendOperation {
Add,
Subtract,
ReverseSubtract,
Max,
Min,
}
impl BlendOperation {
pub(crate) fn to_gl(self) -> u32 {
use BlendOperation::*;
match self {
Add => glow::FUNC_ADD,
Subtract => glow::FUNC_SUBTRACT,
ReverseSubtract => glow::FUNC_REVERSE_SUBTRACT,
Max => glow::MAX,
Min => glow::MIN,
}
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendFunction {
Same {
source: BlendFactor,
destination: BlendFactor,
},
Separate {
source_color: BlendFactor,
source_alpha: BlendFactor,
destination_color: BlendFactor,
destination_alpha: BlendFactor,
},
}
impl Default for BlendFunction {
fn default() -> BlendFunction {
BlendFunction::Same {
source: BlendFactor::Color {
input: BlendInput::Source,
channel: BlendChannel::Alpha,
is_inverse: false,
},
destination: BlendFactor::Color {
input: BlendInput::Source,
channel: BlendChannel::Alpha,
is_inverse: true,
},
}
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendFactor {
Zero,
One,
Color {
input: BlendInput,
channel: BlendChannel,
is_inverse: bool,
},
}
impl BlendFactor {
pub(crate) fn to_gl(self) -> u32 {
use BlendChannel::*;
use BlendFactor::{Color as Col, One, Zero};
use BlendInput::*;
match self {
Zero => glow::ZERO,
One => glow::ONE,
Col {
input: Source,
channel: Color,
is_inverse: false,
} => glow::SRC_COLOR,
Col {
input: Source,
channel: Color,
is_inverse: true,
} => glow::ONE_MINUS_SRC_COLOR,
Col {
input: Source,
channel: Alpha,
is_inverse: false,
} => glow::SRC_ALPHA,
Col {
input: Source,
channel: Alpha,
is_inverse: true,
} => glow::ONE_MINUS_SRC_ALPHA,
Col {
input: Destination,
channel: Color,
is_inverse: false,
} => glow::DST_COLOR,
Col {
input: Destination,
channel: Color,
is_inverse: true,
} => glow::ONE_MINUS_DST_COLOR,
Col {
input: Destination,
channel: Alpha,
is_inverse: false,
} => glow::DST_ALPHA,
Col {
input: Destination,
channel: Alpha,
is_inverse: true,
} => glow::ONE_MINUS_DST_ALPHA,
Col {
input: GlobalBlend,
channel: Color,
is_inverse: false,
} => glow::CONSTANT_COLOR,
Col {
input: GlobalBlend,
channel: Color,
is_inverse: true,
} => glow::ONE_MINUS_CONSTANT_COLOR,
Col {
input: GlobalBlend,
channel: Alpha,
is_inverse: false,
} => glow::CONSTANT_ALPHA,
Col {
input: GlobalBlend,
channel: Alpha,
is_inverse: true,
} => glow::ONE_MINUS_CONSTANT_ALPHA,
}
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendInput {
Source,
Destination,
GlobalBlend,
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlendChannel {
Color,
Alpha,
}