Skip to content

Commit

Permalink
Oculus native (#2174)
Browse files Browse the repository at this point in the history
* Oculus native backend

* build oculus

* Oculus template

* update readme
  • Loading branch information
nkast authored Jan 6, 2025
1 parent ec3c109 commit 198ed18
Show file tree
Hide file tree
Showing 30 changed files with 4,217 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
run: dotnet build Kni.Platform.iOS.GL.sln --property:WarningLevel=1
- name: Build Android.GL
run: dotnet build Kni.Platform.Android.GL.sln --property:WarningLevel=1
# - name: Build Oculus.GL
# run: dotnet build Kni.Platform.Oculus.GL.sln --property:WarningLevel=1
# - name: Build Cardboard.GL
# run: dotnet build Kni.Platform.Cardboard.GL.sln --property:WarningLevel=1
# - name: Build Windows UAP.DX11
Expand Down
1 change: 1 addition & 0 deletions BuildNuget.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dotnet pack src\Xna.Framework.Content.Pipeline.Media\Xna.Framework.Content.Pipel
"C:\Program Files (x86)\NuGet3\nuget.exe" pack NuGetPackages/MonoGame.Framework.WindowsUniversal.nuspec -OutputDirectory NuGetPackages\Output\ -BasePath . -Version 3.14.9001.0 -Properties Configuration=Release

dotnet pack Platforms\Kni.Platform.Android.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
dotnet pack Platforms\Kni.Platform.Oculus.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
dotnet pack Platforms\Kni.Platform.iOS.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
dotnet pack Platforms\Kni.Platform.WinForms.DX11.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
dotnet pack Platforms\Kni.Platform.SDL2.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
Expand Down
7 changes: 7 additions & 0 deletions KNI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Tests.SDL2.GL", "Tests\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Tests.WinForms.DX11", "Tests\Kni.Tests.WinForms.DX11.csproj", "{DED2DDB6-D4BE-656D-2E54-657374732E57}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Platform.Oculus.GL", "Platforms\Kni.Platform.Oculus.GL.csproj", "{3472997A-CD26-4D0D-B64A-795F913E6777}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -207,6 +209,10 @@ Global
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Release|Any CPU.Build.0 = Release|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -243,6 +249,7 @@ Global
{5212C44E-1573-43C2-85E8-5751A12FBBFD} = {753EFCC6-42AB-433E-A013-B7B5D1FE50E0}
{DED2DDB6-D4BE-B1B4-2E54-657374732E57} = {94670BA5-3B36-4EBA-A3E0-27912F6BD11A}
{DED2DDB6-D4BE-656D-2E54-657374732E57} = {94670BA5-3B36-4EBA-A3E0-27912F6BD11A}
{3472997A-CD26-4D0D-B64A-795F913E6777} = {9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {48F20664-456B-4FE0-AE0A-7F5AC695B13C}
Expand Down
98 changes: 98 additions & 0 deletions Kni.Platform.Oculus.GL.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 17.9.34723.18
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Framework", "Framework", "{A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platforms", "Platforms", "{9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework", "src\Xna.Framework\Xna.Framework.csproj", "{741B4B1E-89E4-434C-8867-6129838AFD51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Content", "src\Xna.Framework.Content\Xna.Framework.Content.csproj", "{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Graphics", "src\Xna.Framework.Graphics\Xna.Framework.Graphics.csproj", "{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Audio", "src\Xna.Framework.Audio\Xna.Framework.Audio.csproj", "{3F81F76D-F0F3-44FE-A256-40AF153C33F7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Media", "src\Xna.Framework.Media\Xna.Framework.Media.csproj", "{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Input", "src\Xna.Framework.Input\Xna.Framework.Input.csproj", "{8FB8B257-C091-4C41-B221-75C37B68CD8F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Game", "src\Xna.Framework.Game\Xna.Framework.Game.csproj", "{90BBD6EF-F386-4F47-88CD-BF386C7D1705}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Devices", "src\Xna.Framework.Devices\Xna.Framework.Devices.csproj", "{6B3E56F7-C567-463C-9746-0244FD959322}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Storage", "src\Xna.Framework.Storage\Xna.Framework.Storage.csproj", "{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xna.Framework.XR", "src\Xna.Framework.XR\Xna.Framework.XR.csproj", "{6D0D985D-B256-4208-9E78-77897D461698}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Platform.Oculus.GL", "Platforms\Kni.Platform.Oculus.GL.csproj", "{3472997A-CD26-4D0D-B64A-795F913E6777}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{741B4B1E-89E4-434C-8867-6129838AFD51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{741B4B1E-89E4-434C-8867-6129838AFD51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{741B4B1E-89E4-434C-8867-6129838AFD51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{741B4B1E-89E4-434C-8867-6129838AFD51}.Release|Any CPU.Build.0 = Release|Any CPU
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Release|Any CPU.Build.0 = Release|Any CPU
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Release|Any CPU.Build.0 = Release|Any CPU
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Release|Any CPU.Build.0 = Release|Any CPU
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Release|Any CPU.Build.0 = Release|Any CPU
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Release|Any CPU.Build.0 = Release|Any CPU
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Release|Any CPU.Build.0 = Release|Any CPU
{6B3E56F7-C567-463C-9746-0244FD959322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B3E56F7-C567-463C-9746-0244FD959322}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B3E56F7-C567-463C-9746-0244FD959322}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B3E56F7-C567-463C-9746-0244FD959322}.Release|Any CPU.Build.0 = Release|Any CPU
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Release|Any CPU.Build.0 = Release|Any CPU
{6D0D985D-B256-4208-9E78-77897D461698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D0D985D-B256-4208-9E78-77897D461698}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D0D985D-B256-4208-9E78-77897D461698}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D0D985D-B256-4208-9E78-77897D461698}.Release|Any CPU.Build.0 = Release|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{741B4B1E-89E4-434C-8867-6129838AFD51} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{3F81F76D-F0F3-44FE-A256-40AF153C33F7} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{8FB8B257-C091-4C41-B221-75C37B68CD8F} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{90BBD6EF-F386-4F47-88CD-BF386C7D1705} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{6B3E56F7-C567-463C-9746-0244FD959322} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{6D0D985D-B256-4208-9E78-77897D461698} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
{3472997A-CD26-4D0D-B64A-795F913E6777} = {9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions NuGetPackages/RegisterLocalNuget.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set username=username
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.UAP.DX11 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.SDL2.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.Android.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.Oculus.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive

"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.WinForms.DX11.OculusOVR 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive

Expand Down Expand Up @@ -54,6 +55,7 @@ set username=username
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.UAP.DX11.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.SDL2.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.Android.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.Oculus.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"

"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.WinForms.DX11.OculusOVR.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"

Expand Down
4 changes: 4 additions & 0 deletions Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public override bool BeginDraw()

public override void EndDraw()
{
#if OCULUS
return; // On Oculus, do not Present() the backbuffer.
#endif

//base.EndDraw();

GraphicsDevice device = this.GraphicsDevice;
Expand Down
139 changes: 139 additions & 0 deletions Platforms/Game/.Oculus/AndroidCompatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System;
using System.Linq;
using Android.App;
using Android.Content.Res;
using Android.OS;
using Android.Views;

namespace Microsoft.Xna.Framework
{
/// <summary>
/// Properties that change from how XNA works by default
/// </summary>
public class AndroidCompatibility
{
private static AndroidCompatibility _current;

/// <summary>
/// Because the Kindle Fire devices default orientation is fliped by 180 degrees from all the other android devices
/// on the market we need to do some special processing to make sure that LandscapeLeft is the correct way round.
/// This list contains all the Build.Model strings of the effected devices, it should be added to if and when
/// more devices exhibit the same issues.
/// </summary>
private readonly string[] Kindles = new[] { "KFTT", "KFJWI", "KFJWA", "KFSOWI", "KFTHWA", "KFTHWI", "KFAPWA", "KFAPWI" };

public bool FlipLandscape { get; private set; }

[CLSCompliant(false)]
public Orientation NaturalOrientation { get; private set; }


[CLSCompliant(false)]
public static AndroidCompatibility Current
{
get
{
if (_current != null)
return _current;
else
throw new InvalidOperationException("Not initialized.");
}
}

internal static void Initialize(Activity activity)
{
if (_current == null)
_current = new AndroidCompatibility(activity);
}

private AndroidCompatibility(Activity activity)
{
FlipLandscape = Kindles.Contains(Build.Model);
NaturalOrientation = GetDeviceNaturalOrientation(activity);
}

private Orientation GetDeviceNaturalOrientation(Activity activity)
{
var orientation = activity.Resources.Configuration.Orientation;
SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation;

// check if MainActivity setup is correct.
var screenOrientation = activity.RequestedOrientation;
if (screenOrientation != Android.Content.PM.ScreenOrientation.Landscape)
throw new InvalidOperationException("Invalid orientation. Set ScreenOrientation in MainActivity to Landscape.");

if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) &&
orientation == Orientation.Landscape)
|| ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) &&
orientation == Orientation.Portrait))
{
return Orientation.Landscape;
}
else
{
return Orientation.Portrait;
}
}

internal DisplayOrientation GetAbsoluteOrientation(int degrees)
{
// Orientation is reported by the device in degrees compared to the natural orientation
// Some tablets have a natural landscape orientation, which we need to account for
if (NaturalOrientation == Orientation.Landscape)
degrees += 270;

// Round orientation into one of 8 positions, either 0, 45, 90, 135, 180, 225, 270, 315.
degrees = ( ((degrees + 22) / 45) * 45) % 360;

// Surprisingly 90 degree is landscape right, except on Kindle devices
var disporientation = DisplayOrientation.Unknown;
switch (degrees)
{
case 90: disporientation = FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight;
break;
case 270: disporientation = FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft;
break;
case 0: disporientation = DisplayOrientation.Portrait;
break;
case 180: disporientation = DisplayOrientation.PortraitDown;
break;
default:
disporientation = DisplayOrientation.Unknown;
break;
}

return disporientation;
}

/// <summary>
/// Get the absolute orientation of the device, accounting for platform differences.
/// </summary>
/// <returns></returns>
[CLSCompliant(false)]
public DisplayOrientation GetAbsoluteOrientation(Activity activity)
{
var orientation = activity.WindowManager.DefaultDisplay.Rotation;

// Landscape degrees (provided by the OrientationListener) are swapped by default
// Since we use the code used by OrientationListener, we have to swap manually
int degrees;
switch (orientation)
{
case SurfaceOrientation.Rotation90:
degrees = 270;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 90;
break;
default:
degrees = 0;
break;
}

return GetAbsoluteOrientation(degrees);
}
}
}
Loading

0 comments on commit 198ed18

Please sign in to comment.