Created
March 28, 2017 02:32
-
-
Save tuesda/d6c864972b54f8bd2f6bc9746808814d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int getMaxSizeInternal() { | |
EGL10 egl = (EGL10) EGLContext.getEGL(); | |
EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); | |
int[] versions = new int[2]; | |
egl.eglInitialize(dpy, versions); | |
EGLConfig[] configs = new EGLConfig[1]; | |
int[] numConfig = new int[1]; | |
egl.eglGetConfigs(dpy, configs, 1, numConfig); | |
if (numConfig[0] == 0) { | |
// TROUBLE! No config found. | |
// 创建 openGl context 失败,所以直接尝试调用max size,因为android 5.0之前没有context也可以直接调用成功 | |
int[] maxSize = new int[1]; | |
GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); | |
return maxSize[0]; | |
} | |
EGLConfig config = configs[0]; | |
int[] surfAttr = { | |
EGL10.EGL_WIDTH, 64, | |
EGL10.EGL_HEIGHT, 64, | |
EGL10.EGL_NONE | |
}; | |
EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr); | |
final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; // missing in EGL10 | |
int[] ctxAttribute = { | |
EGL_CONTEXT_CLIENT_VERSION, 1, | |
EGL10.EGL_NONE | |
}; | |
EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttribute); | |
egl.eglMakeCurrent(dpy, surf, surf, ctx); | |
int[] maxSize = new int[1]; | |
GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); | |
egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, | |
EGL10.EGL_NO_CONTEXT); | |
egl.eglDestroySurface(dpy, surf); | |
egl.eglDestroyContext(dpy, ctx); | |
egl.eglTerminate(dpy); | |
return maxSize[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment