我正在尝试获取 Android 中 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;
}
最佳答案
不幸的是,PBUFFER 最大尺寸与最大纹理尺寸无关(但可能相同)。
我相信获得最大纹理大小的最佳方法是创建 GL 上下文(在与您实际使用该纹理的上下文相同的上下文中)并请求 GL_MAX_TEXTURE_SIZE。
这背后有充分的理由:在表面(和上下文)创建之前,ogl 驱动程序未针对当前进程进行初始化。一些驱动程序在初始化时执行底层 HW/SKU 检测,并根据 HW 功能计算最大表面尺寸。
此外,允许最大纹理大小根据上下文(EGLConfig 上下文的创建时间)而变化。
还有一件事:eglGetConfigs 将为您提供所有 EGL 配置,甚至是来自默认软件 android 渲染器的配置,或者来自 OpenGL ES 1.1CM HW 驱动程序的这些配置(如果目标平台上有单独的 1.1 和 2.0 驱动程序)。驱动程序在图形堆栈中是独立的,可以返回不同的最大值。
关于android - 在 Android 中获取最大 OpenGL ES 2.0 纹理大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11022109/