Posts Tagged 'CoreAnimation'

OpenGL ES + CATransform3D

Well, here’s a followup to yesterday’s post on CATransform3D: The fellow who wrote the 3D molecular visualizer Molecules that we mentioned back when it was open sourced decided to apply that work to Molecules’ rendering routines, and it worked out pretty well!

It turns out that the CATransform3D struct provided by Core Animation for doing manipulation of CALayers is identical in structure to the model view matrix in OpenGL (ES). In fact, Apple has provided us with a number of functions for manipulating this CATransform3D struct in ways that correspond to glRotate, glScale, and glTranslate calls.

This solves the biggest known problem I had with Molecules’ rendering routines: for me to do rotation and translation relative to the user’s touch input, I had to know the state of the model view matrix at all times. In the current version of the program, that means that I had to use a few glGetFloatv calls to query the current state of the model view matrix. Each of these calls halted the rendering pipeline, so I needed a way to get rid of them.

CATransform3D and its supporting functions provide the means to do that. I could keep track of the current model view matrix in a CATransform3D, perform manipulations on that structure, and just replace the OpenGL model view matrix with it every time there was a change…

…this quick set of optimizations leads to an increase of 14-25% (depending on the specific model) in the number of triangles per second that Molecules was able to push through the iPhone’s GPU. This means that on the iPhone 2.2 firmware, I’m now getting a max of 310,000 triangles per second. This is still short of the 470,000 triangles per second the iPhone is capable of under these conditions, as reported elsewhere. There’s still some room to improve, but I’m getting there.

So there you go. If you’ve got any complicated OpenGL transformations to keep track of, look into CoreAnimation!

h/t: iPhoneKicks!

Continue Reading →
1