Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Maximum OpenGL ES 2.0 Texture Size Limit in Android

I am trying to get the maximum texture size limit in Android for OpenGL 2.0. But I've found that the next instruction only works if I'm currently within the OpenGL Context, in other words I must have a GL Surface and a GL Renderer, etc, which I don't want.

int[] maxTextureSize = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);

So I came with the next algorithm, which gives me the maximum texture size without having to create any surface or renderer. It works correctly, so my question is if this will work with all Android devices, and if anyone can spot any bug, just in case.

public int getMaximumTextureSize()
{
    EGL10 egl = (EGL10)EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++)
    {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
        {
            maximumTextureSize = textureSize[0];
        }

        Log.i("GLHelper", Integer.toString(textureSize[0]));
    }

    // Release
    egl.eglTerminate(display);
    Log.i("GLHelper", "Maximum GL texture size: " + Integer.toString(maximumTextureSize));

    return maximumTextureSize;

}
like image 631
PerracoLabs Avatar asked Jun 13 '12 19:06

PerracoLabs


1 Answers

PBUFFER max size is unfortunately not related to max texture size (but may be the same).

I believe the best way to obtain max texture size is to create GL context (on the same context as one on which You will actually use this textures) and ask for GL_MAX_TEXTURE_SIZE.

There is strong reason behind this: the ogl driver is not initialized for current process before surface (and context) creation. Some drivers perform underlying HW/SKU detection on initialization and calculate max surface sizes depending on HW capabilities.

Furthermore, max texture size is permitted to vary depending on context (and EGLConfig context was created on).

And one more thing: eglGetConfigs will get You all EGLconfigs, even these from default, software android renderer, or theese from OpenGL ES 1.1CM HW driver (if there are separate drivers for 1.1 and 2.0 on target platform). Drivers are sort of independent in graphics stack and can return different max-es.

like image 105
sacygan Avatar answered Nov 04 '22 04:11

sacygan