【发布时间】:2017-10-11 14:18:15
【问题描述】:
在使用 PowerVR G6200 GPU 的设备(例如 Sony Xperia M5 (E5603) 和 Xiaomi Redmi Note 3 (hennessy))上,创建使用 OpenGL ES 2 进行渲染的 EGL 上下文失败,而它在我测试过的所有其他设备上都可以使用:
java.lang.RuntimeException:
at android.opengl.GLSurfaceView$EglHelper.throwEglException (GLSurfaceView.java:1233)
at android.opengl.GLSurfaceView$EglHelper.throwEglException (GLSurfaceView.java:1224)
at android.opengl.GLSurfaceView$EglHelper.start (GLSurfaceView.java:1074)
at android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1447)
at android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1286)
配置选择器是这样实现的:
class CustomEGLConfigChooser implements GLSurfaceView.EGLConfigChooser {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
EGLConfig [] configs = new EGLConfig[1];
int [] num_config = new int[1];
int [] attrib_list = new int[] {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 24,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE,
};
boolean res = egl.eglChooseConfig(display, attrib_list, configs, configs.length, num_config);
if (res && num_config[0] > 0) {
return configs[0];
}
return null;
}
}
配置选择器从 GLSurfaceView 子类中使用,如下所示:
public class GameView extends GLSurfaceView {
public GameView (Context context, ClientConfig clientConfig) {
super(context);
setEGLContextClientVersion(2);
setEGLConfigChooser(new CustomEGLConfigChooser());
}
}
【问题讨论】:
标签: java android opengl-es-2.0 glsurfaceview egl