From 3054e2ee0236672ae88bd124e60ba49aae701695 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 21 Sep 2015 10:11:32 +0200 Subject: Switch EGL to use only pf_reqs and opengl --- src/lib.rs | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index a5155f9..8c93036 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -411,32 +411,53 @@ impl<'a> BuilderAttribs<'a> { (new_attribs, sharing) } + fn choose_pixel_format(&self, iter: I) -> Result<(T, PixelFormat), CreationError> + where I: IntoIterator, T: Clone + { + self.pf_reqs.choose_pixel_format(iter) + } +} + +/// 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 PixelFormatRequirements { fn choose_pixel_format(&self, iter: I) -> Result<(T, PixelFormat), CreationError> where I: IntoIterator, T: Clone { // filtering formats that don't match the requirements let iter = iter.into_iter().filter(|&(_, ref format)| { - if format.color_bits < self.pf_reqs.color_bits.unwrap_or(0) { + if format.color_bits < self.color_bits.unwrap_or(0) { return false; } - if format.alpha_bits < self.pf_reqs.alpha_bits.unwrap_or(0) { + if format.alpha_bits < self.alpha_bits.unwrap_or(0) { return false; } - if format.depth_bits < self.pf_reqs.depth_bits.unwrap_or(0) { + if format.depth_bits < self.depth_bits.unwrap_or(0) { return false; } - if format.stencil_bits < self.pf_reqs.stencil_bits.unwrap_or(0) { + if format.stencil_bits < self.stencil_bits.unwrap_or(0) { return false; } - if !format.stereoscopy && self.pf_reqs.stereoscopy { + if !format.stereoscopy && self.stereoscopy { return false; } - if let Some(req_ms) = self.pf_reqs.multisampling { + if let Some(req_ms) = self.multisampling { match format.multisampling { Some(val) if val >= req_ms => (), _ => return false @@ -447,7 +468,7 @@ impl<'a> BuilderAttribs<'a> { } } - if let Some(srgb) = self.pf_reqs.srgb { + if let Some(srgb) = self.srgb { if srgb != format.srgb { return false; } @@ -511,19 +532,6 @@ 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 { -- cgit v1.2.3