Phantom Functions

June 10, 2009 · Posted in dev 

Not that they’re very spooky, but function calls that don’t do anything can be a real time-sink. The call in question: glPolygonOffset(), a terribly useful function which I was using to prevent Z-fighting. Everything worked as expected in the iPhone simulator, but nothing happened when run from the real hardware! After an hour of searching through the code and documentation, it turns out the answer is pretty straightforward: polygon offset is not supported by the hardware.

The fact that the compiler didn’t kick out a warning or error would seem to suggest that the feature is available in later models. My test platform uses PowerVR’s MBX Lite 3D GPU, as do all models up until Monday’s announcement. Still, Apple is able to tailor the SDK’s header files exactly to their devices capabilities, so it’s a touch frustrating. On the bright side, there’s a workaround for coders who needed glPolygonOffset to draw edge geometry:

        #define EDGE_OFFSET 0.00001

        glDepthRange(EDGE_OFFSET, 1.0);
        /* draw all non-edge geometry */

        glDepthRange(0.0, 1.0 - EDGE_OFFSET);
        /* draw all edges */

There’s a couple more good ideas actually, but the above code works fine for a low-power device.

Comments

Leave a Reply