mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
hal/egl: don't assume EGL-1.5 if upcast works (#2105)
This commit is contained in:
parent
161e81a070
commit
cda0be9cbf
@ -598,7 +598,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
) -> Option<crate::SurfaceCapabilities> {
|
||||
if surface.presentable {
|
||||
Some(crate::SurfaceCapabilities {
|
||||
formats: if surface.enable_srgb {
|
||||
formats: if surface.supports_srgb() {
|
||||
vec![
|
||||
wgt::TextureFormat::Rgba8UnormSrgb,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
@ -656,11 +656,6 @@ impl crate::Instance<super::Api> for Instance {
|
||||
}
|
||||
};
|
||||
|
||||
let enable_srgb = match inner.srgb_kind {
|
||||
SrgbFrameBufferKind::Core | SrgbFrameBufferKind::Khr => true,
|
||||
SrgbFrameBufferKind::None => false,
|
||||
};
|
||||
|
||||
inner
|
||||
.egl
|
||||
.make_current(inner.display, None, None, None)
|
||||
@ -676,7 +671,7 @@ impl crate::Instance<super::Api> for Instance {
|
||||
pbuffer: inner.pbuffer,
|
||||
raw_window_handle,
|
||||
swapchain: None,
|
||||
enable_srgb,
|
||||
srgb_kind: inner.srgb_kind,
|
||||
})
|
||||
}
|
||||
unsafe fn destroy_surface(&self, _surface: Surface) {}
|
||||
@ -756,7 +751,7 @@ pub struct Surface {
|
||||
pub(super) presentable: bool,
|
||||
raw_window_handle: RawWindowHandle,
|
||||
swapchain: Option<Swapchain>,
|
||||
pub(super) enable_srgb: bool,
|
||||
srgb_kind: SrgbFrameBufferKind,
|
||||
}
|
||||
|
||||
unsafe impl Send for Surface {}
|
||||
@ -834,6 +829,13 @@ impl Surface {
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn supports_srgb(&self) -> bool {
|
||||
match self.srgb_kind {
|
||||
SrgbFrameBufferKind::None => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Surface<super::Api> for Surface {
|
||||
@ -891,58 +893,55 @@ impl crate::Surface<super::Api> for Surface {
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let raw = if let Some(egl) = self.egl.upcast::<egl::EGL1_5>() {
|
||||
let attributes = [
|
||||
egl::RENDER_BUFFER as usize,
|
||||
if cfg!(target_os = "android") {
|
||||
egl::BACK_BUFFER as usize
|
||||
} else {
|
||||
egl::SINGLE_BUFFER as usize
|
||||
},
|
||||
// Always enable sRGB in EGL 1.5
|
||||
egl::GL_COLORSPACE as usize,
|
||||
egl::GL_COLORSPACE_SRGB as usize,
|
||||
egl::ATTRIB_NONE,
|
||||
];
|
||||
let mut attributes = vec![
|
||||
egl::RENDER_BUFFER,
|
||||
if cfg!(target_os = "android") {
|
||||
egl::BACK_BUFFER
|
||||
} else {
|
||||
egl::SINGLE_BUFFER
|
||||
},
|
||||
];
|
||||
match self.srgb_kind {
|
||||
SrgbFrameBufferKind::None => {}
|
||||
SrgbFrameBufferKind::Core => {
|
||||
attributes.push(egl::GL_COLORSPACE);
|
||||
attributes.push(egl::GL_COLORSPACE_SRGB);
|
||||
}
|
||||
SrgbFrameBufferKind::Khr => {
|
||||
attributes.push(EGL_GL_COLORSPACE_KHR as i32);
|
||||
attributes.push(EGL_GL_COLORSPACE_SRGB_KHR as i32);
|
||||
}
|
||||
}
|
||||
attributes.push(egl::ATTRIB_NONE as i32);
|
||||
|
||||
// Careful, we can still be in 1.4 version even if `upcast` succeeds
|
||||
let raw_result = if let Some(egl) = self.egl.upcast::<egl::EGL1_5>() {
|
||||
let attributes_usize = attributes
|
||||
.into_iter()
|
||||
.map(|v| v as usize)
|
||||
.collect::<Vec<_>>();
|
||||
egl.create_platform_window_surface(
|
||||
self.display,
|
||||
self.config,
|
||||
native_window_ptr,
|
||||
&attributes,
|
||||
&attributes_usize,
|
||||
)
|
||||
.map_err(|e| {
|
||||
log::warn!("Error in create_platform_window_surface: {:?}", e);
|
||||
crate::SurfaceError::Lost
|
||||
})
|
||||
} else {
|
||||
let mut attributes = vec![
|
||||
egl::RENDER_BUFFER,
|
||||
if cfg!(target_os = "android") {
|
||||
egl::BACK_BUFFER
|
||||
} else {
|
||||
egl::SINGLE_BUFFER
|
||||
},
|
||||
];
|
||||
if self.enable_srgb {
|
||||
attributes.push(EGL_GL_COLORSPACE_KHR as i32);
|
||||
attributes.push(EGL_GL_COLORSPACE_SRGB_KHR as i32);
|
||||
}
|
||||
attributes.push(egl::ATTRIB_NONE as i32);
|
||||
self.egl
|
||||
.create_window_surface(
|
||||
self.display,
|
||||
self.config,
|
||||
native_window_ptr,
|
||||
Some(&attributes),
|
||||
)
|
||||
.map_err(|e| {
|
||||
log::warn!("Error in create_platform_window_surface: {:?}", e);
|
||||
crate::SurfaceError::Lost
|
||||
})
|
||||
}?;
|
||||
self.egl.create_window_surface(
|
||||
self.display,
|
||||
self.config,
|
||||
native_window_ptr,
|
||||
Some(&attributes),
|
||||
)
|
||||
};
|
||||
|
||||
(raw, wl_window)
|
||||
match raw_result {
|
||||
Ok(raw) => (raw, wl_window),
|
||||
Err(e) => {
|
||||
log::warn!("Error in create_platform_window_surface: {:?}", e);
|
||||
return Err(crate::SurfaceError::Lost);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -83,7 +83,6 @@ impl crate::Instance<super::Api> for Instance {
|
||||
swapchain: None,
|
||||
texture: None,
|
||||
presentable: true,
|
||||
enable_srgb: true, // WebGL only supports sRGB
|
||||
})
|
||||
} else {
|
||||
unreachable!()
|
||||
@ -107,7 +106,6 @@ pub struct Surface {
|
||||
pub(super) swapchain: Option<Swapchain>,
|
||||
texture: Option<glow::Texture>,
|
||||
pub(super) presentable: bool,
|
||||
pub(super) enable_srgb: bool,
|
||||
present_program: Option<glow::Program>,
|
||||
}
|
||||
|
||||
@ -169,6 +167,10 @@ impl Surface {
|
||||
|
||||
program
|
||||
}
|
||||
|
||||
pub fn supports_srgb(&self) -> bool {
|
||||
true // WebGL only supports sRGB
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Surface<super::Api> for Surface {
|
||||
|
Loading…
Reference in New Issue
Block a user