Game Development Community

Use Apple's utility for PowerVR compressed textures

by Mat Valadez · in iTorque 2D · 12/23/2008 (2:46 pm) · 12 replies

Apple ships a command-line tool for generating PowerVR compressed textures from PNG files with the iPhone SDK. The PVRTC files you create using this tool can be used directly with Torque, dramatically reducing texture memory usage. By default, the tool is installed to this path: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool

For full usage information, run the tool without arguments. To generate a file that can be used with Torque, you must pass at least the following arguments:

texturetool -e PVRTC -o -f PVR

...where is the name of the file to be generated (which should have the ".pvr" extension) and is the image file you wish to convert. This will generate a compressed texture using four bits per pixel with no mipmaps. To generate a texture with two bits per pixel, pass "--bits-per-pixel-2". To generate a complete set of mipmaps, pass "-m".

Be sure to include the "-f PVR" argument; otherwise, texturetool will output the raw compressed texture data without any header information. Torque uses the header to determine attributes such as the dimensions and format of the compressed texture.

The texture must be square, with power-of-two dimensions. Non-square textures will not work.

For complete usage information, run texturetool without arguments. For more information about compressed textures, consult the PowerVR SDK for OpenGL ES 1.x, available at: http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES1xMBX.asp

#1
12/24/2008 (7:46 am)
Mat,
When I use power of two textures with filtering and padding, they end up taking twice the memory (because of the padding). So usually I resize them to 126*126 or 62*62 and that seems to work great. With the PVR textures, can I use square textures that are not power of 2?
#2
12/25/2008 (12:28 pm)
IPhone only accepts power of two AND square textures.
That means textures must be 64x64, 128x128, 256x256, 512x512 or 1024x1024
that are the only supported sizes on the iphone
#3
12/26/2008 (6:41 pm)
I think what Marc means is that PVRTC textures must be square and power of 2 dimensions. PNGs can be any size or ratio, and will get get auto-sized up to the next power of 2.
#4
12/27/2008 (4:50 am)
Well you can use whatever you want. but above are the only texture sizes that are allowed on the iphone so iTGB will resize / pack them to meet that.
The iphone does NOT accept any texture not meeting those requirements, independent if compressed or not.
#5
01/09/2009 (1:14 pm)
What PVR format can you use to encode png's with alpha? 4bpp and 2bpp doesn't work for alpha, right?
#6
01/09/2009 (1:15 pm)
If I use any of the 16bit pvr's they seem to generate bigger files than the .png
#7
01/09/2009 (3:54 pm)
So I was able to use the cmd line tool to convert my png to pvr.
However, I can't load it in the editor. even when I edit the datablocks.cs and start the editor. it doesn't seem to like it.
Is there any example of a pvr file or what it should look like in datablocks.cs?
#8
01/09/2009 (11:48 pm)
ITGB is set to look for PVR textures first. Here's what I would do.

Use a regular PNG, in the datablock, don't include the extension. e.g.

new t2dImageMapDatablock(SomeImageMap) {
      imageName = "~/data/images/Actor/SomeImage";
      ...
  }

Then create the PVR with the same name

on your non-iPhone build it'll load the PNG, but on the iPhone, it'll load you PVR first so you.

Basically, just use the PNG, but make the PVR and it'll load on the iPhone without you having to "manage" it.
#9
01/10/2009 (11:09 am)
Has someone already created a small post build script that removes all png where corresponding pvr are present after the app has been built?
Doing it manually in the resources is naturally a way but one that takes pretty long.
#10
02/04/2009 (1:31 am)
@ Eyal

PVRs will generally be larger than PNGs in terms of file size, but they will take up a drastically less amount of video memory on the iPhone itself in game. When iTG* loads in any standard file format (PNG, JPG, etc.) it will uncompress them in order to store them into an OpenGL texture, which graphic cards (doesn't matter if it is an iPhone PowerVR or an ATI card on your PC, etc.) need to be in some kind of standard video format (ie 8888, 1555, paletized, DXT, etc.).

So basically, unless your image is saved in a file that uses some kind of valid texture compression format for the specified video hardware (ie. PVR, DDS, etc.), Torque will just load it as a standard, uncompressed texture for video memory storage (and ultimately video card rendering) purposes.

Bottom line is, don't be fooled by the disk size of an image and just use PVR wherever you can!
#11
02/04/2009 (7:44 am)
got ya, I see how it works.
I guess it a trade-off between using a compress file that is smaller and will help you go under 10Mb for the 3G limitation . or use PVR which will help your video memory / application crash.
Good to know.
#12
02/04/2009 (8:17 am)
you will have a hard time getting smaller files than pvr unless you want even worse quality by using jpg