在Android中获取最大OpenGL ES 2.0纹理大小限制

时间:2012-06-13 19:36:08

标签: android opengl-es textures

我试图在Android for OpenGL 2.0中获得最大的纹理大小限制。 但是我发现只有当我在OpenGL上下文中时,下一条指令才有效,换句话说我必须有GL Surface和GL Renderer等,这是我不想要的。

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

所以我选择了下一个算法,它为我提供了最大的纹理大小,而无需创建任何表面或渲染器。 它工作正常,所以我的问题是,这是否适用于所有Android设备,如果有人能发现任何错误,以防万一。

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;

}

1 个答案:

答案 0 :(得分:6)

遗憾的是,PBUFFER最大尺寸与最大纹理尺寸无关(但可能相同)。

我认为获得最大纹理大小的最佳方法是创建GL上下文(与实际使用此纹理的上下文相同)并请求GL_MAX_TEXTURE_SIZE。

这背后有充分的理由:在创建表面(和上下文)之前,不会为当前进程初始化ogl驱动程序。某些驱动程序在初始化时执行基础HW / SKU检测,并​​根据硬件功能计算最大表面大小。

此外,允许最大纹理大小取决于上下文(并且创建了EGLConfig上下文)。

还有一件事:eglGetConfigs将获得所有EGLconfigs,即使这些来自默认的软件android渲染器,或来自OpenGL ES 1.1CM HW驱动程序(如果在目标平台上有1.1和2.0的单独驱动程序)。驱动程序在图形堆栈中是独立的,可以返回不同的max-es。