utils/godot_dev_tools/addons/dev_tools/dev_frame.gd
Krzysztof kuhy Rudnicki db2650b9c9 Add godot_dev_tools 0.1.0
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXs4gEhEUMr9rgYG9V
2026-11-16 14:29:48 +01:00

21 lines
817 B
GDScript

extends RefCounted
## The frame as drawn, for the annotator. A headless run (a bot, a test) draws
## nothing and never emits frame_post_draw, so it gets a blank frame of the
## viewport's size at once: the bundle is still written, only the picture is empty.
## No class_name (the addon's scripts reach each other with relative preload).
const BLANK := Color(0.1, 0.1, 0.1)
## The viewport's last drawn frame (waits for the draw; instant when headless).
static func grab(viewport: Viewport) -> Image:
if DisplayServer.get_name() == "headless":
var size := viewport.get_visible_rect().size
var blank := Image.create(
maxi(1, int(size.x)), maxi(1, int(size.y)), false, Image.FORMAT_RGBA8
)
blank.fill(BLANK)
return blank
await RenderingServer.frame_post_draw
return viewport.get_texture().get_image()