How Node2D works internally ?

Ajrarn777Ajrarn777 Posts: 13Member
in 2D

I had the assumption that, when drawing into a Node2D (with draw_line or others) , Godot was internally creating a texture cache , and draw directly on this texture. Then this texture was passed to the video card, so the draw function doesn't need to be executed on every frame.

But, if I made 500 calls to the draw_line function inside the on_draw( ) call back, it became super, super slow (on my android at least). So my assumption is somewhere wrong.

Are the draw_line operations are executed directly by the video card on every frame ?
How this is working.

I think it is important that I understand the basic so my code is optimized.
Thanks for your help.


  • GlyphTheWolfGlyphTheWolf Posts: 78Member


    I checked source code of Godot available on Github and well, that seems to be pretty complicated to understand exactly in short time, but from my knowledge and what I saw in code it looks like:
    1. When you call draw_line() for example Godot adds "draw_line" command to some commands list that should be performed when drawing that canvas item (that is probably "caching" mentioned in docs).
    2. Later that command list seems to be transformed into some commands buffer
    3. Rendering server uses that command buffer to process multiple commands from buffer
    That commands seems to be separated by type of thing you want to render (like mesh, multimesh, particle, primitive) and all things of the same type are processed together (like all primitives for example).

    I saw also something about binding texture, but I don't know if that is texture which holds result or maybe if that is texture used if you want to draw some texture?

    Exactly understanding that need more time or Godot programmer could answer that question better.

  • Ajrarn777Ajrarn777 Posts: 13Member

    Great, thanks @GlyphTheWolf

    I think this is enough to confirm the theory that the draw commands are performed on the graphic card, or somewhere in between.
    Should, we should be extra careful how we structure the draw operations.


Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file