简体   繁体   English

减少OpenGL ES 1.1中纹理的内存使用

[英]Reduce memory use for textures in OpenGL ES 1.1

My scene in OpenGL ES requires several large resolution textures, but they are grayscale, since I am using them just for masks. 我在OpenGL ES中的场景需要几个大分辨率纹理,但它们是灰度的,因为我只是将它们用于蒙版。 I need to reduce my memory use. 我需要减少我的记忆力。

I have tried loading these textures with Bitmap.Config.ALPHA_8, and as RGB_565. 我尝试使用Bitmap.Config.ALPHA_8和RGB_565加载这些纹理。 ALPHA_8 seems to actually increase memory use. ALPHA_8似乎实际上增加了内存使用。

Is there some way to get a texture loaded into OpenGL and have it use less than 16bits per pixel? 是否有某种方法可以将纹理加载到OpenGL中并使其每像素使用少于16位?

glCompressedTexImage2D looks like it might be promising, but from what I can tell, different phones offer different texture compression methods. glCompressedTexImage2D看起来很有希望,但据我所知,不同的手机提供不同的纹理压缩方法。 Also, I don't know if the compression actually reduces memory use at runtime. 此外,我不知道压缩是否实际上减少了运行时的内存使用。 Is the solution to store my textures in both ATITC and PVRTC formats? 解决方案是以ATITC和PVRTC格式存储我的纹理吗? If so, how do I detect which format is supported by the device? 如果是这样,我如何检测设备支持哪种格式?

Thanks! 谢谢!

PVRTC, ATITC, S3TC and so forth, the GPU native compressed texture should reduce memory usage and improve rendering performance. PVRTC,ATITC,S3TC等,GPU原生压缩纹理应该减少内存使用并提高渲染性能。

For example (sorry in C, you can implement it as using GL11.glGetString in Java), 例如(抱歉在C中,您可以在Java中使用GL11.glGetString实现它),

const char *extensions = glGetString(GL_EXTENSIONS);
int isPVRTCsupported = strstr(extensions, "GL_IMG_texture_compression_pvrtc") != 0;
int isATITCsupported = strstr(extensions, "GL_ATI_texture_compression_atitc") != 0;
int isS3TCsupported = strstr(extensions, "GL_EXT_texture_compression_s3tc") != 0;

if (isPVRTCsupportd) {
    /* load PVRTC texture using glCompressedTexImage2D */
} else if (isATITCsupported) {
...

Besides you can specify supported devices using texture format in AndroidManifest.xml. 此外,您可以在AndroidManifest.xml中使用纹理格式指定支持的设备。

EDIT : 编辑

With Imagination Technologies-based (aka PowerVR) systems, you should be able to use PVRTC 4bpp and (depending on the texture and quality requirements) maybe even 2bpp PVRTC variant. 使用基于Imagination Technologies(又名PowerVR)的系统,您应该能够使用PVRTC 4bpp和(取决于纹理和质量要求)甚至2bpp PVRTC变体。

Also, though I'm not sure what is exposed in Android systems, the PVRTextool lists I8 (ie greyscale 8bpp) as target texture format, which would give you a lossless option. 此外,虽然我不确定在Android系统中暴露了什么,但PVRTextool将I8(即灰度8bpp)列为目标纹理格式,这将为您提供无损选项。

Android 2.2及更高版本的所有Android设备均支持ETC1纹理压缩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM