Search code examples
c++performanceopenglopengl-4

Performance gain using interleaved attribute arrays in OpenGL4.0


I work with OpenGL4.X .Recently I read this Apple OpenGLES2 doc where it is stated that using interleaved attribute arrays improves performance on IOS mobile devices and is the recommended way (instead of using blocks of attributes).

For those who didn't understand what I mean here is an example:

Block of attributes in a single attribute array:

 float vertices[]{
 //Triangle vertices:

  v0x , v0y , v0z ,
  v1x , v1y , v1z ,
  v2x , v2y , v2z ,

  //Triangle UVs:

  uv0s , uv0t ,
  uv1s , uv1t ,
  uv2s , uv2t ,

  //Triangle Normals:
  n0x , n0y , n0z ,
  n1x , n1y , n1z ,
  n2x , n2y , n2z 

}

Interleaved attribute array:

 float vertices[]{


  v0x , v0y , v0z ,
  uv0s , uv0t ,          ////vertex 1 attributes
  n0x , n0y , n0z ,

  v1x , v1y , v1z ,
  uv1s , uv1t ,         ///vertex 2 attributes
  n1x , n1y , n1z ,

  v2x , v2y , v2z ,
  uv2s , uv2t ,         ///vertex 3 attributes
  n2x , n2y , n2z 

}

So my question is : Is it also true for OpenGL running on desktop GPUs ? If yes ,then how big the performance gain can theoretically be ?


Solution

  • Is it also true for OpenGL running on desktop GPUs ?

    From Vertex specification wiki page :

    As a general rule, you should use interleaved attributes wherever possible. Obviously if you need to change certain attributes and not others, then interleaving the ones that change with those that don't is not a good idea.


    how big the performance gain can theoretically be ?

    I can't really answer that, but I wouldn't expect huge improvement. The only sure way is to measure.