Looking for tips to speed up getScreenshot

Hi Folks,

For a personnal project, I’m trying to use Panda3D as a remote Rendering Engine, meaning I want to render a scene then send it through a thin client over TCP. Actually, my main problem is the Panda’s method to copy the framebuffer into an object, which is slow. In my code I have :

frameBuffer = PNMImage()
self.showBase.win.getScreenshot(frameBuffer)

For a 640*480 resolution, Panda3D can take between 0.1 and 0.3s to render a simple scene, which means that my framerate can be limited up to 1/0.3 = 3.33 fps.

Of course, lowering the resolution (at the expense of image quality) helped me to speed up my project.

Do you have any optimization trick to speed up this task ? Also, just because I’m curious, could someone tell me what is the slowest process : saving a screenshot into a PNMImage or retrieving the framebuffer ? I’m also wondering if switching to a full C++ rendering engine (Irrlicht or Ogre) would give much better performance (even if Panda3D is implemented in C++).

Thanks in advance

PS : Excuse my english

getScreenshot() is not intended to be fast enough to run every frame. Actually, saving the framebuffer to RAM is going to slow you down considerably no matter how you do it, but it is possible to get interactive rates with this technique.

Your best bet is to render to a texture, with base.win.addRenderTexture() or base.win.makeTextureBuffer(). Be sure you set the flag that indicates you wish to copy the texture image all the way to system RAM, instead of leaving it in graphics memory.

Then, create a task that sends tex.getRamImage() over the wire to your remote client. (You should probably also check tex.hasRamImage() first before you query getRamImage.) Your remote client will receive the raw, unformatted image contents, and can load it into its own texture with tex.setRamImage() or some similar mechanism.

This avoids all of the overhead needed to populate a PNMImage, which is painfully slow.

Python is certainly not your bottleneck in this case. There’s no advantage to eliminating it.

David

1 Like

Thank you so much David, I’ll follow your advices and see what improvements I can get.