How to determine maximum texture memory on Android OpenGL ES

后端 未结 1 1826
花落未央
花落未央 2021-02-19 06:04

I\'m writing a mixed 2D/3D game on Android and I\'m not able to determine how much texture memory I can use. Is there any way to determine maximum texture memory in OpenGL ES? <

相关标签:
1条回答
  • 2021-02-19 06:55

    It seems that you are trying to know the amout of VRAM (video RAM) available. The question has already been partially answered.

    However, the amount of VRAM does not determine how much textures will fit in it: these ones can be compressed, the amount of VRAM can change because of another app, and we don't know how much memory the video driver uses.

    Method 1

    From this topic, you can get the maximum amount of texture units; that means the max number that can be bound at the same time:

    int[] maxSize = new int[1];
    gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
    

    And from this other one, you can retrieve the max texture size:

    int[] maxNum = new int[1];
    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, maxNum, 0);
    

    So, logically, you can at least fit maxSize[0]²×maxNum[0] pixels in the VRAM without problems. Even if the VRAM runs out of space, the graphics driver will manage it for us (which may include an application crash in case of starvation).

    Anyway, you're probably not going to adjust your textures' size depending on the VRAM amount or the available pixels; it's possible but not profitable, portable and is hard to implement properly. There's a way better way to do this:

    Method 2

    99% of the time, the amout of VRAM on the graphics chip is proportional to the screen size. Thus, use the screen's DPI (ldpi, mdpi, hdpi, xhdpi) to determine which version (size) of the texture to load (experiment with different (real) devices), so you're safe about the "will it fit for that device?".

    0 讨论(0)
提交回复
热议问题