use std::default::Default;
use std::fmt;
use target;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum FrontFace {
Clockwise,
CounterClockwise,
}
pub type LineWidth = i32;
pub type OffsetSlope = i32;
pub type OffsetUnits = i32;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct Offset(pub OffsetSlope, pub OffsetUnits);
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum CullFace {
Nothing,
Front,
Back,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum RasterMethod {
Point,
Line(LineWidth),
Fill
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct MultiSample;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct Rasterizer {
pub front_face: FrontFace,
pub cull_face: CullFace,
pub method: RasterMethod,
pub offset: Option<Offset>,
pub samples: Option<MultiSample>,
}
impl Rasterizer {
pub fn new_fill() -> Rasterizer {
Rasterizer {
front_face: FrontFace::CounterClockwise,
cull_face: CullFace::Nothing,
method: RasterMethod::Fill,
offset: None,
samples: None,
}
}
pub fn with_cull_back(self) -> Rasterizer {
Rasterizer {
cull_face: CullFace::Back,
..self
}
}
pub fn with_offset(self, slope: f32, units: OffsetUnits) -> Rasterizer {
Rasterizer {
offset: Some(Offset(slope as OffsetSlope, units)),
..self
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum Comparison {
Never,
Less,
LessEqual,
Equal,
GreaterEqual,
Greater,
NotEqual,
Always,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum StencilOp {
Keep,
Zero,
Replace,
IncrementClamp,
IncrementWrap,
DecrementClamp,
DecrementWrap,
Invert,
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct StencilSide {
pub fun: Comparison,
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,
mask_read: target::Stencil::max_value(),
mask_write: target::Stencil::max_value(),
op_fail: StencilOp::Keep,
op_depth_fail: StencilOp::Keep,
op_pass: StencilOp::Keep,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct Stencil {
pub front: StencilSide,
pub back: StencilSide,
}
impl Default for Stencil {
fn default() -> Stencil {
Stencil {
front: Default::default(),
back: Default::default(),
}
}
}
impl Stencil {
pub fn new(fun: Comparison, mask: target::Stencil,
ops: (StencilOp, StencilOp, StencilOp))
-> Stencil {
let side = StencilSide {
fun: fun,
mask_read: mask,
mask_write: mask,
op_fail: ops.0,
op_depth_fail: ops.1,
op_pass: ops.2,
};
Stencil {
front: side,
back: side,
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
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(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum Equation {
Add,
Sub,
RevSub,
Min,
Max,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum BlendValue {
SourceColor,
SourceAlpha,
DestColor,
DestAlpha,
ConstColor,
ConstAlpha,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub enum Factor {
Zero,
One,
SourceAlphaSaturated,
ZeroPlus(BlendValue),
OneMinus(BlendValue),
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
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::One,
destination: Factor::One,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct Blend {
pub color: BlendChannel,
pub alpha: BlendChannel,
}
impl Default for Blend {
fn default() -> Blend {
Blend {
color: Default::default(),
alpha: Default::default(),
}
}
}
impl Blend {
pub fn new(eq: Equation, src: Factor, dst: Factor) -> Blend {
let chan = BlendChannel {
equation: eq,
source: src,
destination: dst,
};
Blend {
color: chan,
alpha: chan,
}
}
}
impl fmt::Debug for Blend {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Blend {{ color: {:?}, alpha: {:?}}}",
self.color, self.alpha)
}
}
bitflags!(
#[allow(missing_docs)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub flags ColorMask: u8 {
#[allow(missing_docs)]
const RED = 0x1,
#[allow(missing_docs)]
const GREEN = 0x2,
#[allow(missing_docs)]
const BLUE = 0x4,
#[allow(missing_docs)]
const ALPHA = 0x8,
#[allow(missing_docs)]
const MASK_ALL = 0xF,
#[allow(missing_docs)]
const MASK_NONE = 0x0
}
);
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct Color {
pub mask: ColorMask,
pub blend: Option<Blend>,
}
impl Default for Color {
fn default() -> Color {
Color {
mask: MASK_ALL,
blend: None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
pub struct RefValues {
pub stencil: (target::Stencil, target::Stencil),
pub blend: target::ColorValue,
}
impl Default for RefValues {
fn default() -> RefValues {
RefValues {
stencil: (0, 0),
blend: [0f32; 4],
}
}
}