Android-检测设备最大OpenGL版本
我有一个应用程序,它使用OpenGL ES 2或3。如果3是可用的,它应该是首选,因为我正在使用它的一些功能来提高性能。 是否有一种方法,如何在呼叫前检测ES版本Android-检测设备最大OpenGL版本,android,opengl-es,Android,Opengl Es,我有一个应用程序,它使用OpenGL ES 2或3。如果3是可用的,它应该是首选,因为我正在使用它的一些功能来提高性能。 是否有一种方法,如何在呼叫前检测ES版本 setEGLContextClientVersion 在舱单上,我有 <uses-feature android:glEsVersion="0x00020000" android:required="true"/> 在只支持2.0的设备上,我希望init GL支持2.0。但如果设备同时支持-2.0和3.0(或3.1
setEGLContextClientVersion
在舱单上,我有
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
在只支持2.0的设备上,我希望init GL支持2.0。但如果设备同时支持-2.0和3.0(或3.1),我想使用后者
如何做到这一点?来自谷歌资源:
private static int getVersionFromActivityManager(上下文){
活动管理器活动管理器=
(ActivityManager)context.getSystemService(context.ACTIVITY_服务);
ConfigurationInfo configInfo=activityManager.GetDeviceConfiguration信息();
if(configInfo.reqGlEsVersion!=ConfigurationInfo.GL\U ES\U版本\U未定义){
返回configInfo.reqGlEsVersion;
}否则{
返回1(0){
用于(功能信息功能信息:功能信息){
//Null功能名称表示此功能是open gl es版本功能。
if(featureInfo.name==null){
if(featureInfo.reqGlEsVersion!=featureInfo.GL\u ES\u版本\u未定义){
返回featureInfo.reqGlEsVersion;
}否则{
return 1我相信萨满的方法很好,但谷歌的文档似乎推荐了另外两种方法。从这里:
在从高于应用程序清单中所需最低版本的版本使用OpenGL ES功能之前,应用程序应检查设备上可用的API版本。可以通过以下两种方法之一执行此操作:
尝试创建更高级别的OpenGL ES上下文(EGLContext)和
检查结果
创建受支持的最小OpenGL ES上下文并检查版本
价值观
下面的示例代码演示如何检查可用的
OpenGL通过创建一个EGLContext并检查结果来更新版本。
此示例显示如何检查OpenGL ES 3.0版本:
如果上面显示的createContext()方法返回null,那么您的代码
应该创建OpenGL ES 2.0上下文,然后使用
只有那个API
下面的代码示例演示如何检查OpenGL ES
通过先创建受支持的最小上下文,然后
正在检查版本字符串:
//创建受支持的最小OpenGL ES上下文,然后选中:
字符串版本=javax.microedition.khronos.opengles.GL10.glGetString(
GL10.GL_版本);
Log.w(标签,“版本:”+版本);
//版本格式显示为:“OpenGL ES”
//然后是实现提供的可选内容。
使用这种方法,如果您发现设备支持
更高级别的API版本,必须销毁最小的OpenGL ES
上下文,并使用更高的可用API创建新上下文
版本
private static int getVersionFromActivityManager(Context context) {
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) {
return configInfo.reqGlEsVersion;
} else {
return 1 << 16; // Lack of property means OpenGL ES version 1
}
}
private static int getVersionFromPackageManager(Context context) {
PackageManager packageManager = context.getPackageManager();
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
if (featureInfos != null && featureInfos.length > 0) {
for (FeatureInfo featureInfo : featureInfos) {
// Null feature name means this feature is the open gl es version feature.
if (featureInfo.name == null) {
if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
return featureInfo.reqGlEsVersion;
} else {
return 1 << 16; // Lack of property means OpenGL ES version 1
}
}
}
}
return 1;
}
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;
}
}
// Create a minimum supported OpenGL ES context, then check:
String version = javax.microedition.khronos.opengles.GL10.glGetString(
GL10.GL_VERSION);
Log.w(TAG, "Version: " + version );
// The version format is displayed as: "OpenGL ES <major>.<minor>"
// followed by optional content provided by the implementation.