2017-12-10 1 views
0

私はOpenGL ES 2または3を使用しているアプリを持っています。3を利用できる場合は、その機能の一部を使用してパフォーマンスを向上させているため、3を使用することをお勧めします。 は、どのようにマニフェストでAndroid - 最大デバイス検出OpenGLバージョン

setEGLContextClientVersion 

を呼び出す前に、ESのバージョンを検出するために、そこの方法です、私はsupportesが唯一の2.0私はしたいが、2.0とGLを初期化することを、デバイスで

<uses-feature android:glEsVersion="0x00020000" android:required="true"/> 

を持っています。しかし、デバイスが2.0と3.0(または3.1)の両方をサポートしている場合は、後で使用したいと思います。

これを行う方法?

答えて

1

Googleのソース[Compatibility Test Suite]から:

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; 
    } 
1

私はシャーマンのアプローチは罰金であると確信しているが、Googleのドキュメントは、他の二つのアプローチを推奨しているように見えるん。ここから:https://developer.android.com/guide/topics/graphics/opengl.html

アプリケーションマニフェストに必要な最小値より高いバージョンからのOpenGL ESの機能を使用する前に、アプリケーションがデバイスで使用可能なAPIのバージョンを確認する必要があります。

上位レベルのOpenGL ESコンテキスト(EGLContext)を作成しようとしましたが、 の結果を確認してください。

最小限サポートされているOpenGL ESコンテキストを作成し、バージョン の値を確認してください。

次のコード例は、EGLContextを作成して結果を確認して、利用可能な OpenGL ESバージョンを確認する方法を示しています。

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; 
    } 
} 

のcreateContext()メソッドのショーは、上記nullを返した場合、あなたのコード ではなくのOpenGL ES 2.0コンテキストを作成してにフォールバックする必要があります この例では、OpenGL ESのための3.0バージョンを確認する方法を示していますそのAPIだけを を使用してください。あなたがあれば、このアプローチで

// 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. 

次のコード例では、最初にサポートされる最小のコンテキストを作成することにより、OpenGL ESの バージョンを確認し、 は、バージョン文字列をチェックする方法を示していますデバイスが 上位APIバージョンをサポートしていることを発見した場合は、最低限のOpenGL ES コンテキストを破棄し、より高い利用可能なAPI バージョンで新しいコンテキストを作成する必要があります。

関連する問題