Optimizing meshes for the iPhone

The PowerVR guide says if you order triangle indices as if they were triangle strips you will get a speed boost, because the PowerVR chip implementation uses  triangle strips internally. The PowerVR SDK has an example to shows this, using a model of a sphere. I assumed that the example was an extreme case and you wouldn’t see such a big improvement for real models. However, I was pleasantly surprised to see that it actually did give a big improvement in a real world example – cutting down render time from 38ms to 35.5ms in a scene with 18 skinned meshes.

I used tootle to re-order the indices:

int result = TootleOptimizeVCache(pIndices,
      numTriIndices/3, m_listVertexArray[0]->GetNumVertices(),
      TOOTLE_DEFAULT_VCACHE_SIZE, pIndices, NULL, TOOTLE_VCACHE_LSTRIPS);
if (result != TOOTLE_OK)
    cout << "could not optimise!" << endl;

It’s important to use TOOTLE_VCACHE_LSTRIPS, because the default ordering is designed for PC GPUs and won’t work well on the iPhone.
Also, you have to reorder the vertex data to match the order in the triangle index array. Tootle can be found here.
Unfortunately, Tootle crashes for certain meshes. If there was source code, I probably could have fixed that – but there isn’t :(.

Advertisements

Rendering models with transparent textures

I was having problems rending low polygon trees in my scene. It was because they used transparent textures which are always problemic. I found this artical that helped me greatly:

http://www.sjbaker.org/steve/omniv/alpha_sorting.html

The solution was to render all opaque objects first, then do:

glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_ALPHA_TEST);
and now every thing renders perfectly