use gpui_engine::ImportedTextureHandle;
#[derive(Clone)]
pub struct WgpuImportedTexture {
pub view: wgpu::TextureView,
}
pub trait ImportedTextureExt {
fn to_imported_handle(&self) -> anyhow::Result<ImportedTextureHandle>;
}
impl ImportedTextureExt for wgpu::TextureView {
fn to_imported_handle(&self) -> anyhow::Result<ImportedTextureHandle> {
let texture = self.texture();
let format = texture.format();
anyhow::ensure!(
matches!(
format,
wgpu::TextureFormat::Rgba8UnormSrgb | wgpu::TextureFormat::Bgra8UnormSrgb
),
"an imported texture must sample as sRGB (Rgba8UnormSrgb or Bgra8UnormSrgb), \
but this view's texture is {format:?}"
);
anyhow::ensure!(
texture
.usage()
.contains(wgpu::TextureUsages::TEXTURE_BINDING),
"an imported texture must be created with wgpu::TextureUsages::TEXTURE_BINDING"
);
Ok(ImportedTextureHandle::new(WgpuImportedTexture {
view: self.clone(),
}))
}
}