在 Android 中获取最大 OpenGL ES 2.0 纹理大小限制 [英] Get Maximum OpenGL ES 2.0 Texture Size Limit in Android

查看:20
本文介绍了在 Android 中获取最大 OpenGL ES 2.0 纹理大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android 中为 OpenGL 2.0 获取最大纹理大小限制.但是我发现下一条指令只有在我当前处于 OpenGL 上下文中时才有效,换句话说,我必须有一个 GL Surface 和一个 GL Renderer 等,这是我不想要的.

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);

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

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 最大尺寸与最大纹理尺寸无关(但可能相同).

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

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

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.

这背后有一个强有力的原因:在表面(和上下文)创建之前,ogl 驱动程序没有为当前进程初始化.一些驱动程序在初始化时执行底层硬件/SKU 检测,并根据硬件功能计算最大表面尺寸.

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.

此外,最大纹理大小允许根据上下文(并且创建 EGLConfig 上下文)而变化.

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

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

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.

这篇关于在 Android 中获取最大 OpenGL ES 2.0 纹理大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆