[英]Get Maximum OpenGL ES 2.0 Texture Size Limit in Android
我試圖在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;
}
遺憾的是,PBUFFER最大尺寸與最大紋理尺寸無關(但可能相同)。
我相信獲得最大紋理大小的最佳方法是創建GL上下文(與實際使用此紋理的上下文相同)並請求GL_MAX_TEXTURE_SIZE。
這背后有充分的理由:在創建表面(和上下文)之前,未對當前進程初始化ogl驅動程序。 某些驅動程序在初始化時執行基礎HW / SKU檢測,並根據硬件功能計算最大表面大小。
此外,允許最大紋理大小取決於上下文(並且創建了EGLConfig上下文)。
還有一件事:eglGetConfigs將獲得所有EGLconfigs,甚至是默認的軟件android渲染器,或者來自OpenGL ES 1.1CM HW驅動程序(如果在目標平台上有1.1和2.0的單獨驅動程序)。 驅動程序在圖形堆棧中是獨立的,可以返回不同的max-es。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.