In Xcode version 4.2 and above, there’s a very nice feature to capture OpenGL rendering commands from your game as it runs on an iOS device. I use the OpenGL ES 2.0 API, but it works the same in ES 1.1. Here are some helpful tips that I’ve discovered. I bumbled through these issues myself, so these will hopefully save you some time.
- Only render the objects that you are debugging. In Xcode 4.2, capturing a frame consumes a TON of memory if you have a lot of objects. For example, my game renders about 50 objects, each with approximately 2000 vertices and this will consume gigabytes of memory. So unless you enjoy trying to end tasks while your Mac is completely unresponsive, hide all but the objects that you are investigating. On the Apple Developer Forums, I was told that this issue has been improved in Xcode 4.3.
- Group your commands. There’s a handy debug extension you can call to mark the start and end of a group of rendering commands. Rendering a single primitive like a triangle strip, even if it is one object, involves setting a lot of attributes and uniforms and possibly changing blend modes. You can group all these commands together in the debugger by first calling glPushGroupMarkerEXT(0,”Name”) before issuing the commands and then glPopGroupMarkerEXT() after. You can also group objects together in the same way to create a hierarchy in the tool’s interface.
- Label your resources. When you create a texture or vertex buffer, you can attach a friendly name to it so that it doesn’t appear as “Texture #28.” This is done using the glLabelObjectEXT()function. Here’s how to do it for a texture:
glLabelObjectEXT(GL_TEXTURE, texture.glid, 0, texture.name)
where texture.glid is the GL texture identifier returned from glGenTextures() and texture.name is a null-terminated char string. One important tip here is that you can’t call this until you’ve actually created your texture using glTexImage2D(). Otherwise you’ll get an error returned.