I'm working on an iPad app that displays lightmapped scenes. Loading the 20 or so 1Kx1K textures that are involved is taking a while, and when I started timing the various operations I found it was taking slightly less than 1/2 second per texture.
It turns out that loading a texture image from the filesystem is pretty fast, and that the bottleneck is in copying the UIImage
to a CGContext
in order to pass the image to a glTexImage2D()
I've tried two different ways of making the copy:
CGContextSetInterpolationQuality(textureCopyContext, kCGInterpolationNone);
CGContextDrawImage( textureCopyContext, CGRectMake( 0, 0, width, height ), image);
and
UIGraphicsPushContext(textureCopyContext) ;
[uiImage drawInRect:CGRectMake(0, 0, width, height)] ;
UIGraphicsPopContext() ;
and both take about 0.45 seconds. This strikes me as excessive, even for a relatively underpowered device.
I'm relatively new to iOS development, so I just want to ask whether the times I'm seeing are reasonable, or whether they can be improved.
Update: I'm aware of the PVRTC alternative, but for now I've got to stick with PNGs. However, there is an excellent summary of the pros and cons of PVRTC in this answer. The same answer also hints at why PNGs result in such long texture setup times -- "internal pixel reordering". Can anybody confirm this?