diff --git a/wgpu/src/api/texture.rs b/wgpu/src/api/texture.rs index c076b8503..931c28ea4 100644 --- a/wgpu/src/api/texture.rs +++ b/wgpu/src/api/texture.rs @@ -197,6 +197,25 @@ impl Texture { } } +#[cfg(wgpu_core)] +impl Texture { + /// Create a new texture of wgpu from a wgpu-core texture. + /// + /// # Arguments + /// + /// - `core_texture` - wgpu-core texture. + pub fn from_core(core_texture: alloc::sync::Arc) -> Self { + Self { + inner: crate::backend::wgpu_core::CoreTexture::from_core(core_texture).into(), + } + } + + /// Returns the underlying wgpu-core texture if this `Texture` is on the wgpu-core backend, otherwise `None`. + pub fn as_core(&self) -> Option> { + self.inner.as_core_opt().map(|cd| cd.as_core()) + } +} + /// Describes a [`Texture`]. /// /// For use with [`Device::create_texture`]. diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 153f9ff14..ccb0b90d5 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -324,6 +324,16 @@ impl CoreTexture { pub unsafe fn as_hal(&self) -> Option> { unsafe { self.wgpu_texture.clone().as_hal::() } } + + pub(crate) fn from_core(core_texture: Arc) -> Self { + Self { + wgpu_texture: core_texture, + } + } + + pub(crate) fn as_core(&self) -> Arc { + self.wgpu_texture.clone() + } } #[derive(Debug, Clone)]