Cat*_*san 7 android opengl-es-2.0
我正在为API级别创建一个Android应用程序> = 7.一个屏幕通过ndk使用带有OpenGL ES 2.0的GLSurfaceView.如何检测opengl 2.0是否可用?我不能android:glEsVersion="0x00020000"在我的AndroidManifest.xml中使用,因为我必须支持API级别> = 7的所有手机.如果不支持2.0,我将显示静态屏幕.
我正在使用ndk附带的hello-gl2示例应用程序中的类似代码.在GL2JNIView中,当它设置Opengl上下文时,如果它没有找到合适的opengl配置(在我的情况下是一个需要opengl es 2.0的配置),它会抛出一个IllegalArgumentException("No configs match configSpec")并且应用程序崩溃.我找不到拦截该异常并在该屏幕上执行其他操作的方法.有任何想法吗?
这是我在互联网中发现的:
private boolean checkGL20Support( Context context )
{
EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
egl.eglInitialize(display, version);
int EGL_OPENGL_ES2_BIT = 4;
int[] configAttribs =
{
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[10];
int[] num_config = new int[1];
egl.eglChooseConfig(display, configAttribs, configs, 10, num_config);
egl.eglTerminate(display);
return num_config[0] > 0;
}
Run Code Online (Sandbox Code Playgroud)
资料来源:http://www.badlogicgames.com/wordpress/? p = 343
也许这可以帮助
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Check if the system supports OpenGL ES 2.0.
final ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
if (supportsEs2)
{
// Request an OpenGL ES 2.0 compatible context.
}
else
{
// This is where you could create an OpenGL ES 1.x compatible
// renderer if you wanted to support both ES 1 and ES 2.
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6690 次 |
| 最近记录: |