Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Vast question, batching is always a matter of compromise.</p> <p>The ideal structure for performance would be, as you mention, to one single array containing all triangles to draw.</p> <p>Starting from here, we can start adding constraints :</p> <ul> <li><p>One additional constraint is that having vertex indices in 16bits saves bandwidth and memory, and probably the fast path for your platform. So you could consider grouping triangles in chunks of 65536 vertices.</p></li> <li><p>Then, if you want to switch the shader/material/glState used to draw geometry, you have no choice (*) but to emit one draw call per shader/material/glState. So grouping triangles could consider grouping by shaderID/materialID/glStateID.</p></li> <li><p>Next, if you want to animate things, you have no choice (*) but to transmit your transform matrix to GL, and then issue a draw call. So grouping triangles could consider grouping triangles by 'transform groups', for example, all static geometry together, animated geometry that have common transforms can be grouped too.</p></li> </ul> <p>In these cases, you'd have to transform the vertices yourself (using CPU) before merging the meshes together.</p> <p>Regarding triangle strips, you can transform any mesh in strips, even if it has discontinuities in its topology, by introducing degenerate triangles. So this is a technique that always apply.</p> <p>All in all, reducing draw calls is a game of compromises, some techniques might work well for a 3d model, while others may be more suited for other 3d models. IMHO, the key is to be creative and to carefully benchmark your application to see if your changes actually improve performance on your target platform.</p> <p>HTH, cheers,</p> <hr> <p>(*) actually there are techniques that allow to reduce the number of draw calls in these cases, such as :</p> <ul> <li><p><a href="http://http.download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf"><em>texture atlases</em></a> to group different textures in a single one, to prevent switching textures in GL, thus allowing to limit draw calls</p></li> <li><p><em>(pseudo) hardware instancing</em> that allow shaders to fetch transforms from various sources to transform mesh instances in different ways.</p></li> <li><p>...</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload