How to get raw frame data in gdextension _process method

Hello everyone, I hope someone can help me …

Godot Version

4.2.1 - latest


I already have working code that sends raw data to godot in gdextension. Now I would like to send raw data of current frame (_process method) in c++ gdextension to other process …
I tried to do different things, but it seems like I cannot do it, for example

    Viewport* viewport = get_viewport();

    if (viewport) {
        // Get the current frame's texture from the viewport
        auto tex = viewport->get_texture();
        auto image = viewport->get_image();
        if (image.is_valid()) {
            const uint8_t* data = image->get_data().read().ptr();

            auto w = image->get_width();
            auto h = image->get_height();

            UtilityFunctions::print(w, "", h );


Maybe this was working on previous versions. Is there any documentation on how can I do it now? I’m extending Node2D to get _process method called for every frame.

Any help welcome!

Are you getting an error when you run the code? The bit shown seems to work for me. Are you sure _process is being called?

Hi, thank you for taking time.

… I managed to get a bit further by including viewport_texture.hpp header :slight_smile:

It seems that I cannot get pointer to raw image data, it just dies. If I just print width and height, I get correct reading.

auto data = image->get_data().ptr();
Can you confirm it works for you? Also … is _process method best place to get current rendered image?

I can confirm that it works for me. Printing the data pointer in UtilityFunctions prints . I don’t know enough about the project to know if _process is the best place to get the image.

The image class does have a few methods that may be useful, like save_png and save_png_to_buffer. Accessing the pointer directly, outside of the Godot process, may not end well.

I get a build error when I try to build with a class that hasn’t had their header set properly. You may want to include <godot/classes/image.hpp> as well.