forked from dotnet/android-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestActivity.cs
70 lines (64 loc) · 2.09 KB
/
TestActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Content.PM;
namespace Mono.Samples.GLTriangle30
{
[Activity (Label = "Compatibility Check", MainLauncher = true)]
public class TestActivity : Activity
{
private static string tag = "GLVersion";
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Test);
if (SupportedOpenGLVersion () >= 3) {
Log.Info (tag, "Supported hardware. Launching the demo.");
var launch = new Intent (this, typeof(GLTriangle30Activity));
StartActivity (launch);
Finish ();
} else {
var textout = FindViewById<TextView> (Resource.Id.textView1);
textout.Text = GetString (Resource.String.unsupported);
Log.Info (tag, "Unsupported hardware. Displaying notification screen");
}
}
/// <summary>
/// Gets the supported OpenGL ES version of device.
/// </summary>
/// <returns>Hieghest supported version of OpenGL ES</returns>
private long SupportedOpenGLVersion ()
{
//based on https://android.googlesource.com/platform/cts/+/master/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
var featureInfos = PackageManager.GetSystemAvailableFeatures ();
if (featureInfos != null && featureInfos.Length > 0) {
foreach (FeatureInfo info in featureInfos) {
// Null feature name means this feature is the open gl es version feature.
if (info.Name == null) {
if (info.ReqGlEsVersion != FeatureInfo.GlEsVersionUndefined)
return GetMajorVersion (info.ReqGlEsVersion);
else
return 0L;
}
}
}
return 0L;
}
private static long GetMajorVersion (long raw)
{
//based on https://android.googlesource.com/platform/cts/+/master/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
long cleaned = ((raw & 0xffff0000) >> 16);
Log.Info (tag, "OpenGL ES major version: " + cleaned);
return cleaned;
}
}
}