More geeking out about iPhone game programming and textures. The version of the texture tool provided with the iPhone sdk outputs a compressed texture with absolutely no header information. The lack of header forces your code to know the details like width, height, bitdepth, and pixel format instead of it being nicely encapsulated in the file itself. This causes you to have to hardcode this data into your texture load calls and just makes for all around ugliness. I’ve since tossed out Apple’s version of the tool and started using the version that comes with the PowerVR sdk. While I have to do my conversions under Windows, it allows my code to be more generic in the way that it handles textures. I read in the first 52 bytes of the file to get all the information I need and then pass along the rest to OpenGL to drop into VRAM.
Here’s a small code snippet of what I’m now doing in my texture code.
unsigned int dwHeaderSize; /*!< size of the structure */
unsigned int dwHeight; /*!< height of surface to be created */
unsigned int dwWidth; /*!< width of input surface */
unsigned int dwMipMapCount; /*!< number of mip-map levels requested */
unsigned int dwpfFlags; /*!< pixel format flags */
unsigned int dwTextureDataSize; /*!< Total size in bytes */
unsigned int dwBitCount; /*!< number of bits per pixel */
unsigned int dwRBitMask; /*!< mask for red bit */
unsigned int dwGBitMask; /*!< mask for green bits */
unsigned int dwBBitMask; /*!< mask for blue bits */
unsigned int dwAlphaBitMask; /*!< mask for alpha channel */
unsigned int dwPVR; /*!< magic number identifying pvr file */
unsigned int dwNumSurfs; /*!< the number of surfaces present in the pvr */
NSData *fileContents = [[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:filename]] retain];
if (fileContents == nil)
// pointer to the actual pvr image data, skip the header
char *pvrData = (char*)[fileContents bytes] + sizeof(PVR_Texture_Header);
// create the header and copy in the data from the file
memcpy(&textureInfo, [fileContents bytes], sizeof(PVR_Texture_Header));
The definition for the PVR_Texture_Header was found in the PowerVR SDK.