Just a quick blog if you are working on OpenGL Texture compression in Android ES2. I’ve been busy lately, so I can’t take the time to do a complete tutorial, but I think these links will help.
While attempting to improve my texture loading, I came across something that was easy but maybe a little hard to find. I noticed that ETC1 is supported (perhaps mandatory in ES2, i’m not 100% sure). I found ETC1 utilities inside the SDK, ok great! I read the example CompressedTextureActivity from Google, but I didn’t know how to create the texture from my existing png’s which were originally Bitmaps in my original code.
After searching for a way to convert PNG’s to etc1 format quickly, I found this in the Android source tree.
out/host/linux-x86/bin usage: ./etc1tool infile [--help | --encode | --encodeNoHeader | --decode] [--showDifference difffile] [-o outfile] Default is --encode --help print this usage information. --encode create an ETC1 file from a PNG file. --encodeNoHeader create a raw ETC1 data file (without a header) from a PNG file. --decode create a PNG file from an ETC1 file. --showDifference difffile Write difference between original and encoded image to difffile. (Only valid when encoding). If outfile is not specified, an outfile path is constructed from infile, with the apropriate suffix (.pkm or .png).
For me, this etc1tool was the missing piece of information to do this quickly. Now, after you convert you textures from png to this pkm format. You can use:
ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, input);
Just add this pkm file into your res/raw directory, and use standard java to hand it an inputstream (see the Google example for a full example):
InputStream input = getResources().openRawResource(R.raw.androids);
The result is that my texture loading went from 9ms -> 1-2ms (your results may vary). Now after all this, I should tell you that you cannot use ETC1 for textures that have alpha channels! For this, you may need to use the various proprietary GPU formats. This is ugly, because Android is based on at least a few chipsets, and we would need to write way more code to address all possible GPU’s. If anyone has any recommendations on a way to do compression with alpha layer in Android, i’m all ears.
I hope you find this useful, if not let me know if I need to explain more details.
Marcus
here is an article on how to use alpha by combining 2 ETC1 texture and a fragment shader.
http://blog.tewdew.com/post/7362195285/the-android-texture-decision
Thanks for the info. I have been trying to get compressed textures running on android for about 5 days. I need to have alpha channels, so I focused on DXT5 and PVR. Unfortunately I could not find a single example or document on the usage of glCompressedTexImage2D with these compression formats in java. I did get code that would run, but the best I could do was a white rectangle.
Using your examples, ETC worked the first time. Unfortunately I need alpha.
If you are aware of any code or documentation that show functional display of DXT or PVR files, please post this.
Thanks in advance
RaiderJ
I’m looking for pkm document, and watch this page, thank you very much, it’s useful for me.