From 58b3bfb4fba22ecdb6f846f88f8a74e13ecae8ec Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 21 Sep 2015 09:33:41 +0200 Subject: Extract PixelFormatRequirements from BuilderAttribs --- src/lib.rs | 65 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 438938a..4cf9b0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,13 +371,7 @@ pub struct BuilderAttribs<'a> { #[allow(dead_code)] headless: bool, strict: bool, - multisampling: Option, - depth_bits: Option, - stencil_bits: Option, - color_bits: Option, - alpha_bits: Option, - stereoscopy: bool, - srgb: Option, + pf_reqs: PixelFormatRequirements, window: WindowAttributes, opengl: GlAttributes<&'a platform::Window>, } @@ -387,13 +381,7 @@ impl BuilderAttribs<'static> { BuilderAttribs { headless: false, strict: false, - multisampling: None, - depth_bits: None, - stencil_bits: None, - color_bits: None, - alpha_bits: None, - stereoscopy: false, - srgb: None, + pf_reqs: Default::default(), window: Default::default(), opengl: Default::default(), } @@ -408,13 +396,7 @@ impl<'a> BuilderAttribs<'a> { let new_attribs = BuilderAttribs { headless: self.headless, strict: self.strict, - multisampling: self.multisampling, - depth_bits: self.depth_bits, - stencil_bits: self.stencil_bits, - color_bits: self.color_bits, - alpha_bits: self.alpha_bits, - stereoscopy: self.stereoscopy, - srgb: self.srgb, + pf_reqs: self.pf_reqs, window: self.window, opengl: GlAttributes { sharing: None, @@ -434,27 +416,27 @@ impl<'a> BuilderAttribs<'a> { { // filtering formats that don't match the requirements let iter = iter.into_iter().filter(|&(_, ref format)| { - if format.color_bits < self.color_bits.unwrap_or(0) { + if format.color_bits < self.pf_reqs.color_bits.unwrap_or(0) { return false; } - if format.alpha_bits < self.alpha_bits.unwrap_or(0) { + if format.alpha_bits < self.pf_reqs.alpha_bits.unwrap_or(0) { return false; } - if format.depth_bits < self.depth_bits.unwrap_or(0) { + if format.depth_bits < self.pf_reqs.depth_bits.unwrap_or(0) { return false; } - if format.stencil_bits < self.stencil_bits.unwrap_or(0) { + if format.stencil_bits < self.pf_reqs.stencil_bits.unwrap_or(0) { return false; } - if !format.stereoscopy && self.stereoscopy { + if !format.stereoscopy && self.pf_reqs.stereoscopy { return false; } - if let Some(req_ms) = self.multisampling { + if let Some(req_ms) = self.pf_reqs.multisampling { match format.multisampling { Some(val) if val >= req_ms => (), _ => return false @@ -465,7 +447,7 @@ impl<'a> BuilderAttribs<'a> { } } - if let Some(srgb) = self.srgb { + if let Some(srgb) = self.pf_reqs.srgb { if srgb != format.srgb { return false; } @@ -529,6 +511,33 @@ impl<'a> BuilderAttribs<'a> { } } +/// VERY UNSTABLE! Describes how the backend should choose a pixel format. +#[derive(Clone, Debug)] +#[allow(missing_docs)] +pub struct PixelFormatRequirements { + pub multisampling: Option, + pub depth_bits: Option, + pub stencil_bits: Option, + pub color_bits: Option, + pub alpha_bits: Option, + pub stereoscopy: bool, + pub srgb: Option, +} + +impl Default for PixelFormatRequirements { + fn default() -> PixelFormatRequirements { + PixelFormatRequirements { + multisampling: None, + depth_bits: None, + stencil_bits: None, + color_bits: None, + alpha_bits: None, + stereoscopy: false, + srgb: None, + } + } +} + /// Attributes to use when creating a window. #[derive(Clone)] pub struct WindowAttributes { -- cgit v1.2.3