Sampling a Pixel’s Color From a Screen or Texture

The graphics pipeline is heavily, well, pipelined. That means that any attempt to read back data requires flushing any pending commands, and draining the pipe, waiting for them to be done. Most of the time you’re seeing is probably not due to the transfer, but due to the pipeline stall.

The only way to get around this is to get the screenshot asynchronously, meaning it will be copied in the background and you get a notification (callback, event or resumption of a coroutine) when it’s done. This may be several frames later, however, so it’s only useful if you don’t need the result right away.

If you want to use this, you will have to use a development build of Panda, which has support for getting a screenshot asynchronously.

As an aside, getting the screenshot as a Texture and using .peek() on that texture is more efficient than getting it via PNMImage.

1 Like