diff options
Diffstat (limited to 'opengl-bindings/src')
| -rw-r--r-- | opengl-bindings/src/blending.rs | 180 | ||||
| -rw-r--r-- | opengl-bindings/src/lib.rs | 1 |
2 files changed, 181 insertions, 0 deletions
diff --git a/opengl-bindings/src/blending.rs b/opengl-bindings/src/blending.rs new file mode 100644 index 0000000..5e8c1ef --- /dev/null +++ b/opengl-bindings/src/blending.rs @@ -0,0 +1,180 @@ +use crate::CurrentContextWithFns; + +pub fn configure( + current_context: &CurrentContextWithFns<'_>, + configuration: Configuration, +) +{ + unsafe { + current_context.fns().BlendFunc( + configuration.source_factor.into_gl(), + configuration.destination_factor.into_gl(), + ); + + current_context + .fns() + .BlendEquation(configuration.equation.into_gl()); + } +} + +#[derive(Debug, Clone)] +pub struct Configuration +{ + source_factor: Factor, + destination_factor: Factor, + equation: Equation, +} + +impl Configuration +{ + pub fn with_source_factor(mut self, source_factor: Factor) -> Self + { + self.source_factor = source_factor; + self + } + + pub fn with_destination_factor(mut self, destination_factor: Factor) -> Self + { + self.destination_factor = destination_factor; + self + } + + pub fn with_equation(mut self, equation: Equation) -> Self + { + self.equation = equation; + self + } +} + +impl Default for Configuration +{ + fn default() -> Self + { + Self { + source_factor: Factor::One, + destination_factor: Factor::Zero, + equation: Equation::default(), + } + } +} + +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +pub enum Factor +{ + /// Factor will be the RGBA color `(0,0,0,0)` + Zero, + + /// Factor will be the RGBA color `(1,1,1,1)` + One, + + /// Factor will be the source color + SrcColor, + + /// Factor will be the RGBA color `(1,1,1,1) - source color` + OneMinusSrcColor, + + /// Factor will be the destination color + DstColor, + + /// Factor will be the RGBA color `(1,1,1,1) - destination color` + OneMinusDstColor, + + /// Factor will be the alpha component of the source color. + SrcAlpha, + + /// Factor will be the RGBA color `(1,1,1,1) - source color alpha` + OneMinusSrcAlpha, + + /// Factor will be the alpha component of the destination color. + DstAlpha, + + /// Factor will be the RGBA color `(1,1,1,1) - destination color alpha` + OneMinusDstAlpha, + + /// Factor will be the constant color + ConstantColor, + + /// Factor will be the RGBA color `(1,1,1,1) - constant color` + OneMinusConstantColor, + + /// Factor will be the alpha component of the constant color. + ConstantAlpha, + + /// Factor will be the RGBA color `(1,1,1,1) - constant color alpha` + OneMinusConstantAlpha, + // /// (i,i,i,1) + // SrcAlphaSaturate, + // + // /// (Rs1kR,Gs1kG,Bs1kB,As1kA) + // Src1Color, + // + // /// (1,1,1,1)−(Rs1kR,Gs1kG,Bs1kB,As1kA) + // OneMinusSrc1Color, + // + // /// (As1kA,As1kA,As1kA,As1kA) + // Src1Alpha, + // + // /// (1,1,1,1)−(As1kA,As1kA,As1kA,As1kA) + // OneMinusSrc1Alpha, +} + +impl Factor +{ + fn into_gl(self) -> crate::sys::types::GLenum + { + match self { + Self::Zero => crate::sys::ZERO, + Self::One => crate::sys::ONE, + Self::SrcColor => crate::sys::SRC_COLOR, + Self::OneMinusSrcColor => crate::sys::ONE_MINUS_SRC_COLOR, + Self::DstColor => crate::sys::DST_COLOR, + Self::OneMinusDstColor => crate::sys::ONE_MINUS_DST_COLOR, + Self::SrcAlpha => crate::sys::SRC_ALPHA, + Self::OneMinusSrcAlpha => crate::sys::ONE_MINUS_SRC_ALPHA, + Self::DstAlpha => crate::sys::DST_ALPHA, + Self::OneMinusDstAlpha => crate::sys::ONE_MINUS_DST_ALPHA, + Self::ConstantColor => crate::sys::CONSTANT_COLOR, + Self::OneMinusConstantColor => crate::sys::ONE_MINUS_CONSTANT_COLOR, + Self::ConstantAlpha => crate::sys::CONSTANT_ALPHA, + Self::OneMinusConstantAlpha => crate::sys::ONE_MINUS_CONSTANT_ALPHA, + } + } +} + +#[derive(Debug, Default, Clone, Copy)] +pub enum Equation +{ + /// The destination color and source color is added to each other in the blend + /// function + #[default] + Add, + + /// The destination color is subtracted from the source color in the blend function + Subtract, + + /// The source color is subtracted from the destination color in the blend function + ReverseSubtract, + + /// The blend function will take the component-wise minimum of the destination color + /// and the source color + Min, + + /// The blend function will take the component-wise maximum of the destination color + /// and the source color + Max, +} + +impl Equation +{ + fn into_gl(self) -> crate::sys::types::GLenum + { + match self { + Self::Add => crate::sys::FUNC_ADD, + Self::Subtract => crate::sys::FUNC_SUBTRACT, + Self::ReverseSubtract => crate::sys::FUNC_REVERSE_SUBTRACT, + Self::Min => crate::sys::MIN, + Self::Max => crate::sys::MAX, + } + } +} diff --git a/opengl-bindings/src/lib.rs b/opengl-bindings/src/lib.rs index 7fd9933..af80e69 100644 --- a/opengl-bindings/src/lib.rs +++ b/opengl-bindings/src/lib.rs @@ -7,6 +7,7 @@ use glutin::display::GetGlDisplay; use glutin::prelude::{GlDisplay, NotCurrentGlContext, PossiblyCurrentGlContext}; use glutin::surface::{Surface, SurfaceTypeTrait}; +pub mod blending; pub mod buffer; pub mod data_types; pub mod debug; |
