What we are talking about really is the work of the GPU and OpenGL. Two things are involved here:
- Giving OpenGL instructions to set up the render state. Which shader should be used? Which texture? Which blend mode? And so on.
- Instructions sent to the GPU to draw a mesh. These are the draw calls.
The initial setup of the render state is expensive. Telling the GPU to draw a mesh isn’t.
Defold will try to batch draw calls that have the same render state (ie the same texture, shader, blend mode etc).
When I write “break a batch” what I really mean is that if we have a long list of things in the game (for instance sprites) that have the same properties they will all be drawn in a single draw call. This is good. BUT if I have one sprite with another material or with another blend mode and stick that into the middle of my long list of otherwise identical sprites then I’m breaking the batch of draw calls. What would otherwise have resulted in 1 draw call now results in 3 draw calls. This is bad.
The documented that has already been linked previously covers this: Draw calls and Defold
To clarify:
Rendering of sprites, spine models, particle fx etc
- Rendering is based on z-order, back to front.
- Components on different depths will be batched unless one of the following is different from the previous component:
- Component type (sprite, spine, particle, label, model)
- Texture
- Material
- Blend mode, tint etc
- Collection proxies
- Note: Each particle emitter will result in a draw call
Rendering of gui scenes
- Rendering is based on the order of the nodes in the outline, depth first
- Nodes will be batched unless one of the following is different from the previous node:
- Node type (box, text, pie)
- Texture
- Blend mode
- Font
- Stencil settings
Layers are used to group different nodes to reduce the number of draw calls. Some images: