Android OpenGL 纹理压缩

发布于 2025-01-03 04:27:18 字数 146 浏览 2 评论 0原文

我需要一些帮助来查找有关如何在 Android 上使用纹理压缩的信息(或示例)。我现在有很多 PNG,我需要减少它们占用的内存量。我正在研究 PVR 压缩,但我不知道如何在 OpenGL 中使用它。

有人可以指出我正确的方向或提供一些例子,因为我找不到任何东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恍梦境° 2025-01-10 04:27:18

Android 主要支持四种纹理压缩类型:

  • ETC1(爱立信纹理压缩)。所有 Android 手机都支持此格式。但是,它不支持 Alpha 通道,因此只能用于不透明纹理。
  • PVRTC(PowerVR 纹理压缩)。受具有 PowerVR GPU 的设备(Nexus S、Kindle fire 等)支持。
  • ATITC(ATI 纹理压缩)。用于配备 Qualcomm Adreno GPU 的设备(Nexus One 等)。
  • S3TC(S3纹理压缩)。这种纹理压缩用于 NVIDIA 芯片组集成设备(Motorola Xoom 等)。

更详细的信息 此处此处

简而言之,如果你的纹理没有 Alpha,你可以使用 ETC1。如果它们确实有 Alpha,并且您想支持所有设备,则必须以其他三种类型压缩纹理并根据设备加载它们。

如何使用:

  1. 压缩您的png文件(您可以使用ETC-Pack等工具,< a href="http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp" rel="noreferrer">PVRTexTool, ATI 压缩器Nvidia Texure Tools 根据纹理类型)并添加到您的项目资源中。

  2. 如果您不使用 ETC1,请确定设备中可用的扩展:

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    
         字符串 s = gl.glGetString(GL10.GL_EXTENSIONS);
    
         if (s.contains("GL_IMG_texture_compression_pvrtc")){
              //使用PVR压缩纹理         
         }else if (s.contains("GL_AMD_compressed_ATC_texture") ||
                  s.contains(“GL_ATI_texture_compression_atitc”)){
              //加载ATI纹理           
         }else if (s.contains("GL_OES_texture_compression_S3TC") ||
                    s.contains(“GL_EXT_texture_compression_s3tc”)){
             //使用DTX纹理
         }别的{
             //处理没有建立的纹理压缩。               
         }
    
    }           
    
  3. 将压缩纹理加载为原始数据。

  4. 使用glCompressedTexImage2D代替glTexImage2D:

    public void onDrawFrame(GL10 gl) {
    
       ....
    
       gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, 级别, 内部格式, 宽度, 
                                 高度、边框、图像大小、数据);
    
    }
    

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);
    
    }
    
寂寞清仓 2025-01-10 04:27:18

这是一个 ol 线程,所以我想我应该使用 http://devtools.ericsson 上提供的信息来更新它。 com/etc
ETC2 在 Khronos 标准 OpenGL ES 3.0 和 OpenGL 4.3 中是强制性的。

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.

我也只是我 2025-01-10 04:27:18

您不应该在 Android 上仅使用 PVR 压缩,因为这并不适用于所有型号。为了解决这个问题,您应该只使用 ETC1(在所有 GLES 2.0 设备上强制)或为单独的 GPU 模式使用单独的纹理包。 android 开发指南 有一个辅助类来加载压缩格式。

您可以使用 etcpack 进行压缩。

请注意,您不会使用 ETC1 获得 Alpha 通道 - 您可以通过将 Alpha 通道作为单独的纹理来执行一些奇特的片段着色技巧来解决这个问题。

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.

萌面超妹 2025-01-10 04:27:18

只是想指出并非所有 Android 设备都支持 etc1,这与 gergonzalez 所说的相反

注意:大多数 Android 设备都支持 ETC1 格式,但不保证可用。要检查设备是否支持 ETC1 格式,请调用 ETC1Util.isETC1Supported() 方法。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文