pub struct ReadbackSurface { /* private fields */ }Expand description
Reusable GPU-to-CPU color readback surface owning a staging buffer and a persistent pixel cache.
Handles 256-byte row-pitch unpadding, optional R/B channel swizzling, optional Y-axis flip,
and optional unpremultiplication, while retaining Self::cached_pixels for zero-cost idle frames.
Implementations§
Source§impl ReadbackSurface
impl ReadbackSurface
pub fn new(options: ReadbackOptions) -> Self
pub fn options(&self) -> ReadbackOptions
pub fn set_options(&mut self, options: ReadbackOptions)
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn unpadded_row_pitch(&self) -> u32
pub fn size_bytes(&self) -> usize
pub fn cached_pixels(&self) -> &[u8] ⓘ
Sourcepub fn ensure_dimensions(
&mut self,
device: &Device,
width: u32,
height: u32,
) -> bool
pub fn ensure_dimensions( &mut self, device: &Device, width: u32, height: u32, ) -> bool
Ensures the staging buffer and CPU cache match (width, height), clamping to at least 1x1.
Returns true if the staging buffer was allocated or reallocated.
Sourcepub fn copy_from_texture(
&self,
encoder: &mut CommandEncoder,
texture: &Texture,
) -> Result<(), ReadbackError>
pub fn copy_from_texture( &self, encoder: &mut CommandEncoder, texture: &Texture, ) -> Result<(), ReadbackError>
Encodes a GPU texture-to-staging-buffer copy into encoder.
Sourcepub fn map_and_repack(
&mut self,
device: &Device,
) -> Result<&[u8], ReadbackError>
pub fn map_and_repack( &mut self, device: &Device, ) -> Result<&[u8], ReadbackError>
Synchronously maps the staging buffer, unpacks rows into Self::cached_pixels, and unmaps.
Sourcepub fn readback_sync(
&mut self,
device: &Device,
queue: &Queue,
texture: &Texture,
) -> Result<&[u8], ReadbackError>
pub fn readback_sync( &mut self, device: &Device, queue: &Queue, texture: &Texture, ) -> Result<&[u8], ReadbackError>
Ensures dimensions match texture, submits a copy command, and reads back the pixels synchronously.
Auto Trait Implementations§
impl !RefUnwindSafe for ReadbackSurface
impl !UnwindSafe for ReadbackSurface
impl Forget for ReadbackSurface
impl Freeze for ReadbackSurfacewhere
*const ArcInner<CoreBuffer> is !null: Freeze,
PhantomData<ArcInner<CoreBuffer>>: Freeze,
*const ArcInner<Mutex<MapContext>> is !null: Freeze,
PhantomData<ArcInner<Mutex<MapContext>>>: Freeze,
InternalBitFlags: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
impl Move for ReadbackSurface
impl Send for ReadbackSurface
impl Sync for ReadbackSurface
impl Unpin for ReadbackSurface
impl UnsafeUnpin for ReadbackSurfacewhere
*const ArcInner<CoreBuffer> is !null: UnsafeUnpin,
PhantomData<ArcInner<CoreBuffer>>: UnsafeUnpin,
*const ArcInner<Mutex<MapContext>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<MapContext>>>: UnsafeUnpin,
InternalBitFlags: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more