Is there a glReadPixels() equivalent?


I’m trying to implement a mouse picker via the unique-color-per-object method, and thus need to read the contents of a GraphicsBuffer. (I know this is discouraged in Panda3D, but the extra render is piggybacking off a shader I need anyway, so there’s no cost there.)

I’m using GraphicsEngine.extractTextureData() to pull the texture in to RAM, but it’s doing a number on my framerate. Is there a way to read a single pixel from the buffer? If not, I’ll try setting up a camera to render the area under the mouse to a 1-by-1 buffer.


Hmm, you might be able to create a 1x1 DisplayRegion under the mouse, and use DisplayRegion.getScreenShot() to copy the data to RAM. This will basically map to a glReadPixels() call, but I have no idea whether this will give you the performance you need or not.


Hey David, thanks for the tip.

I got decent performance by setting up a 1x1 buffer and using a camera with the film size equal to one pixel and film offset based on the mouse position. It takes around 600us to extract the texture, make a texture peeker, and grab the pixel.

While this is fine, I tried implementing the picker with DisplayRegion, on your suggestion, with the hope that it might improve performance by saving a render operation (albeit a teeny 1x1 render).

Unfortunately, getScreenshot() seems to copy the contents of the visible window rather than the contents of the buffer that I made the DisplayRegion from. I ran in to the same problem with GraphicsOutput.getScreenshot() a while back.

Ah, that happens because of the render order. It means that you are actually rendering to a ParasiteBuffer, instead of a true buffer; and the ParasiteBuffer is just a convention for rendering into the main window in sequence.

You could try insisting on a true buffer. The way to insist on a true buffer instead of a ParasiteBuffer differs depending on the way you are opening the buffer; but one easy way is to set the following in your Config.prc file:

prefer-texture-buffer 1
prefer-parasite-buffer 0
force-parasite-buffer 0

But based on what you say, it’s probably not worth the trouble.