aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-09-21 09:33:41 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-09-21 12:03:56 +0200
commit58b3bfb4fba22ecdb6f846f88f8a74e13ecae8ec (patch)
tree3c39af2f6ac64aa44dc2555a9302f24115697e56 /src
parent48fe9b26442662517b1590cb98ab81d79b059953 (diff)
downloadglutin-58b3bfb4fba22ecdb6f846f88f8a74e13ecae8ec.tar.gz
glutin-58b3bfb4fba22ecdb6f846f88f8a74e13ecae8ec.zip
Extract PixelFormatRequirements from BuilderAttribs
Diffstat (limited to 'src')
-rw-r--r--src/api/cocoa/mod.rs10
-rw-r--r--src/lib.rs65
-rw-r--r--src/window.rs14
3 files changed, 49 insertions, 40 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index e3feda2..a682489 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -471,16 +471,16 @@ impl Window {
// full color size and hope for the best. Another hiccup is that
// `NSOpenGLPFAColorSize` also includes `NSOpenGLPFAAlphaSize`,
// so we have to account for that as well.
- let alpha_depth = builder.alpha_bits.unwrap_or(8);
- let color_depth = builder.color_bits.unwrap_or(24) + alpha_depth;
+ let alpha_depth = builder.pf_reqs.alpha_bits.unwrap_or(8);
+ let color_depth = builder.pf_reqs.color_bits.unwrap_or(24) + alpha_depth;
let mut attributes = vec![
NSOpenGLPFADoubleBuffer as u32,
NSOpenGLPFAClosestPolicy as u32,
NSOpenGLPFAColorSize as u32, color_depth as u32,
NSOpenGLPFAAlphaSize as u32, alpha_depth as u32,
- NSOpenGLPFADepthSize as u32, builder.depth_bits.unwrap_or(24) as u32,
- NSOpenGLPFAStencilSize as u32, builder.stencil_bits.unwrap_or(8) as u32,
+ NSOpenGLPFADepthSize as u32, builder.pf_reqs.depth_bits.unwrap_or(24) as u32,
+ NSOpenGLPFAStencilSize as u32, builder.pf_reqs.stencil_bits.unwrap_or(8) as u32,
NSOpenGLPFAOpenGLProfile as u32, profile,
];
@@ -491,7 +491,7 @@ impl Window {
attributes.push(NSOpenGLPFAColorFloat as u32);
}
- builder.multisampling.map(|samples| {
+ builder.pf_reqs.multisampling.map(|samples| {
attributes.push(NSOpenGLPFAMultisample as u32);
attributes.push(NSOpenGLPFASampleBuffers as u32); attributes.push(1);
attributes.push(NSOpenGLPFASamples as u32); attributes.push(samples as u32);
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<u16>,
- depth_bits: Option<u8>,
- stencil_bits: Option<u8>,
- color_bits: Option<u8>,
- alpha_bits: Option<u8>,
- stereoscopy: bool,
- srgb: Option<bool>,
+ 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<u16>,
+ pub depth_bits: Option<u8>,
+ pub stencil_bits: Option<u8>,
+ pub color_bits: Option<u8>,
+ pub alpha_bits: Option<u8>,
+ pub stereoscopy: bool,
+ pub srgb: Option<bool>,
+}
+
+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 {
diff --git a/src/window.rs b/src/window.rs
index 4a45a01..85d3440 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -110,38 +110,38 @@ impl<'a> WindowBuilder<'a> {
/// Will panic if `samples` is not a power of two.
pub fn with_multisampling(mut self, samples: u16) -> WindowBuilder<'a> {
assert!(samples.is_power_of_two());
- self.attribs.multisampling = Some(samples);
+ self.attribs.pf_reqs.multisampling = Some(samples);
self
}
/// Sets the number of bits in the depth buffer.
pub fn with_depth_buffer(mut self, bits: u8) -> WindowBuilder<'a> {
- self.attribs.depth_bits = Some(bits);
+ self.attribs.pf_reqs.depth_bits = Some(bits);
self
}
/// Sets the number of bits in the stencil buffer.
pub fn with_stencil_buffer(mut self, bits: u8) -> WindowBuilder<'a> {
- self.attribs.stencil_bits = Some(bits);
+ self.attribs.pf_reqs.stencil_bits = Some(bits);
self
}
/// Sets the number of bits in the color buffer.
pub fn with_pixel_format(mut self, color_bits: u8, alpha_bits: u8) -> WindowBuilder<'a> {
- self.attribs.color_bits = Some(color_bits);
- self.attribs.alpha_bits = Some(alpha_bits);
+ self.attribs.pf_reqs.color_bits = Some(color_bits);
+ self.attribs.pf_reqs.alpha_bits = Some(alpha_bits);
self
}
/// Request the backend to be stereoscopic.
pub fn with_stereoscopy(mut self) -> WindowBuilder<'a> {
- self.attribs.stereoscopy = true;
+ self.attribs.pf_reqs.stereoscopy = true;
self
}
/// Sets whether sRGB should be enabled on the window. `None` means "I don't care".
pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> {
- self.attribs.srgb = srgb_enabled;
+ self.attribs.pf_reqs.srgb = srgb_enabled;
self
}