Skip to content

IRenderer.ReadPixelsAsync(ITexture, CancellationToken) Method

Definition

Namespace: Brine2D.Rendering

Asynchronously downloads the pixel data from a GPU texture to a CPU-side byte array.

C#
System.Threading.Tasks.Task<byte[]> ReadPixelsAsync(Brine2D.Rendering.ITexture texture, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

texture ITexture

The texture to read. Use Texture to read a render target.

cancellationToken System.Threading.CancellationToken

Cancellation token.

Returns

System.Threading.Tasks.Task<System.Byte[]>
Raw pixel bytes in BGRA8 order \(4 bytes per pixel, row\-major\). The returned array has length texture.Width × texture.Height × 4.

Remarks

This is a potentially slow GPU readback operation. It submits a copy command, waits for the GPU to finish, then maps the transfer buffer. Avoid calling every frame.