【问题标题】:GLSurfaceView with opengl ES 3.0GLSurfaceView 与 opengl ES 3.0
【发布时间】:2017-01-13 05:09:49
【问题描述】:
我的问题是:GLSurfaceView 是否支持 api18+ 的 EGL 上下文 3.0。
因为我使用了 setEGLContextClientVersion( 3 ) 然后 crash accurs ,所以我没有只用一台具有 android 4.4.2 的设备进行尝试
并且清单包含
<uses-feature android:glEsVersion="0x00030000" android:required="true"/>
【问题讨论】:
标签:
android
opengl-es
glsurfaceview
【解决方案1】:
正如official documentation 所述,设备可能不支持 OpenGL 3.0,因此您应该在设置 egl 上下文版本之前检查这一点。
但是,如果您在清单中为 uses-feature 声明 required=true,则应用在 Google Play 商店中发布后,对于那些不支持它的设备应该是不可见的。因此,除非他们设法从其他来源下载 APK,否则他们将无法安装它。
要检查 3.0 是否可用,您可以执行以下操作:
private static double glVersion = 3.0;
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
Log.w(TAG, "creating OpenGL ES " + glVersion + " context");
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, (int) glVersion, EGL10.EGL_NONE };
// attempt to create a OpenGL ES 3.0 context
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
return context; // returns null if 3.0 is not supported;
}
}