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

Aug 10, 2008 1:40 PM in response to javaboyjunior99

I've only just started looking into it and nothing is working yet, but the information is there:
- to create the textures, download PVRTexTool from the powervr website. Only works with Windows/Linux so VMware is really handy here.
- For code, download oolongengine (oolongengine.com and http://code.google.com/p/oolongengine/source/checkout). By itself very interesting, but for this topic, the following file is key: Oolong Engine2/Renderer/Core/GraphicsDevice/Texture.mm.
E.g. have a look at line 423:

glCompressedTexImage2D(GL TEXTURE2D, nMIPMapLevel-nLoadFromLevel, textureFormat, nSizeX, nSizeY, 0, CompressedImageSize, theTextureToLoad);

That's as far as I've come, but with that you should be on your way.

Tom

Aug 11, 2008 9:25 AM in response to wallclimber21

Thanks Tom, can you keep us posted? I have tried the PVRTexTool but can't figure out which of the multitude of formats/command line options to use. I started with a 20K PNG file, ran it through the tool (tried pvrtc4 foramt, 4444 and 565) and ended up with a 300K file - not really compressed 🙂.

Sample code exists to load .pvr4 files into Texture2D objects in the TouchFighter demo (if you have access to the WWDC files) the only issue for me is converting my PNGs to the .pvr4 file format, again like the TouchFighter demo. I heard Apple has their own texture conversion tool but can't find any info on it. If I could convert my PNGs to the right format, I'd be done.

Thanks!

Mike

Aug 11, 2008 12:29 PM in response to MikeCahill

I don't have it running yet because I didn't try very hard. 🙂

I only used the interactive tool, where you just click on 'encode' and then have a whole bunch of options. The ones that matter are pvr 4bpp or pvr 2bpp, depending on the quality you want. The interactive tools allows you to compare between the original and compressed version. 2bpp is usually to ugly...

Be sure to compare the right file sizes:
if you have a .PNG file that compresses very well (e.g. a file with a lot of constant color regions), then the .PNG file will be smaller than the texture compressed one, but when used as a real texture, it will be stored in the iPhone uncompressed. That's that value against which you have to compare.

So just check the size of the original texture.
Say 256x256x32bpp => 256KB uncompressed
If you are converting it to a 656 texture when loading it into the iPhone, it will only take up 128KB in memory.
When using 4bbp texture compression => 32KB

Your .pvr file should be slightly larger because of the header.

If you are using mipmapping, then size will grow by 30%.

I don't have a WWDC access and I doubt it's legal to post those examples freely.

Tom

Message was edited by: wallclimber21

Message was edited by: wallclimber21

Aug 11, 2008 2:51 PM in response to wallclimber21

<snip>
Be sure to compare the right file sizes:
if you have a .PNG file that compresses very well (e.g. a file with a lot of constant color regions), then the .PNG file will be smaller than the texture compressed one, but when used as a real texture, it will be stored in the iPhone uncompressed. That's that value against which you have to compare.
</snip>

That was the piece of information I was missing, thanks a lot Tom - I think I am set from here on out.

Mike

Aug 11, 2008 9:46 PM in response to MikeCahill

A little more information - not there yet. I have compressed images with the PVRTexTool application - the resulting texture is much smaller as expected. However, the image does not display correctly.

Interesting enough, the .pvr4 files that came with the TouchFighter demo do not load or display in the PVRTextTool application. The .pvr4 files from the TF sample app do load and display in my app but my .pvr files do not load and display in the TF sample app. From this I believe my images are corrupt/incorrectly formatted.

Having been told by support at ImgTec that Apple has their own texture tool and that the output format is different to standard PVRTC format and, given the results above, I don't think I'm going to be able to use the standard PVRTextTool to convert PNG files for use on the iPhone. Either that or I am converting my images incorrectly. I've opened a developer support incident with Apple to try to get to the bottom of this.

Has anyone converted a .PNG to .PVR and got it to display on the iPhone?

Cheers

Mike

Aug 13, 2008 8:03 AM in response to javaboyjunior99

OK, I finally have this resolved.

- the PVRTextTool created .pvr files absolutely work on the iPhone however you'll have to wrote the loading code yourself or pull it from C++ examples etc.

- much easier is to use Apple's texturetool (located at /Development/platforms/iPhoneOS.platform/usr/bin) to convert your files to Apple's .pvr format (which is different to the PVRTextTool .pvr format) and use their sample Texture2D code to load the files. However you have to have access to a sample containing the full Texture2D code. The TouchFighter demo from WWDC is such a sample although I am not sure how you legally acquire this unless you attended WWDC.

My issue was that I was trying to use .pvr files created by PVRTextTool with the Apple .pvr loader - that's what didn't work. Now I have the correct .pvr format, we're in business.

Hope someone benefits from all this.

Cheers

Mike

Sep 11, 2008 8:35 AM in response to Frogblast

Lots of good info in this thread. Unfortunately, none of it has worked out for me. I've created pvr files with texturetool and loaded the raw data, and I've parsed the powervr pvr files created with their texture tool. In both cases, I get only black-ish textures. It seems that nothing I pass to glCompressedTexImage2D works properly.

Uncompressed png textures work fine with glTexImage2D.

Some of you actually have compressed textures working? I wonder what I'm missing.

Sep 18, 2008 5:49 AM in response to rubbernecker

I got the same black-ish texture problem, it was because I used mipmap generation :
glTexParameteri(GL TEXTURE2D, GL GENERATEMIPMAP, GL_FALSE);
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MINFILTER, GL_LINEAR);
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MAGFILTER, GL_LINEAR);
instead of
glTexParameteri(GL TEXTURE2D, GL GENERATEMIPMAP, GL_TRUE);
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MINFILTER, GL LINEAR_MIPMAPNEAREST);
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MAGFILTER, GL_LINEAR);

works great now. very easy to use in fact, just use raw texturetool output with
glCompressedTexImage2D(GL TEXTURE2D, 0, GL COMPRESSED_RGB_PVRTC_4BPPV1IMG,width,height, 0, compressedSize, compressedData);

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.