Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

Android OpenGL Texture Compression

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are mainly four texture compression types supported on Android:

  • ETC1 (Ericsson texture compression). This format is supported by all Android phones. But, it doesn't support an alpha channel, so can only be used for opaque textures.
  • PVRTC (PowerVR texture compression). Supported by devices with PowerVR GPUs (Nexus S, Kindle fire, etc.).
  • ATITC (ATI texture compression). Used in devices with Adreno GPU from Qualcomm (Nexus One, etc.).
  • S3TC (S3 texture compression). This texture compression is used in the NVIDIA chipset integrated devices (Motorola Xoom, etc.)

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:

  1. 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.

  2. 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.               
         }
    
    }           
    
  3. Load compressed texture as raw data.

  4. Use glCompressedTexImage2D instead of glTexImage2D:

    public void onDrawFrame(GL10 gl) {
    
       ....
    
       gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, level, internalformat, width, 
                                 height, border, imageSize, data);
    
    }
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...