mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-21 07:41:51 +00:00
wgpu: Export the error type for TryFrom<wgpu::Texture> for Image as slint::wgpu_24::WGPUTextureImportError
cc #8631
This commit is contained in:
parent
74a62fd646
commit
7af9eec820
2 changed files with 27 additions and 29 deletions
|
@ -991,47 +991,21 @@ impl BorrowedOpenGLTextureBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-wgpu-24")]
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
/// This enum describes the possible errors that can occur when importing a WGPU texture,
|
||||
/// via [`Image::try_from()`].
|
||||
pub enum WGPUTextureImportError {
|
||||
/// The texture format is not supported. The only supported format is Rgba8Unorm and Rgba8UnormSrgb.
|
||||
InvalidFormat,
|
||||
/// The texture usage must include TEXTURE_BINDING as well as RENDER_ATTACHMENT.
|
||||
InvalidUsage,
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-wgpu-24")]
|
||||
impl core::fmt::Display for WGPUTextureImportError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
WGPUTextureImportError::InvalidFormat => f.write_str(
|
||||
"The texture format is not supported. The only supported format is Rgba8Unorm and Rgba8UnormSrgb",
|
||||
),
|
||||
WGPUTextureImportError::InvalidUsage => f.write_str(
|
||||
"The texture usage must include TEXTURE_BINDING as well as RENDER_ATTACHMENT",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-wgpu-24")]
|
||||
impl TryFrom<wgpu_24::Texture> for Image {
|
||||
type Error = WGPUTextureImportError;
|
||||
type Error = crate::graphics::wgpu_24::TextureImportError;
|
||||
|
||||
fn try_from(texture: wgpu_24::Texture) -> Result<Self, Self::Error> {
|
||||
if texture.format() != wgpu_24::TextureFormat::Rgba8Unorm
|
||||
&& texture.format() != wgpu_24::TextureFormat::Rgba8UnormSrgb
|
||||
{
|
||||
return Err(WGPUTextureImportError::InvalidFormat);
|
||||
return Err(Self::Error::InvalidFormat);
|
||||
}
|
||||
let usages = texture.usage();
|
||||
if !usages.contains(wgpu_24::TextureUsages::TEXTURE_BINDING)
|
||||
|| !usages.contains(wgpu_24::TextureUsages::RENDER_ATTACHMENT)
|
||||
{
|
||||
return Err(WGPUTextureImportError::InvalidUsage);
|
||||
return Err(Self::Error::InvalidUsage);
|
||||
}
|
||||
Ok(Self(ImageInner::WGPUTexture(WGPUTexture::WGPU24Texture(texture))))
|
||||
}
|
||||
|
|
|
@ -82,3 +82,27 @@ impl Default for WGPUConfiguration {
|
|||
Self::Automatic(WGPUSettings::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
/// This enum describes the possible errors that can occur when importing a WGPU texture,
|
||||
/// via [`Image::try_from()`](super::Image::try_from()).
|
||||
pub enum TextureImportError {
|
||||
/// The texture format is not supported. The only supported format is Rgba8Unorm and Rgba8UnormSrgb.
|
||||
InvalidFormat,
|
||||
/// The texture usage must include TEXTURE_BINDING as well as RENDER_ATTACHMENT.
|
||||
InvalidUsage,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for TextureImportError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
TextureImportError::InvalidFormat => f.write_str(
|
||||
"The texture format is not supported. The only supported format is Rgba8Unorm and Rgba8UnormSrgb",
|
||||
),
|
||||
TextureImportError::InvalidUsage => f.write_str(
|
||||
"The texture usage must include TEXTURE_BINDING as well as RENDER_ATTACHMENT",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue