tags:

views:

261

answers:

4

Is there an optimum packing format for vertex arrays on the iPhone hardware? My textured (triangle) arrays are ordered:

  1. Vertex (x, y, z)
  2. Vertex Normal (x, y, z)
  3. Texture Coordinates (u, v)

This is the way I've always done it. Should the UVs come before the normals? I'm not sure if it matters. I'd assume that the texturing & lighting units would have a preference, but I can't find anything about it. I certainly can't detect a difference.

A: 

It does not make a difference.

Nils Pipenbrinck
+1  A: 

From the iPhone OpenGL ES Programming Guide:

In OpenGL ES, you enable each attribute your application needs and provide a pointer to an array of that data type. OpenGL ES allows you to specify a stride, which offers your application the flexibility of providing multiple arrays (also known as a struct of arrays) or a single array with a single vertex format (an array of structs).

Your application should use an array of structs with a single interleaved vertex format. Interleaved data provides better memory locality than using a separate array for each attribute.

You may want to separate out attribute data that is updated at a frequency different from the rest of your vertex data (as described in “Vertex Buffer Usage”). Similarly, if attribute data can be shared between two or more pieces of geometry, separating it out may reduce your memory usage.

There doesn't seem to be any preferred ordering suggested in any of the current documentation, but there was a technote (TN2230) out there on tuning OpenGL ES for the iPhone that appears to have vanished. It had the following sentence in it:

For optimal performance, interleave the individual components in an order of Position, Normal, Color, TexCoord0, TexCoord1, PointSize, Weight, MatrixIndex.

Note this this technote may have been removed because of incorrect or outdated information contained within it. I don't know that I saw much of a boost in ordering my vertex buffer objects in this way, certainly not as much as simply reducing the size of my geometry by using GL_SHORT instead of GL_FLOAT where I could.

Brad Larson
Thank you. Since I'm following the outdated / revoked suggestion and no substitute has come about, I can proceed confidently. Thanks again!
Pestilence
+1  A: 

Ordering of vertex attributes is really only relevant on older devices (iPhone 2G/3G and iPod touch 1G/2G) running iPhone OS 3.1 or later, which can submit vertex data more efficiently if the ordering matches what used to be in TN2230. This won’t increase vertex throughput on the GPU side, but can result in a reduction in CPU usage. As Brad observes, if you want to push more vertices through the GPU, your best bet is to make them smaller.

Pivot
A: 

Since the iPhone has only a small number of hardware implementations, can't you just measure performance empirically and find out which way is fastest for sure, in practice rather than in theory?

Tartley
I couldn't detect a difference. There was nothing statistically significant in my own benchmarks. Still, I didn't want to break future compatibility just because it doesn't matter right now... but, yes: test assumptions always.
Pestilence