mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Merge pull request #354 from tomaka/srgb
Add support for sRGB attribute and fix creation on windows
This commit is contained in:
commit
0d35ce0035
1
build.rs
1
build.rs
|
@ -31,6 +31,7 @@ fn main() {
|
|||
"WGL_ARB_pixel_format".to_string(),
|
||||
"WGL_EXT_create_context_es2_profile".to_string(),
|
||||
"WGL_EXT_extensions_string".to_string(),
|
||||
"WGL_EXT_framebuffer_sRGB".to_string(),
|
||||
"WGL_EXT_swap_control".to_string(),
|
||||
],
|
||||
"1.0", "core", &mut file).unwrap();
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -253,6 +253,7 @@ pub struct BuilderAttribs<'a> {
|
|||
color_bits: Option<u8>,
|
||||
alpha_bits: Option<u8>,
|
||||
stereoscopy: bool,
|
||||
srgb: Option<bool>,
|
||||
}
|
||||
|
||||
impl BuilderAttribs<'static> {
|
||||
|
@ -274,6 +275,7 @@ impl BuilderAttribs<'static> {
|
|||
color_bits: None,
|
||||
alpha_bits: None,
|
||||
stereoscopy: false,
|
||||
srgb: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -299,6 +301,7 @@ impl<'a> BuilderAttribs<'a> {
|
|||
color_bits: self.color_bits,
|
||||
alpha_bits: self.alpha_bits,
|
||||
stereoscopy: self.stereoscopy,
|
||||
srgb: self.srgb,
|
||||
};
|
||||
|
||||
(new_attribs, sharing)
|
||||
|
@ -332,6 +335,16 @@ impl<'a> BuilderAttribs<'a> {
|
|||
continue;
|
||||
}
|
||||
|
||||
if self.multisampling.is_some() && format.multisampling.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(srgb) = self.srgb {
|
||||
if srgb != format.srgb {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
current_software_result = Some((id.clone(), format.clone()));
|
||||
if format.hardware_accelerated {
|
||||
current_result = Some((id, format));
|
||||
|
|
|
@ -140,7 +140,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
|||
// getting the pixel format that we will use and setting it
|
||||
{
|
||||
let formats = enumerate_native_pixel_formats(&dummy_window);
|
||||
let (id, _) = try!(builder.choose_pixel_format(formats.into_iter().map(|(a, b)| (b, a))));
|
||||
let id = try!(choose_dummy_pixel_format(formats.into_iter()));
|
||||
try!(set_pixel_format(&dummy_window, id));
|
||||
}
|
||||
|
||||
|
@ -502,6 +502,8 @@ unsafe fn enumerate_arb_pixel_formats(extra: &gl::wgl_extra::Wgl, hdc: &WindowWr
|
|||
},
|
||||
srgb: if is_extension_supported(extra, hdc, "WGL_ARB_framebuffer_sRGB") {
|
||||
get_info(index, gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB) != 0
|
||||
} else if is_extension_supported(extra, hdc, "WGL_EXT_framebuffer_sRGB") {
|
||||
get_info(index, gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_EXT) != 0
|
||||
} else {
|
||||
false
|
||||
},
|
||||
|
@ -562,3 +564,21 @@ unsafe fn is_extension_supported(extra: &gl::wgl_extra::Wgl, hdc: &WindowWrapper
|
|||
|
||||
extensions.split(" ").find(|&e| e == extension).is_some()
|
||||
}
|
||||
|
||||
fn choose_dummy_pixel_format<I>(iter: I) -> Result<libc::c_int, CreationError>
|
||||
where I: Iterator<Item=(PixelFormat, libc::c_int)>
|
||||
{
|
||||
let mut backup_id = None;
|
||||
|
||||
for (format, id) in iter {
|
||||
if backup_id.is_none() {
|
||||
backup_id = Some(id);
|
||||
}
|
||||
|
||||
if format.hardware_accelerated {
|
||||
return Ok(id);
|
||||
}
|
||||
}
|
||||
|
||||
backup_id.ok_or(CreationError::NotSupported)
|
||||
}
|
||||
|
|
|
@ -129,6 +129,12 @@ impl<'a> WindowBuilder<'a> {
|
|||
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
|
||||
}
|
||||
|
||||
/// Builds the window.
|
||||
///
|
||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||
|
|
Loading…
Reference in a new issue