recordCaptureOrNull

fun CommandBuffer.recordCaptureOrNull(device: GpuDevice, window: Window, texture: GpuTexture, width: Int, height: Int, format: TextureFormat): FrameCapture?(source)

Records a read-back of texture into this command buffer if window has captures queued with Window.capture, and returns it, or returns null and records nothing when none is queued. Takes the queued captures off window either way.

Call it after the frame's last render pass into texture has ended and before the buffer is submitted; then submit with CommandBuffer.submitAndAcquireFence, wait for the fence and call FrameCapture.save. texture is width by height pixels in format, which must be an 8-bit RGBA or BGRA format such as the swapchain's or TextureFormat.RGBA8. When texture is the swapchain texture last acquired for window, the size SDL reported when it was acquired is read back instead of width by height, since the window may have changed size since. With no capture queued the call only checks the queue, so it costs nothing to make every frame.

A capture that cannot be recorded, because format is not supported or the read-back memory cannot be allocated or copied, prints one line to standard error through printError and is dropped, and the function returns null.