I need some help finding information (or an example) of how to use texture compression for Android. I have a lot of PNG's right now and I need to reduce the amount of memory they take up. I was looking at PVR compression but I can't figure out how to use this within OpenGL.
Could some point me in the right direction or offer some examples as I cannot find anything.
The Adaptive Scalable Texture Compression (ASTC) format offers advantages, such as improved rendering performance, faster load times, a smaller in-memory footprint, better battery life, and improved visual quality.
Texture size should not have any effect on the performance. Texture compression can have a positive impact - the less space a block occupies in memory, the more blocks can be cached at the same time.
Texture compression is a specialized form of image compression designed for storing texture maps in 3D computer graphics rendering systems. Unlike conventional image compression algorithms, texture compression algorithms are optimized for random access.
There are mainly four texture compression types supported on Android:
More detailed information here and here.
In short, if your textures don't have alpha, you can use ETC1. If they do have alpha, and you want to support all devices, you must have your textures compressed in the other three types and load them according to the device.
How to use:
Compress your png files (You can use a tool like ETC-Pack, PVRTexTool, ATI Compressonator, Nvidia Texure Tools according to the type of texture) and add to your project assets.
Determine which extensions are available in the device, if you're not using ETC1:
public void onSurfaceCreated(GL10 gl, EGLConfig config) { String s = gl.glGetString(GL10.GL_EXTENSIONS); if (s.contains("GL_IMG_texture_compression_pvrtc")){ //Use PVR compressed textures }else if (s.contains("GL_AMD_compressed_ATC_texture") || s.contains("GL_ATI_texture_compression_atitc")){ //Load ATI Textures }else if (s.contains("GL_OES_texture_compression_S3TC") || s.contains("GL_EXT_texture_compression_s3tc")){ //Use DTX Textures }else{ //Handle no texture compression founded. } }
Load compressed texture as raw data.
Use glCompressedTexImage2D instead of glTexImage2D:
public void onDrawFrame(GL10 gl) { .... gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, level, internalformat, width, height, border, imageSize, data); }
This is an ol thread, so I thought I'd update it with the information available on http://devtools.ericsson.com/etc ETC2 is mandatory in the Khronos standards OpenGL ES 3.0 and OpenGL 4.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With