获取Android的最大的OpenGL ES 2.0纹理大小限制纹理、大小、最大、Android

2023-09-04 11:41:04 作者:执笔画卿颜

我想获得最大纹理大小限制在Android中的OpenGL 2.0。 但我发现,下一条指令只能如果我现在是OpenGL的语境中,换句话说,我必须有一个GL表面和GL渲染引擎等,这是我不想要的。

  INT [] maxTextureSize =新INT [1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE,maxTextureSize,0);
 

于是我来到下一个算法,这给了我最大纹理大小,而无需创建任何表面或渲染器。 它正常工作,所以我的问题是,这是否会与所有的Andr​​oid设备的工作,如果任何人都可以发现任何错误,以防万一。

 公众诠释getMaximumTextureSize()
{
    EGL10 EGL =(EGL10)EGLContext.getEGL();
    EGLDisplay显示= egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    //初始化
    INT []版本=新INT [2];
    egl.eglInitialize(显示器,版本);

    配置//查询总数
    INT [] totalConfigurations =新INT [1];
    egl.eglGetConfigs(显示器,NULL,0,totalConfigurations);

    //查询实际列表配置
    EGLConfig [] configurationsList =新EGLConfig [totalConfigurations [0];
    egl.eglGetConfigs(显示器,configurationsList,totalConfigurations [0],totalConfigurations);

    INT [] textureSize =新INT [1];
    INT maximumTextureSize = 0;

    //通过所有的配置迭代到位于最大纹理尺寸
    的for(int i = 0; I< totalConfigurations [0];我++)
    {
        //只需要检查的宽度,因为OpenGL的纹理总是平方
        egl.eglGetConfigAttrib(显示器,configurationsList [I],EGL10.EGL_MAX_PBUFFER_WIDTH,textureSize);

        //跟踪最大纹理大小
        如果(maximumTextureSize&其中; textureSize [0])
        {
            maximumTextureSize = textureSize [0];
        }

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

    // 推出
    egl.eglTerminate(显示);
    Log.i(GLHelper,最大GL纹理尺寸:+ Integer.toString(maximumTextureSize));

    返回maximumTextureSize;

}
 

解决方案

pbuffer的最大规模​​遗憾的是没有关系的最大纹理大小(但可能是相同的)。

我相信,以获得最大纹理尺寸的最好方法是创建GL上下文(在相同的情况下为一个对你会真正使用这个纹理),并要求GL_MAX_TEXTURE_SIZE。

有背后强大的理由:对于当前进程的表面(和上下文)创建之前的OGL驱动器未初始化。有些司机进行底层硬件/ SKU检测的初始化,并计算最大表面的大小取决于硬件的能力。

此外,最大纹理大小允许依赖于上下文(和EGLConfig上下文上创建的)。以改变

还有一件事:eglGetConfigs会得到你所有的EGLconfigs,即使是这些来自默认情况下,Android的软件渲染器,或theese从OpenGL ES的1.1CM硬件的驱动程序(如果有1.1和2.0不同的驱动程序在目标平台上)。司机是那种独立的图形堆栈并且可以返回不同的MAX-ES。

OpenGL ES 2.0应用中启用4 MSAA会怎样

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;

}

解决方案

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.