use crate::graphics::Colour;
#[cfg(any(windows))]
use crate::windows::OpenGraphicsLibrary;
use core::mem::transmute;
const ZERO:u32=0;
const ONE:u32=1;
const SRC_COLOR:u32=0x0300;
const ONE_MINUS_SRC_COLOR:u32=0x0301;
const SRC_ALPHA:u32=0x0302;
const ONE_MINUS_SRC_ALPHA:u32=0x0303;
const DST_ALPHA:u32=0x0304;
const ONE_MINUS_DST_ALPHA:u32=0x0305;
const DST_COLOR:u32=0x0306;
const ONE_MINUS_DST_COLOR:u32=0x0307;
const SRC_ALPHA_SATURATE:u32=0x0308;
const CONSTANT_COLOR:u32=0x8001;
const ONE_MINUS_CONSTANT_COLOR:u32=0x8002;
const CONSTANT_ALPHA:u32=0x8003;
const ONE_MINUS_CONSTANT_ALPHA:u32=0x8004;
const SRC1_ALPHA:u32=0x8589;
const SRC1_COLOR:u32=0x88F9;
const ONE_MINUS_SRC1_COLOR:u32=0x88FA;
const ONE_MINUS_SRC1_ALPHA:u32=0x88FB;
const FUNC_ADD:u32=0x8006;
const FUNC_SUBTRACT:u32=0x800A;
const FUNC_REVERSE_SUBTRACT:u32=0x800B;
const MIN:u32=0x8007;
const MAX:u32=0x8008;
const BLEND_COLOR:u32=0x8005;
const BLEND_DST_ALPHA:u32=0x80CA;
const BLEND_DST_RGB:u32=0x80C8;
const BLEND_EQUATION:u32=0x8009;
const BLEND_EQUATION_ALPHA:u32=0x883D;
const BLEND_EQUATION_RGB:u32=0x8009;
const BLEND_SRC_ALPHA:u32=0x80CB;
const BLEND_SRC_RGB:u32=0x80C9;
#[repr(u32)]
pub enum BlendingEquation{
Addition=FUNC_ADD,
Subtraction=FUNC_SUBTRACT,
ReverseSubtraction=FUNC_REVERSE_SUBTRACT,
Minimum=MIN,
Maximum=MAX
}
#[repr(u32)]
#[derive(Clone,Copy,Debug)]
pub enum BlendingFunction{
Zero=ZERO,
One=ONE,
SourceColour=SRC_COLOR,
OneMinusSourceColour=ONE_MINUS_SRC_COLOR,
DestinationColour=DST_COLOR,
OneMinusDestinationColour=ONE_MINUS_DST_COLOR,
SourceAlpha=SRC_ALPHA,
OneMinusSourceAlpha=ONE_MINUS_SRC_ALPHA,
DestinationAlpha=DST_ALPHA,
OneMinusDestinationAlpha=ONE_MINUS_DST_ALPHA,
ConstantColour=CONSTANT_COLOR,
OneMinusConstantColour=ONE_MINUS_CONSTANT_COLOR,
ConstantAlpha=CONSTANT_ALPHA,
OneMinusConstantAlpha=ONE_MINUS_CONSTANT_ALPHA,
SourceAlphaSaturate=SRC_ALPHA_SATURATE,
}
pub struct Blend{
glBlendColor:usize,
glBlendFunc:usize,
glBlendFuncSeparate:usize,
glBlendEquation:usize,
glBlendEquationSeparate:usize,
}
impl Blend{
pub const fn new()->Blend{
Self{
glBlendColor:0,
glBlendFunc:0,
glBlendFuncSeparate:0,
glBlendEquation:0,
glBlendEquationSeparate:0,
}
}
#[cfg(any(windows))]
pub fn load(&mut self,library:&OpenGraphicsLibrary){
unsafe{
self.glBlendColor=transmute(library.get_proc_address("glBlendColor\0"));
self.glBlendFunc=transmute(library.get_proc_address("glBlendFunc\0"));
self.glBlendFuncSeparate=transmute(library.get_proc_address("glBlendFuncSeparate\0"));
self.glBlendEquation=transmute(library.get_proc_address("glBlendEquation\0"));
self.glBlendEquationSeparate=transmute(library.get_proc_address("glBlendEquationSeparate\0"));
}
}
}
impl Blend{
#[inline(always)]
pub fn set_blending_colour(&self,[red,greed,blue,alpha]:Colour){
unsafe{
transmute::<usize,fn(f32,f32,f32,f32)>(self.glBlendColor)(red,greed,blue,alpha)
}
}
#[inline(always)]
pub fn set_function(
&self,
sourse_factor:BlendingFunction,
destination_factor:BlendingFunction
){
unsafe{
transmute::<usize,fn(
BlendingFunction,
BlendingFunction
)>(self.glBlendFunc)
(
sourse_factor,
destination_factor
)
}
}
#[inline(always)]
pub fn set_function_separate(
&self,
sourse_factor_rgb:BlendingFunction,
destination_factor_rgb:BlendingFunction,
sourse_factor_alpha:BlendingFunction,
destination_factor_alpha:BlendingFunction,
){
unsafe{
transmute::<usize,fn(
BlendingFunction,
BlendingFunction,
BlendingFunction,
BlendingFunction
)>(self.glBlendFuncSeparate)(
sourse_factor_rgb,
destination_factor_rgb,
sourse_factor_alpha,
destination_factor_alpha
)
}
}
#[inline(always)]
pub fn set_equation(&self,equation:BlendingEquation){
unsafe{
transmute::<usize,fn(BlendingEquation)>(self.glBlendEquation)(equation)
}
}
#[inline(always)]
pub fn set_equation_separate(
&self,
equation_rgb:BlendingEquation,
equation_alpha:BlendingEquation
){
unsafe{
transmute::<usize,fn(
BlendingEquation,
BlendingEquation
)>(self.glBlendEquationSeparate)(
equation_rgb,
equation_alpha
)
}
}
}