0
\$\begingroup\$


I was wondering whats more efficient to do if you want to transform a mesh.
1) Transforming a matrix and pass that to a shader or
2) Manipulate the meshs vertex data directly

I was wondering because LibGDX is using the second option to transform sprites. And calculating the translation, rotation and scaling for every mesh every frame seems a bit too much, since you have to change the vertex data every frame too.

\$\endgroup\$
2
\$\begingroup\$

It's usually faster to use matrices and keep the vertices the same for multiple reasons:

  • The GPU makes optimizations based on the fact, that the vertices don't change. There are ways to make OpenGL expect changes in the vertex list (like using GL_DYNAMIC_DRAW), but these methods are still slow.

  • You usually don't need to update every matrix every frame, but if any one of them changes, you'd need to update the vertices. For example the projection matrix hardly changes if at all.

  • The CPU is good at doing complex stuff, but slowly (relatively) and the GPU is good at doing basic stuff, but fast. This means, that the GPU is very fast at matrix multiplications.

  • Calculating matrices is very fast. it's mostly just setting some values to constant or easily calculateable values. The most complex is the rotational matrix, and it only requires calculating the cosinus and sinus of 3 angles.

  • Even if every matrix has to get updated, you only need to load 48 values to the GPU. This could only be faster, if you only need to update less than 16 vertices.

\$\endgroup\$
  • \$\begingroup\$ Thanks, that's what I first thought too, but it's always good to here some more opinions. \$\endgroup\$ – mrdlink Aug 26 '17 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.