Skip to content

Commit

Permalink
[GLNativeES30] Cleanly fails on unsupported HW
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
6 changes: 4 additions & 2 deletions GLNativeES30/GLNativeES30.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F2AB5E1D-F6AB-46F8-B83B-6B0F4F06BA19}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand All @@ -17,7 +17,7 @@
<AssemblyName>GLNativeES20</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v4.3</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand Down Expand Up @@ -53,6 +53,7 @@
<Compile Include="Triangle.cs" />
<Compile Include="Square.cs" />
<Compile Include="GLNativeES30Activity.cs" />
<Compile Include="TestActivity.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand All @@ -67,6 +68,7 @@
<AndroidResource Include="Resources\drawable-mdpi\icon.png" />
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
<AndroidResource Include="Resources\drawable-xxhdpi\icon.png" />
<AndroidResource Include="Resources\layout\Test.axml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GLNativeES30/GLNativeES30Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace GLNativeES30
// keyboard is shown (highly recommended for all GL apps)
[Activity (Label = "GLNativeES30",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
MainLauncher = true)]
MainLauncher = false)]
public class GLNativeES30Activity : Activity
{
private GLSurfaceView mGLView;
Expand Down
3 changes: 2 additions & 1 deletion GLNativeES30/Properties/AndroidManifest.xml
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>
15 changes: 15 additions & 0 deletions GLNativeES30/Resources/layout/Test.axml
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>
1 change: 1 addition & 0 deletions GLNativeES30/Resources/values/Strings.xml
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>
70 changes: 70 additions & 0 deletions GLNativeES30/TestActivity.cs
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;
}
}
}

0 comments on commit 030a725

Please sign in to comment.