pub struct Rgba8Readback { /* private fields */ }Expand description
A submitted texture readback whose buffer has not been mapped yet.
The handle owns its staging buffer, so it outlives the renderer borrow and can be moved into an asynchronous browser task. Any pack target returns to the texture pool after its copy submission, before buffer mapping finishes.
Implementations§
Source§impl Rgba8Readback
impl Rgba8Readback
Sourcepub const fn size(&self) -> RenderSize
pub const fn size(&self) -> RenderSize
Returns the pixel dimensions the mapped result will contain.
Sourcepub const fn staging_bytes(&self) -> u64
pub const fn staging_bytes(&self) -> u64
Returns bytes retained by the GPU-visible staging buffer.
Sourcepub fn wait_ready(&self) -> Result<(), RenderError>
pub fn wait_ready(&self) -> Result<(), RenderError>
Blocks a native caller until this specific readback submission is mapped.
Other work may be submitted between creating and waiting on the handle; the stored submission index prevents this wait from draining the entire device queue.
§Errors
Returns RenderError::TextureReadback when mapping or device polling
fails.
Sourcepub fn wait(self) -> Result<Vec<u8>, RenderError>
pub fn wait(self) -> Result<Vec<u8>, RenderError>
Waits for this readback and packs its mapped rows into RGBA8 pixels.
§Errors
Returns RenderError::TextureReadback when mapping, polling, or row
packing fails.
Sourcepub fn map_async(
&self,
on_ready: impl FnOnce(Result<(), RenderError>) + Send + 'static,
)
pub fn map_async( &self, on_ready: impl FnOnce(Result<(), RenderError>) + Send + 'static, )
Requests buffer mapping and reports readiness exactly once.
The callback receives the failure when mapping was refused or was already requested, which a caller must treat as a failed frame rather than as empty pixels.
Sourcepub fn poll(&self)
pub fn poll(&self)
Advances backends that need explicit polling to resolve a mapping.
Browser WebGPU resolves mapping on its own event loop and ignores this; wgpu-core backends need it to make progress without a blocking wait.
Sourcepub fn finish(self) -> Result<Vec<u8>, RenderError>
pub fn finish(self) -> Result<Vec<u8>, RenderError>
Packs the mapped rows into tightly packed premultiplied RGBA8.
§Errors
Returns RenderError::TextureReadback when the buffer is not mapped,
and RenderError::GpuWorkDropped when the GPU did not run the copy:
the buffer holds no pixels of this readback, so it is not recycled,
and the renderer refuses further work.