use std::default::Default;
use std::fmt;
use target;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", 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="serde", 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="serde", derive(Serialize, Deserialize))]
pub enum CullFace {
Nothing,
Front,
Back,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub enum RasterMethod {
Point,
Line(LineWidth),
Fill
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct MultiSample;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", 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() -> Self {
Rasterizer {
front_face: FrontFace::CounterClockwise,
cull_face: CullFace::Nothing,
method: RasterMethod::Fill,
offset: None,
samples: None,
}
}
pub fn with_cull_back(self) -> Self {
Rasterizer {
cull_face: CullFace::Back,
..self
}
}
pub fn with_offset(self, slope: f32, units: OffsetUnits) -> Self {
Rasterizer {
offset: Some(Offset(slope as OffsetSlope, units)),
..self
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", 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="serde", 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="serde", 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() -> Self {
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, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct Stencil {
pub front: StencilSide,
pub back: StencilSide,
}
impl Stencil {
pub fn new(fun: Comparison, mask: target::Stencil,
ops: (StencilOp, StencilOp, StencilOp))
-> Self {
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="serde", derive(Serialize, Deserialize))]
pub struct Depth {
pub fun: Comparison,
pub write: bool,
}
impl Default for Depth {
fn default() -> Self {
Depth {
fun: Comparison::Always,
write: false,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", 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="serde", 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="serde", 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="serde", derive(Serialize, Deserialize))]
pub struct BlendChannel {
pub equation: Equation,
pub source: Factor,
pub destination: Factor,
}
impl Default for BlendChannel {
fn default() -> Self {
BlendChannel {
equation: Equation::Add,
source: Factor::One,
destination: Factor::Zero,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Default, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct Blend {
pub color: BlendChannel,
pub alpha: BlendChannel,
}
impl Blend {
pub fn new(eq: Equation, src: Factor, dst: Factor) -> Self {
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="serde", derive(Serialize, Deserialize))]
pub struct 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;
}
);
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct Color {
pub mask: ColorMask,
pub blend: Option<Blend>,
}
impl Default for Color {
fn default() -> Self {
Color {
mask: ColorMask::all(),
blend: None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct RefValues {
pub stencil: (target::Stencil, target::Stencil),
pub blend: target::ColorValue,
}
impl Default for RefValues {
fn default() -> Self {
RefValues {
stencil: (0, 0),
blend: [0f32; 4],
}
}
}