IT story

Android OpenGL 텍스처 압축

hot-time 2021. 1. 7. 20:00
반응형

Android OpenGL 텍스처 압축


Android에서 텍스처 압축을 사용하는 방법에 대한 정보 (또는 예)를 찾는 데 도움이 필요합니다. 나는 지금 많은 PNG를 가지고 있고 그들이 차지하는 메모리 양을 줄여야합니다. PVR 압축을보고 있었지만 OpenGL 내에서 이것을 사용하는 방법을 알 수 없습니다.

어떤 사람은 나를 올바른 방향으로 안내하거나 아무것도 찾을 수 없기 때문에 몇 가지 예를 제시 할 수 있습니다.


Android에서 지원되는 주로 네 가지 텍스처 압축 유형이 있습니다.

  • ETC1 (Ericsson 텍스처 압축) . 이 형식은 모든 Android 휴대폰에서 지원됩니다. 그러나 알파 채널을 지원하지 않으므로 불투명 텍스처에만 사용할 수 있습니다.
  • PVRTC (PowerVR 텍스처 압축) . PowerVR GPU (Nexus S, Kindle fire 등)가있는 장치에서 지원됩니다.
  • ATITC (ATI 텍스처 압축) . Qualcomm (Nexus One 등)의 Adreno GPU가있는 기기에서 사용됩니다.
  • S3TC (S3 텍스처 압축) . 이 텍스처 압축은 NVIDIA 칩셋 통합 장치 (Motorola Xoom 등)에서 사용됩니다.

여기여기에 더 자세한 정보가 있습니다 .

즉, 텍스처에 알파가 없으면 ETC1을 사용할 수 있습니다. 알파가 있고 모든 장치를 지원하려면 다른 세 가지 유형으로 텍스처를 압축하고 장치에 따라로드해야합니다.

사용하는 방법:

  1. png 파일을 압축 하고 ( 텍스처 유형에 따라 ETC-Pack , PVRTexTool , ATI Compressonator , Nvidia Texure Tools 와 같은 도구를 사용할 수 있음 ) 프로젝트 자산에 추가합니다.

  2. 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. 압축 된 텍스처를 원시 데이터로로드합니다.

  4. glTexImage2D 대신 glCompressedTexImage2D를 사용합니다.

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

이것은 ol 스레드이므로 http://devtools.ericsson.com/etc에서 사용할 수있는 정보로 업데이트 할 것이라고 생각했습니다. ETC2는 Khronos 표준 OpenGL ES 3.0 및 OpenGL 4.3에서 필수입니다.


You should not use just PVR compression on Android, since that will not work with all models. To get around that you should either only use ETC1 (mandated on all GLES 2.0 devices) or have separate texture packs for separate GPU modes. The android dev guide has a helper class to load the compression format.

You can use etcpack to do compression.

Note that you will not get an alpha channel with ETC1 - you can do some fancy fragment shading tricks to get around that by having the alpha channel as a separate texture.


Just wanted to point out etc1 isn't supported by all android devices, contrary to what gergonzalez said

Caution: The ETC1 format is supported by most Android devices, but it not guaranteed to be available. To check if the ETC1 format is supported on a device, call the ETC1Util.isETC1Supported() method.

https://developer.android.com/guide/topics/graphics/opengl.html#textures

ReferenceURL : https://stackoverflow.com/questions/9148795/android-opengl-texture-compression

반응형