How Drawing Works
Where to draw from and what persists between frames.
Where to Draw
When drawing from code with GeomDraw, place calls in the _process function. Geom nodes handle drawing on their own.
Draw calls are collected during the frame and sent to the renderer once at the end.
Don’t call
GeomDrawfrom Godot’s_drawfunction. That is for Godot’s canvas drawing.
Viewports
GeomDraw targets one viewport: the main window, or the edited
scene in the editor. draw_into(viewport) changes the target for the calls
that follow, and draw_into_default() returns to the default. Shapes appear
only in the viewport they were drawn into.
draw_intois draw state and follows the same lifecycle as the rest; see the Draw State guide.
Between Frames
This is an immediate mode API so shapes must be redrawn every frame.
Draw state, however, is kept between frames. Most scripts should start _process
with reset_all_draw_states(). reset_style() resets everything but the
transforms, and reset_transform() resets only transforms.
Nodes and Scripts
Nodes draw through the same GeomDraw singleton as scripts, so the two share
batches. A node’s draw state is self-contained. Nodes and scripts never change
each other’s draw state.
Draw order follows _process order, which for nodes is tree order.
In the Editor
Geom nodes draw in the editor with no setup.
A script that calls GeomDraw runs in the editor only as a tool script. Add
@tool at the top of the script and its _process draws in the editor.
The editor does not redraw every frame. To animate in the editor, call
request_editor_redraw() from _process.