compressed textures in iPhone openGL ES

After doing some research it seems the iphone supports pvrtc compressed textures in its openGL implementation. Has anyone gotten these working? I found some tools online to convert png's to pvrtc textures but I'm not sure how to take those files and read them into openGL as a texture.

Please let me know as this would save a ton of memory in my application. Right now I'm loading in PNG's at storing them as GL_RGBA internally which is very wasteful and slow to load.

iphone, Mac OS X (10.5.4)

Posted on Jul 28, 2008 8:00 PM

Reply
32 replies

Oct 9, 2008 2:02 AM in response to mazer23

Just a heads-up - when going from OS 2.0 to OS 2.1 I found that all of our non-square PVRTC textures failed to load. After going through the bug reporting process (twice!) I have been told that non-square PVRTC textures are not supported. Despite the fact that they worked perfectly on OS 2.0
I can't remember the last hardware that required square textures, it was sometime in the very early days of 3D graphics cards. Apple have not been forthcoming with reasons why this working feature should be artificially disabled.
I'm moving to palettised textures now.

Jan 28, 2009 10:52 AM in response to GaryBlue

GaryBlue wrote:
Apple have not been forthcoming with reasons why this working feature should be artificially disabled.


You can't blame Apple for this one. The PowerVR MBX Lite GPU itself only supports square PVRTC textures. It's even mentioned in the GL IMG_texture_compressionpvrtc document.

Non-square textures of other formats are still allowed, but dimensions still have to be a power of 2.

I have been told that non-square PVRTC textures are not supported. Despite the fact that they worked perfectly on OS 2.0


On the hardware, or just on the simulator?

I can't remember the last hardware that required square textures, it was sometime in the very early days of 3D graphics cards.


Welcome to the world of small, embedded computers -- reduced power consumption requirements lead to simpler hardware, which leads to a very retro experience for the programmer.

The iPhone's GPU is a lot nicer than most of the GPUs I've encountered in the world of cell phones and handheld gaming devices. The MBX Lite's HSR culls both triangles and texture fetches, and multisampling doesn't require oversized framebuffers.

Feb 8, 2009 7:20 PM in response to javaboyjunior99

Lots of useful information in this thread that helped me get texture compression working.

Just want to add some more info if people need more help:

1. Use 'texturetool' on your machine from that path "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool" to convert a regular png/jpg file into the required "pvr" format. My usage was:

texturetool -e PVRTC --bits-per-pixel-4 -p preview.png -o tex.pvr -f PVR tex_1024.png.

This uses 4-bits per pixel in the PVR file. My pvr file was down in size by a factor of 4 from the png file.

2. Make use of the very useful PVRTextureLoader sample project from the iPhone developer website to do the rest - including mipmaps !

The only other (minor) place that I got stuck was that the PVRTexture class allocates an object and gives it to you on autorelease. I forgot to retain it and it was going away after a while. Just retain it. You don't see the project retaining it because they add the object to an array - which implies a retain.

Hope all of this helps. Good luck.

Mar 23, 2009 5:40 PM in response to mazer23

Has anyone gotten alpha channels to work with pvrtc compression? I am following the apple example (linked in a previous post) and it works great with textures without alpha channels. But, those textures that do have alpha channels don't work - the texels that should be transparent come out white. Note that the preview image created with texturetool has the alpha channel set correctly, and if I use png's rather than pvrtc's, the alpha channels work correctly in my code. So something is happening with pvrtc's where I can't seem to use alpha channels in my textures. Anyone else run across this, and has anyone found a solution?

Mar 24, 2009 11:32 AM in response to gonk

ALPHA ANSWER FOUND (I hope)?!?!

Okay, the answer to my previous question is simply that I need to change my alpha-blend func from (GL_ONE, GL ONE_MINUSWHATEVER) to (GL SRCALPHA, GL ONE_MINUSWHATEVER). See, the old way of loading textures would premultiply the alphas, forcing me to have to use "GL_ONE" as the source factor in my alpha func. Loading PVRTC textures the new way does NOT premultiply alphas, hence you have to use GL SRCALPHA for your source factor.

That fixed one problem but created another - if that's all you do, the transparent areas of your textures will come out looking awful. They will look very blotchy, as another poster here described. I think I have found the solution - but it requires using PVRTexTool on windows (since I don't think apple's texturetool supports this, though I haven't checked out the lastest version of the SDK.) Anyway, in PVRTexTool, there is an option to "pre-multiply alpha" in the preprocess dialog. Doing this gets you back to the pre-multiplied case (so you have to go back to using GL_ONE as your source factor), but the transparent areas of your textures now come out looking good. (Note that I have only tested this on two textures, so YMMV.)

Message was edited by: gonk

Mar 26, 2009 8:25 PM in response to gonk

I HAD THE SAME PROBLEM!

After visiting so many forums, I thought I was the only one.
When I saw your post, I was almost in tears, and ran to my dev computer to test out the new parameters, but.. it didn't work for me.

Alpha still comes out as solid white.

I used apple's texturetool to generate my pvr data.
I used apple's PVRTextureLoader as a reference for my code.
But I can't get it to work (I got png transparency to work fine).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

compressed textures in iPhone openGL ES

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.