aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs173
1 files changed, 61 insertions, 112 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c543155..5b1aa03 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -300,6 +300,16 @@ pub enum Robustness {
TryRobustLoseContextOnReset,
}
+/// The behavior of the driver when you change the current context.
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum ReleaseBehavior {
+ /// Doesn't do anything. Most notably doesn't flush.
+ None,
+
+ /// Flushes the context that was previously current as if `glFlush` was called.
+ Flush,
+}
+
#[derive(Debug, Copy, Clone)]
pub enum MouseCursor {
/// The platform-dependent default cursor.
@@ -388,132 +398,71 @@ pub struct PixelFormat {
pub srgb: bool,
}
-/// VERY UNSTABLE! Describes how the backend should choose a pixel format.
+/// Describes how the backend should choose a pixel format.
+// TODO: swap method? (swap, copy)
#[derive(Clone, Debug)]
-#[allow(missing_docs)]
pub struct PixelFormatRequirements {
- pub multisampling: Option<u16>,
- pub depth_bits: Option<u8>,
- pub stencil_bits: Option<u8>,
+ /// If true, only hardware-accelerated formats will be conisdered. If false, only software
+ /// renderers. `None` means "don't care". Default is `Some(true)`.
+ pub hardware_accelerated: Option<bool>,
+
+ /// Minimum number of bits for the color buffer, excluding alpha. `None` means "don't care".
+ /// The default is `Some(24)`.
pub color_bits: Option<u8>,
+
+ /// If true, the color buffer must be in a floating point format. Default is `false`.
+ ///
+ /// Using floating points allows you to write values outside of the `[0.0, 1.0]` range.
+ pub float_color_buffer: bool,
+
+ /// Minimum number of bits for the alpha in the color buffer. `None` means "don't care".
+ /// The default is `Some(8)`.
pub alpha_bits: Option<u8>,
+
+ /// Minimum number of bits for the depth buffer. `None` means "don't care".
+ /// The default value is `Some(24)`.
+ pub depth_bits: Option<u8>,
+
+ /// Minimum number of bits for the depth buffer. `None` means "don't care".
+ /// The default value is `Some(8)`.
+ pub stencil_bits: Option<u8>,
+
+ /// If true, only double-buffered formats will be considered. If false, only single-buffer
+ /// formats. `None` means "don't care". The default is `Some(true)`.
+ pub double_buffer: Option<bool>,
+
+ /// Contains the minimum number of samples per pixel in the color, depth and stencil buffers.
+ /// `None` means "don't care". Default is `None`.
+ /// A value of `Some(0)` indicates that multisampling must not be enabled.
+ pub multisampling: Option<u16>,
+
+ /// If true, only stereoscopic formats will be considered. If false, only non-stereoscopic
+ /// formats. The default is `false`.
pub stereoscopy: bool,
- pub srgb: Option<bool>,
-}
-impl PixelFormatRequirements {
- #[cfg(not(target_os = "macos"))]
- fn choose_pixel_format<T, I>(&self, iter: I) -> Result<(T, PixelFormat), CreationError>
- where I: IntoIterator<Item=(T, PixelFormat)>, T: Clone
- {
- // 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) {
- return false;
- }
-
- if format.alpha_bits < self.alpha_bits.unwrap_or(0) {
- return false;
- }
-
- if format.depth_bits < self.depth_bits.unwrap_or(0) {
- return false;
- }
-
- if format.stencil_bits < self.stencil_bits.unwrap_or(0) {
- return false;
- }
-
- if !format.stereoscopy && self.stereoscopy {
- return false;
- }
-
- if let Some(req_ms) = self.multisampling {
- match format.multisampling {
- Some(val) if val >= req_ms => (),
- _ => return false
- }
- } else {
- if format.multisampling.is_some() {
- return false;
- }
- }
-
- if let Some(srgb) = self.srgb {
- if srgb != format.srgb {
- return false;
- }
- }
-
- true
- });
-
- // sorting so that the preferred format comes first
- let mut formats = iter.collect::<Vec<_>>();
- formats.sort_by(|&(_, ref left), &(_, ref right)| {
- // prefer hardware-accelerated formats
- if left.hardware_accelerated && !right.hardware_accelerated {
- return Ordering::Less;
- } else if right.hardware_accelerated && !left.hardware_accelerated {
- return Ordering::Greater;
- }
-
- // prefer sRGB formats
- if left.srgb && !right.srgb {
- return Ordering::Less;
- } else if right.srgb && !left.srgb {
- return Ordering::Greater;
- }
-
- // prefer formats with the highest color+alpha bits
- if left.color_bits + left.alpha_bits != right.color_bits + right.alpha_bits {
- return (right.color_bits + right.alpha_bits)
- .cmp(&(left.color_bits + left.alpha_bits));
- }
-
- // prefer double-buffering formats
- if left.double_buffer && !right.double_buffer {
- return Ordering::Less;
- } else if right.double_buffer && !left.double_buffer {
- return Ordering::Greater;
- }
-
- // prefer formats with the highest depth bits
- if left.depth_bits != right.depth_bits {
- return (right.depth_bits).cmp(&left.depth_bits);
- }
-
- // prefer formats with the highest stencil bits
- if left.stencil_bits != right.stencil_bits {
- return (right.stencil_bits).cmp(&left.stencil_bits);
- }
-
- // prefer formats with multisampling
- if left.multisampling.is_some() && right.multisampling.is_none() {
- return Ordering::Less;
- } else if right.multisampling.is_some() && left.multisampling.is_none() {
- return Ordering::Greater;
- }
-
- // default
- return Ordering::Equal;
- });
-
- formats.into_iter().next().ok_or(CreationError::NoAvailablePixelFormat)
- }
+ /// If true, only sRGB-capable formats will be considered. If false, don't care.
+ /// The default is `false`.
+ pub srgb: bool,
+
+ /// The behavior when changing the current context. Default is `Flush`.
+ pub release_behavior: ReleaseBehavior,
}
impl Default for PixelFormatRequirements {
#[inline]
fn default() -> PixelFormatRequirements {
PixelFormatRequirements {
+ hardware_accelerated: Some(true),
+ color_bits: Some(24),
+ float_color_buffer: false,
+ alpha_bits: Some(8),
+ depth_bits: Some(24),
+ stencil_bits: Some(8),
+ double_buffer: Some(true),
multisampling: None,
- depth_bits: None,
- stencil_bits: None,
- color_bits: None,
- alpha_bits: None,
stereoscopy: false,
- srgb: None,
+ srgb: false,
+ release_behavior: ReleaseBehavior::Flush,
}
}
}