views:

2110

answers:

3

Hello! Can I get paletted textures with RGB palette and 8-bit alpha channel in OpenGL ES? (I am targetting the iPhone OpenGL ES implementation.) After peeking into the OpenGL documentation it seems to me that there is support for paletted textures with alpha in the palette, ie. the texture contains 8-bit indexes into a palette with 256 RGBA colors. I would like a texture that contains 8-bit indexes into an RGB palette and a standalone 8-bit alpha channel. (I am trying to save memory and 32-bit RGBA textures are quite a luxury.) Or is this supposed to be done by hand, ie. by creating two independent textures, one for the colors and one for the alpha map, and combining them manually?

+1  A: 

Disclaimer: This info is based on the official OpenGL|ES spec. I have no idea of the OpenGL|ES implementation on the iphone supports compressed textures or not. In theory it should at least simulate compressed textures, but you'll never now.

You can load 8 bits/pixel textures via the glCompressedTexImage2D call. The compression type you most likey want to use is GL_PALETTE8_RGBA8_OES.

Storing an additional alpha-channel along with the palette is not directly possible. Either you use the second texture unit for the alpha-component, or you take the alpha during color quantization into account and use a palettized format that contains alpha.

There is a command-line color quantization tool called BRIGHT out there somewhere on the net. It does an incredible job at quantizing images with alpha. You may want to give it a try..

Nils Pipenbrinck
+2  A: 

No. In general, graphics chips really don't like palletized textures (why? because reading any texel from it requires two memory reads, one of the index and another into the palette. Double the latency of a normal read).

If you're only after saving memory, then look into compressed texture formats. In iPhone specifically, it supports PVRTC compressed formats with 2 bits/pixel and 4 bits/pixel. The compression is lossy (just like palette compression is often lossy), but memory and bandwidth savings are substantial.

NeARAZ
Thanks! I am aware of the texture compression, but alas the compression artifacts are too visible for my purposes (this is a cartoonish 2D game).
zoul
+1  A: 

Palette textures will be expanded on load for the GPU in the iPhone so you won't gain any advantage by using them other than storage size. Your best bet for a cartoon style game is to explore using PVRTC compressed textures (like NeARAZ says) and 16-bit textures (RGBA4444 for alpha, RGBA5551 for punch-through, RGB565 for opaque textures). Using a mixture of both is my own approach.

gmaclachlan
Hi. I'm sorry but what do you mean with punch-trough ?. And can you point me to any tutorial or resource regarding using RGBA4444 ( since i only have sprite sheets in RGBA8888 and it's too muchburden to the iphone's memory)
José Joel.
By "punch-through" I mean that all the pixels in your sprite image are either fully-opaque or fully transparent, there are no semi-transparent pixels. This can be represented by the single bit for alpha that's available using RGBA5551 - alpha is either on or of.There's texture loading code available in the POWERVR SDK and Oolong engine that will load thee different formats. To create the textures you can use PVRTexTool from the SDK as well. Once a 16bit texture is loaded it is treated like any other OpenGL texture so there should be no need to change your rendering code.
gmaclachlan