I have read that in order to optimize WebGL application, one should reduce an amount of draw calls. But does it mean that computing a one big mesh from all single meshes on CPU by modifying vertices position (which I heard is much slower than GPU while talking about matrix multiplications) and calling the draw call once would be faster than drawing every single mesh using model matrix inside GPU, calling the draw call for each one of them?


It depends.

  • If it's something static, such as an environment, then it might make sense to group it all together.

  • For several independently moving/transforming objects, it's usually best to keep them separate, as per-vertex calculations are much faster on the GPU than CPU (the GPU can run several vertex calculations in parallel).

  • If the objects are very small though (i.e. particles, billboards), it may be worth grouping them in a large mesh.

There's no general rule, it's all about finding the right balance.

  • \$\begingroup\$ Hmmm, if GPU is really so OP, I just came up with an idea: -#- group as many separate meshes into a one big mesh (the amount depends on how many Vertex Uniform Vectors does a browser support) -#- send an array of Model Matrices along with current's mesh ID attribute for each of grouped object for object dereferencing -#- calculate a vertex position like this: gl_Position = projMatrix * viewMatrix * modelMatrix[currentObjID] * vec4(vertexPosition, 1.0); In my head it sounds clever, but is it even possible to send an array of matrices to the shader? \$\endgroup\$
    – Winged
    Jun 19 '14 at 17:00
  • \$\begingroup\$ You can send an array of matrices in desktop OpenGL (alternatively you could pass them as a texture), although to achieve what you're suggesting, you'd have to have a mesh ID attached to each vertex; that's going to increase memory usage for questionable performance gains. \$\endgroup\$
    – Fault
    Jun 20 '14 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .