docs/android/dokka/filament-android/com.google.android.filament/-renderer/read-pixels.md
//filament-android/com.google.android.filament/Renderer/readPixels
[main]
open fun readPixels(xoffset: Int, yoffset: Int, width: Int, height: Int, buffer: Texture.PixelBufferDescriptor)
Reads back the content of the SwapChain associated with this Renderer.
Framebuffer as seen on User buffer (PixelBufferDescriptor)
screen
+--------------------+
| | .stride .alignment
| | ----------------------->-->
| | O----------------------+--+ low addresses
| | | | | |
| w | | | .top | |
| <---------> | | V | |
| +---------+ | | +---------+ | |
| | ^ | | ======> | | | | |
| x | h| | | |.left| | | |
+------>| v | | +---->| | | |
| +.........+ | | +.........+ | |
| ^ | | | |
| y | | +----------------------+--+ high addresses
O------------+-------+
readPixels must be called within a frame, meaning after beginFrame and before endFrame. Typically, readPixels will be called after render.
After issuing this method, the callback associated with buffer will be invoked on the main thread, indicating that the read-back has completed. Typically, this will happen after multiple calls to beginFrame, render, endFrame.
It is also possible to use a Fence to wait for the read-back.
readPixels is intended for debugging and testing. It will impact performance significantly.
main
| xoffset | left offset of the sub-region to read back |
| yoffset | bottom offset of the sub-region to read back |
| width | width of the sub-region to read back |
| height | height of the sub-region to read back |
| buffer | client-side buffer where the read-back will be written |
| The following format are always supported: | |
| RGBARGBA_INTEGER | |
| The following types are always supported: | |
| UBYTEUINTINTFLOAT | |
| Other combination of format/type may be supported. If a combination is not supported, this operation may fail silently. Use a DEBUG build to get some logs about the failure. |
| BufferOverflowException | if the specified parameters would result in reading outside of buffer. |
[main]
open fun readPixels(renderTarget: RenderTarget, xoffset: Int, yoffset: Int, width: Int, height: Int, buffer: Texture.PixelBufferDescriptor)
Reads back the content of a specified RenderTarget.
Framebuffer as seen on User buffer (PixelBufferDescriptor)
screen
+--------------------+
| | .stride .alignment
| | ----------------------->-->
| | O----------------------+--+ low addresses
| | | | | |
| w | | | .top | |
| <---------> | | V | |
| +---------+ | | +---------+ | |
| | ^ | | ======> | | | | |
| x | h| | | |.left| | | |
+------>| v | | +---->| | | |
| +.........+ | | +.........+ | |
| ^ | | | |
| y | | +----------------------+--+ high addresses
O------------+-------+
Typically readPixels will be called after render and before endFrame.
After issuing this method, the callback associated with buffer will be invoked on the main thread, indicating that the read-back has completed. Typically, this will happen after multiple calls to beginFrame, render, endFrame.
It is also possible to use a Fence to wait for the read-back.
OpenGL only: if issuing a readPixels on a RenderTarget backed by a Texture that had data uploaded to it via setImage, the data returned from readPixels will be y-flipped with respect to the setImage call.
readPixels is intended for debugging and testing. It will impact performance significantly.
main
| renderTarget | RenderTarget to read back from |
| xoffset | left offset of the sub-region to read back |
| yoffset | bottom offset of the sub-region to read back |
| width | width of the sub-region to read back |
| height | height of the sub-region to read back |
| buffer | client-side buffer where the read-back will be written |
| The following format are always supported: | |
| RGBARGBA_INTEGER | |
| The following types are always supported: | |
| UBYTEUINTINTFLOAT | |
| Other combination of format/type may be supported. If a combination is not supported, this operation may fail silently. Use a DEBUG build to get some logs about the failure. |
| BufferOverflowException | if the specified parameters would result in reading outside of buffer. |