I used this in godot plugin for my ovr-utils fork, should be very efffective here (based on obs kmsgrab plugin) https://github.com/mittorn/godot-screengrab/blob/master/src/ScreenGrab.cpp#L47