forked from dotnet/android-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GLNativeES30] Cleanly fails on unsupported HW
User is notified when the device does not have the hardware support for OpenGL ES 3.0 instead of just crashing.
- Loading branch information
benohalloran
committed
Jul 1, 2014
1 parent
dbd026a
commit 030a725
Showing
6 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="GLNativeES30.GLNativeES30"> | ||
<uses-sdk /> | ||
<uses-sdk android:minSdkVersion="18" /> | ||
<application android:label="GLNativeES30"> | ||
<uses-feature android:glEsVersion="0x00030000" android:required="true" /> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:minWidth="25px" | ||
android:minHeight="25px" | ||
android:padding="5dp"> | ||
<TextView | ||
android:text="Checking hardware support for OpenGL ES 3.0" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/textView1" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">GLNativeES30</string> | ||
<string name="unsupported">This application requires OpenGL 3.0 support. OpenGL 3.0 requires Android 4.3 or higher and hardware support. This device does not have hardware support.</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
| ||
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 GLNativeES30 | ||
{ | ||
[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(GLNativeES30Activity)); | ||
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 () | ||
{ | ||
//from 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) | ||
{ | ||
//from 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; | ||
} | ||
} | ||
} | ||
|