use std::default::Default;
use std::fmt;
use target;
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum WindingOrder {
Clockwise,
CounterClockwise,
}
pub type LineWidth = f32;
#[allow(missing_docs)]
pub type OffsetFactor = f32;
#[allow(missing_docs)]
pub type OffsetUnits = u32;
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Offset(pub OffsetFactor, pub OffsetUnits);
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum CullMode {
Nothing,
Front,
Back,
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum RasterMethod {
Point,
Line(LineWidth),
Fill(CullMode),
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Primitive {
pub front_face: WindingOrder,
pub method: RasterMethod,
pub offset: Option<Offset>,
}
impl Primitive {
pub fn get_cull_mode(&self) -> CullMode {
match self.method {
RasterMethod::Fill(mode) => mode,
_ => CullMode::Nothing,
}
}
}
impl Default for Primitive {
fn default() -> Primitive {
Primitive {
front_face: WindingOrder::CounterClockwise,
method: RasterMethod::Fill(CullMode::Nothing),
offset: None,
}
}
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Copy, Clone, Debug)]
pub struct MultiSample;
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum Comparison {
Never,
Less,
LessEqual,
Equal,
GreaterEqual,
Greater,
NotEqual,
Always,
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum StencilOp {
Keep,
Zero,
Replace,
IncrementClamp,
IncrementWrap,
DecrementClamp,
DecrementWrap,
Invert,
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub struct StencilSide {
pub fun: Comparison,
pub value: target::Stencil,
pub mask_read: target::Stencil,
pub mask_write: target::Stencil,
pub op_fail: StencilOp,
pub op_depth_fail: StencilOp,
pub op_pass: StencilOp,
}
impl Default for StencilSide {
fn default() -> StencilSide {
StencilSide {
fun: Comparison::Always,
value: 0,
mask_read: -1,
mask_write: -1,
op_fail: StencilOp::Keep,
op_depth_fail: StencilOp::Keep,
op_pass: StencilOp::Keep,
}
}
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub struct Stencil {
pub front: StencilSide,
pub back: StencilSide,
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub struct Depth {
pub fun: Comparison,
pub write: bool,
}
impl Default for Depth {
fn default() -> Depth {
Depth {
fun: Comparison::Always,
write: false,
}
}
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum Equation {
Add,
Sub,
RevSub,
Min,
Max,
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum InverseFlag {
Normal,
Inverse,
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub enum BlendValue {
Zero,
SourceColor,
SourceAlpha,
SourceAlphaSaturated,
DestColor,
DestAlpha,
ConstColor,
ConstAlpha,
}
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub struct Factor(pub InverseFlag, pub BlendValue);
#[allow(missing_docs)]
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
pub struct BlendChannel {
pub equation: Equation,
pub source: Factor,
pub destination: Factor,
}
impl Default for BlendChannel {
fn default() -> BlendChannel {
BlendChannel {
equation: Equation::Add,
source: Factor(InverseFlag::Inverse, BlendValue::Zero),
destination: Factor(InverseFlag::Normal, BlendValue::Zero),
}
}
}
#[allow(missing_docs)]
#[derive(Copy)]
pub struct Blend {
pub color: BlendChannel,
pub alpha: BlendChannel,
pub value: ::target::ColorValue,
}
impl Default for Blend {
fn default() -> Blend {
Blend {
color: Default::default(),
alpha: Default::default(),
value: [0.0, 0.0, 0.0, 0.0],
}
}
}
impl PartialEq for Blend {
fn eq(&self, other: &Blend) -> bool {
self.color == other.color &&
self.alpha == other.alpha &&
self.value == other.value
}
}
impl Clone for Blend {
fn clone(&self) -> Blend {
Blend {
color: self.color.clone(),
alpha: self.alpha.clone(),
value: self.value,
}
}
}
impl fmt::Debug for Blend {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Blend {{ color: {:?}, alpha: {:?}, value: {:?} }}",
self.color, self.alpha, &self.value[])
}
}
bitflags!(
#[allow(missing_docs)]
flags ColorMask: u32 { const RED = 0x1,
const GREEN = 0x2,
const BLUE = 0x4,
const ALPHA = 0x8,
const MASK_ALL = 0xF
}
);
impl fmt::Debug for ColorMask {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let values = [
(RED, "Red" ),
(GREEN, "Green"),
(BLUE, "Blue" ),
(ALPHA, "Alpha"),
];
try!(write!(f, "ColorMask("));
for (i, &(_, name)) in values.iter()
.filter(|&&(flag, _)| self.contains(flag))
.enumerate()
{
if i == 0 {
try!(write!(f, "{}", name))
} else {
try!(write!(f, " | {}", name))
}
}
try!(write!(f, ")"));
Ok(())
}
}