Back to Filament

readPixels

docs/android/dokka/filament-android/com.google.android.filament/-renderer/read-pixels.md

1.75.07.0 KB
Original Source

//filament-android/com.google.android.filament/Renderer/readPixels

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.

kotlin

 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.

Parameters

main

xoffsetleft offset of the sub-region to read back
yoffsetbottom offset of the sub-region to read back
widthwidth of the sub-region to read back
heightheight of the sub-region to read back
bufferclient-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.

Throws

BufferOverflowExceptionif 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.

kotlin

 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.

Parameters

main

renderTargetRenderTarget to read back from
xoffsetleft offset of the sub-region to read back
yoffsetbottom offset of the sub-region to read back
widthwidth of the sub-region to read back
heightheight of the sub-region to read back
bufferclient-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.

Throws

BufferOverflowExceptionif the specified parameters would result in reading outside of buffer.