本文介绍了Android OpenGL:是否可能内存不足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数周以来,我一直在尝试解决此问题,但现在我不知道该怎么办.

I have been trying to fix this issue for weeks but I'm at the point where I dont know what to do now.

我认为某些Android设备没有足够的内存来加载大量纹理,尽管这可能是导致该问题的其他原因,正如我说的那样,我真的不知道该怎么办.

I think that some Android devices dont have enough memory to load the amount of textures, although it could be something else causing the issue, as I said I really dont know what to do with this.

总共有1024个1024x1024加载了28个PNG,总计4.8megs.下面是用于加载纹理的OpenGL方法

There are 28 PNG's being loaded all 1024x1024 which come to a total of 4.8megs. Below is the OpenGL method for loading textures

    GL10 gl = glGraphics.getGL();
    int[] textureIds = new int[1];
    gl.glGenTextures(1, textureIds, 0);
    textureId = textureIds[0];

    InputStream in = null;
    try {
        in = fileIO.readAsset(fileName);
        Bitmap bitmap = BitmapFactory.decodeStream(in);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        setFilters(GL10.GL_LINEAR , GL10.GL_LINEAR);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        width = bitmap.getWidth();
        height = bitmap.getHeight();
        bitmap.recycle();
    } catch(IOException e) {
        throw new RuntimeException("Couldn't load texture '" + fileName +"'", e);
    } finally {
        if(in != null)
            try { in.close(); } catch (IOException e) { }
    }

Desire HD上没有问题,但是在HTC Cha Cha上根本没有出现很多纹理,而在Galaxy S上,两个纹理只是显示为白色.加载纹理时Cha Cha抛出此错误

There are no issues on my Desire HD, but on a HTC Cha Cha a lot of textures dont appear at all and on a Galaxy S two textures just appear white. The Cha Cha throws this error while loading textures

奇怪的是,如果Cha Cha被锁定(OpenGL纹理被破坏)然后解锁(重新加载的纹理),则最初不存在的特定纹理现在已经存在,但是现在不可见不同的纹理.

Oddly if the Cha Cha is locked (OpenGL textures are destroyed) and then unlocked (reloaded textures) the particular textures that were not there initally are now, however different textures are now not visable.

这是一个内存问题吗?如果可以的话,有办法解决吗?

Is this a memory issue? If so is there a way around this?

谢谢

推荐答案

正确的解决方案是纹理压缩,而不是PNG压缩. PVR-TC 可以满足您的大部分需求.在4-bpp时,您将减少到12MB,而不是117MB.即使仅使用较低位深度的图像(例如RGB-565格式)(每像素16位)也可以将您的需求减少一半.

The correct solution is texture compression, not PNG compression. PVR-TC would get you most of what you need. At 4-bpp, you'd go down to 12MB instead of 117MB. Even just using lower bitdepth images, like RGB-565 formats, (16-bits per pixel) would cut your needs in half.

此外,您不必为手机使用1024x1024纹理;那是一种过分的杀伤力.您可能可以获得512x512的图像.结合PVR-TC,所有这些纹理数据只需约3MB.

Also, you don't have to use 1024x1024 textures for phones; that's kind of overkill. You could probably get away with 512x512 images. Coupled with PVR-TC, you'd only need about 3MB for all of that texture data.

这篇关于Android OpenGL:是否可能内存不足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 03:49