How/where to hook into godot's renderer to dump framebuffers to CPU?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gandalf3

I’d like to use Godot to render visualizations to be overlayed on a video stream in real-time, and I need a way to get the frames out of godot with the alpha channel intact.

However, I’m not sure about the where to to go to pull image data off the GPU. I don’t mind writing a module if need be, but I don’t know how I can hook in to the render pipeline to call glReadPixels or something.

Any suggestions? Are there better ways to go about this that I’m missing?

Thanks!


Ideally I’d like to be able to do the rendering off-screen as well.

:bust_in_silhouette: Reply From: Zylann

I know you can download the last drawn frame from a Viewport to main memory by using Viewport.get_texture().get_data(). This will return an Image object containing the pixel data.
Note that this is a very expensive operation, it can lag a bit if the resolution is too big.

Each Godot game runs under a main viewport representing the screen, which you can get with get_viewport().
You can render offscreen by putting your scene under a custom viewport, and making it render always (by default I think it won’t render if not being made visible by a viewpot container node).

As for hooking up in the renderer itself, I don’t know. Maybe there is another way involving modification of rasterizer_gles3.cpp?
If the destination of the frame is to be rendered using the same graphics card, I imagine there should be a better way than having to download the screen from it 60 times per second.