Android 模拟器上的 OpenGL ES 应用程序禁用了 GPU(软件加速)
OpenGL ES Application on Android Emulator with GPU disabled (Software Accelerated)
我正尝试在 Raspberry Pi 2 (Android Lollipop 5.1) 上 运行 Android OpenGL ES 应用程序。目前不支持硬件加速,所以我已经在软件中完成了所有渲染。
可以在具有以下配置的仿真器 (AVD) 上重新创建 R Pi 的相同环境:ARMv7、禁用 GPU 和 Android 5.1。
如果我在模拟器中启用 GPU,一切正常,但如果我禁用它,我会收到以下错误:
10-23 22:53:36.798 1550-1565/com.example.android.mediaeffects E/AndroidRuntime﹕
FATAL EXCEPTION: GLThread 187
Process: com.example.android.mediaeffects, PID: 1550
java.lang.IllegalArgumentException: No configs match configSpec
at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:858)
at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1023)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1400)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
我看到这个错误对其他人来说也很常见,例如 post:
" java.lang.IllegalArgumentException: No configs match configSpec " While opening Camera Intent
或在其他 post:
OpenGL ES 2.0 Support for Android?
对其他人有效的解决方案是:
1) 在模拟器上启用 GPU
2) 按以下方式设置 EGL 配置:
setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
我的问题是我需要禁用 GPU(因为在 R Pi 上它被禁用),所以我仍然遇到这个错误。
我还通过添加以下内容在清单文件上强制软件加速:
<application
.....
android:hardwareAccelerated="false"
.....>
但这似乎没有任何改变。
有没有人知道如何解决这个问题,但仍然在禁用 GPU 和软件加速(hardwareAccelerated="false")的情况下工作?
我使用以下 setEGLConfigChooser()
方法实现解决了这个问题:
mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview);
mEffectView.setEGLContextClientVersion(2);
mEffectView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
/* Get the number of minimally matching EGL configurations */
int[] s_configAttribs2 =
{
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_RENDERABLE_TYPE, 1,
EGL10.EGL_NONE
};
int[] num_config = new int[1];
egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
int numConfigs = num_config[0];
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
/* Allocate then read the array of minimally matching EGL configs */
EGLConfig[] configs = new EGLConfig[numConfigs];
egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
/* Return the first configuration found */
return configs[0];
}
});
使用此方法可以正确找到有效的 EGL 配置。
我正尝试在 Raspberry Pi 2 (Android Lollipop 5.1) 上 运行 Android OpenGL ES 应用程序。目前不支持硬件加速,所以我已经在软件中完成了所有渲染。
可以在具有以下配置的仿真器 (AVD) 上重新创建 R Pi 的相同环境:ARMv7、禁用 GPU 和 Android 5.1。
如果我在模拟器中启用 GPU,一切正常,但如果我禁用它,我会收到以下错误:
10-23 22:53:36.798 1550-1565/com.example.android.mediaeffects E/AndroidRuntime﹕
FATAL EXCEPTION: GLThread 187
Process: com.example.android.mediaeffects, PID: 1550
java.lang.IllegalArgumentException: No configs match configSpec
at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:858)
at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1023)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1400)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
我看到这个错误对其他人来说也很常见,例如 post:
" java.lang.IllegalArgumentException: No configs match configSpec " While opening Camera Intent
或在其他 post:
OpenGL ES 2.0 Support for Android?
对其他人有效的解决方案是:
1) 在模拟器上启用 GPU
2) 按以下方式设置 EGL 配置:
setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
我的问题是我需要禁用 GPU(因为在 R Pi 上它被禁用),所以我仍然遇到这个错误。
我还通过添加以下内容在清单文件上强制软件加速:
<application
.....
android:hardwareAccelerated="false"
.....>
但这似乎没有任何改变。
有没有人知道如何解决这个问题,但仍然在禁用 GPU 和软件加速(hardwareAccelerated="false")的情况下工作?
我使用以下 setEGLConfigChooser()
方法实现解决了这个问题:
mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview);
mEffectView.setEGLContextClientVersion(2);
mEffectView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
/* Get the number of minimally matching EGL configurations */
int[] s_configAttribs2 =
{
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_RENDERABLE_TYPE, 1,
EGL10.EGL_NONE
};
int[] num_config = new int[1];
egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
int numConfigs = num_config[0];
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
/* Allocate then read the array of minimally matching EGL configs */
EGLConfig[] configs = new EGLConfig[numConfigs];
egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
/* Return the first configuration found */
return configs[0];
}
});
使用此方法可以正确找到有效的 EGL 配置。