3

My scene in OpenGL ES requires several large resolution textures, but they are grayscale, since I am using them just for masks. I need to reduce my memory use.

I have tried loading these textures with Bitmap.Config.ALPHA_8, and as RGB_565. ALPHA_8 seems to actually increase memory use.

Is there some way to get a texture loaded into OpenGL and have it use less than 16bits per pixel?

glCompressedTexImage2D looks like it might be promising, but from what I can tell, different phones offer different texture compression methods. Also, I don't know if the compression actually reduces memory use at runtime. Is the solution to store my textures in both ATITC and PVRTC formats? If so, how do I detect which format is supported by the device?

Thanks!

Tenfour04
  • 83,111
  • 11
  • 94
  • 154

3 Answers3

10

PVRTC, ATITC, S3TC and so forth, the GPU native compressed texture should reduce memory usage and improve rendering performance.

For example (sorry in C, you can implement it as using GL11.glGetString in Java),

const char *extensions = glGetString(GL_EXTENSIONS);
int isPVRTCsupported = strstr(extensions, "GL_IMG_texture_compression_pvrtc") != 0;
int isATITCsupported = strstr(extensions, "GL_ATI_texture_compression_atitc") != 0;
int isS3TCsupported = strstr(extensions, "GL_EXT_texture_compression_s3tc") != 0;

if (isPVRTCsupportd) {
    /* load PVRTC texture using glCompressedTexImage2D */
} else if (isATITCsupported) {
...

Besides you can specify supported devices using texture format in AndroidManifest.xml.

EDIT:

Kazuki Sakamoto
  • 13,929
  • 2
  • 34
  • 96
  • 1
    Is there a way to load a bitmap and compress it at runtime so I don't have to have multiple copies of the images in different formats? I can't find any documentation on the ATITC format. – Tenfour04 Mar 09 '11 at 11:49
  • 1
    For S3TC, you may be able to use [libsquish](http://code.google.com/p/libsquish/). But, AFAIK, Imagination Technologies and AMD provides only compression library binary for windows and so forth. – Kazuki Sakamoto Mar 09 '11 at 12:36
  • Is there a way to extract dimensions and format from a file compressed in one of those formats, or do I need to store that in my metadata somewhere? – EboMike Mar 16 '11 at 08:16
  • 1
    PVRTC is usually used with PVR texture format that includes the metadata of the texture. And, PVR texture format is open, it would be helpful if you modify to support S3Tc or ATITC format. Please refer to [PVRTexTool](http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp). – Kazuki Sakamoto Mar 16 '11 at 12:52
  • NOTE: The Thunderbolt (and maybe other Adreno phones) uses GL_AMD_compressed_ATC for ATITC. – EboMike Mar 18 '11 at 16:01
2

With Imagination Technologies-based (aka PowerVR) systems, you should be able to use PVRTC 4bpp and (depending on the texture and quality requirements) maybe even 2bpp PVRTC variant.

Also, though I'm not sure what is exposed in Android systems, the PVRTextool lists I8 (i.e. greyscale 8bpp) as target texture format, which would give you a lossless option.

Simon F
  • 1,036
  • 8
  • 23
1

ETC1 texture compression is supported on all Android devices with Android 2.2 and up.

keaukraine
  • 5,315
  • 29
  • 54