use device;
use device::Resources;
use device::target::{Level, Layer, Mask};
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Plane<R: Resources> {
Surface(device::SurfaceHandle<R>),
Texture(device::TextureHandle<R>, Level, Option<Layer>),
}
impl<R: Resources> Plane<R> {
pub fn get_surface_info(&self) -> device::tex::SurfaceInfo {
match *self {
Plane::Surface(ref suf) => *suf.get_info(),
Plane::Texture(ref tex, _, _) => tex.get_info().to_surface_info(),
}
}
}
#[derive(Clone, PartialEq, Debug)]
pub struct Frame<R: Resources> {
pub width: u16,
pub height: u16,
pub colors: Vec<Plane<R>>,
pub depth: Option<Plane<R>>,
pub stencil: Option<Plane<R>>,
}
impl<R: Resources> Frame<R> {
pub fn new(width: u16, height: u16) -> Frame<R> {
Frame {
width: width,
height: height,
colors: Vec::new(),
depth: None,
stencil: None,
}
}
pub fn is_default(&self) -> bool {
self.colors.is_empty() &&
self.depth.is_none() &&
self.stencil.is_none()
}
pub fn get_mask(&self) -> Mask {
use device::target as t;
let mut mask = match self.colors.len() {
0 => Mask::empty(),
1 => t::COLOR0,
2 => t::COLOR0 | t::COLOR1,
3 => t::COLOR0 | t::COLOR1 | t::COLOR2,
_ => t::COLOR0 | t::COLOR1 | t::COLOR2 | t::COLOR3,
};
if self.depth.is_some() {
mask.insert(t::DEPTH);
}
if self.stencil.is_some() {
mask.insert(t::STENCIL);
}
if mask.is_empty() {
t::COLOR | t::DEPTH | t::STENCIL
} else {
mask
}
}
}