From 6b4be74539bc1c2bda85600a3fb82fefdf9f4396 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 24 Feb 2015 18:19:17 +1100 Subject: [PATCH] Make Frame::get_mask easier to understand --- src/render/target.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/render/target.rs b/src/render/target.rs index c35d0aac1ed..84de5f2ae5f 100644 --- a/src/render/target.rs +++ b/src/render/target.rs @@ -77,9 +77,13 @@ impl Frame { /// Return a mask of contained planes. pub fn get_mask(&self) -> Mask { use device::target as t; - let mut mask = [t::COLOR0, t::COLOR1, t::COLOR2, t::COLOR3] - .iter().zip(self.colors.iter()) - .fold(Mask::empty(), |u, (&m, _)| (u | m)); + 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); } @@ -89,7 +93,7 @@ impl Frame { if mask.is_empty() { // hack: assuming the default FBO has all planes t::COLOR | t::DEPTH | t::STENCIL - }else { + } else { mask } }