mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Change PixelFormatRequirements
This commit is contained in:
parent
20a6e1ea6e
commit
0b6418fabb
80
src/lib.rs
80
src/lib.rs
|
@ -300,6 +300,16 @@ pub enum Robustness {
|
||||||
TryRobustLoseContextOnReset,
|
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)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum MouseCursor {
|
pub enum MouseCursor {
|
||||||
/// The platform-dependent default cursor.
|
/// The platform-dependent default cursor.
|
||||||
|
@ -388,17 +398,53 @@ pub struct PixelFormat {
|
||||||
pub srgb: bool,
|
pub srgb: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// VERY UNSTABLE! Describes how the backend should choose a pixel format.
|
/// Describes how the backend should choose a pixel format.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub struct PixelFormatRequirements {
|
pub struct PixelFormatRequirements {
|
||||||
pub multisampling: Option<u16>,
|
/// If true, only hardware-accelerated formats will be conisdered. If false, only software
|
||||||
pub depth_bits: Option<u8>,
|
/// renderers. `None` means "don't care". Default is `Some(true)`.
|
||||||
pub stencil_bits: Option<u8>,
|
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>,
|
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>,
|
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 stereoscopy: bool,
|
||||||
pub srgb: Option<bool>,
|
|
||||||
|
/// 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 PixelFormatRequirements {
|
impl PixelFormatRequirements {
|
||||||
|
@ -406,6 +452,10 @@ impl PixelFormatRequirements {
|
||||||
fn choose_pixel_format<T, I>(&self, iter: I) -> Result<(T, PixelFormat), CreationError>
|
fn choose_pixel_format<T, I>(&self, iter: I) -> Result<(T, PixelFormat), CreationError>
|
||||||
where I: IntoIterator<Item=(T, PixelFormat)>, T: Clone
|
where I: IntoIterator<Item=(T, PixelFormat)>, T: Clone
|
||||||
{
|
{
|
||||||
|
if self.release_behavior != ReleaseBehavior::Flush { return Err(CreationError::NoAvailablePixelFormat); }
|
||||||
|
if self.double_buffer == Some(false) { return Err(CreationError::NoAvailablePixelFormat); }
|
||||||
|
if self.float_color_buffer { return Err(CreationError::NoAvailablePixelFormat); }
|
||||||
|
|
||||||
// filtering formats that don't match the requirements
|
// filtering formats that don't match the requirements
|
||||||
let iter = iter.into_iter().filter(|&(_, ref format)| {
|
let iter = iter.into_iter().filter(|&(_, ref format)| {
|
||||||
if format.color_bits < self.color_bits.unwrap_or(0) {
|
if format.color_bits < self.color_bits.unwrap_or(0) {
|
||||||
|
@ -439,11 +489,9 @@ impl PixelFormatRequirements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(srgb) = self.srgb {
|
if self.srgb && !format.srgb {
|
||||||
if srgb != format.srgb {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
@ -507,13 +555,17 @@ impl Default for PixelFormatRequirements {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> PixelFormatRequirements {
|
fn default() -> PixelFormatRequirements {
|
||||||
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,
|
multisampling: None,
|
||||||
depth_bits: None,
|
|
||||||
stencil_bits: None,
|
|
||||||
color_bits: None,
|
|
||||||
alpha_bits: None,
|
|
||||||
stereoscopy: false,
|
stereoscopy: false,
|
||||||
srgb: None,
|
srgb: false,
|
||||||
|
release_behavior: ReleaseBehavior::Flush,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ impl<'a> WindowBuilder<'a> {
|
||||||
/// Sets whether sRGB should be enabled on the window. `None` means "I don't care".
|
/// Sets whether sRGB should be enabled on the window. `None` means "I don't care".
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> {
|
pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> {
|
||||||
self.pf_reqs.srgb = srgb_enabled;
|
self.pf_reqs.srgb = srgb_enabled.unwrap_or(false);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue