Skip to content

Commit

Permalink
[OpenXR] Makes device construction internal and improves exception me…
Browse files Browse the repository at this point in the history
…ssages of new StartPassthrough method
  • Loading branch information
azeno committed Feb 7, 2024
1 parent 5513952 commit ff27bf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions sources/engine/Stride.VirtualReality/OpenXR/OpenXRHmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class OpenXRHmd : VRDevice
// Public static variable to add extensions to the initialization of the openXR session
public static List<string> extensions = new List<string>();

public static OpenXRHmd? New(bool requestPassthrough)
/// <summary>
/// Creates a VR device using OpenXR.
/// </summary>
/// <param name="requestPassthrough">Whether or not the XR_FB_passthrough extension should be enabled (if available).</param>
internal static OpenXRHmd? New(bool requestPassthrough)
{
// Create our API object for OpenXR.
var xr = XR.GetApi();
Expand Down Expand Up @@ -62,6 +66,7 @@ public class OpenXRHmd : VRDevice

// Passthrough
private OpenXRExt_FB_Passthrough? passthroughExt;
private bool passthroughRequested;

private GraphicsDevice? baseDevice;

Expand Down Expand Up @@ -133,6 +138,7 @@ private OpenXRHmd(XR xr, bool requestPassthrough)
{
Xr = xr;
VRApi = VRApi.OpenXR;
passthroughRequested = requestPassthrough;

var requestedExtensions = new List<string>(extensions);
if (requestPassthrough)
Expand Down Expand Up @@ -361,8 +367,11 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager

public override IDisposable StartPassthrough()
{
if (!passthroughRequested)
throw new InvalidOperationException("The passthrough mode needs to be enabled at device creation");

if (!SupportsPassthrough)
throw new NotSupportedException();
throw new NotSupportedException("The device does not support Passthrough mode");

if (passthroughExt is null)
passthroughExt = new OpenXRExt_FB_Passthrough(Xr, globalSession, Instance);
Expand Down
3 changes: 2 additions & 1 deletion sources/engine/Stride.VirtualReality/VRDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public virtual void ReleaseOverlay(VROverlay overlay)
/// Starts a passthrough. When enabled the scene is rendered on top of the camera image of the device.
/// </summary>
/// <returns>A disposable which will stop the passthrough on dispose.</returns>
/// <exception cref="NotSupportedException">Thrown if passthrough is not supported by the device.</exception>
/// <exception cref="NotSupportedException">Thrown if the passthrough mode is not supported by the device.</exception>
/// <exception cref="InvalidOperationException">Thrown if the passthrough mode is already enabled.</exception>
public virtual IDisposable StartPassthrough()
{
throw new NotSupportedException();
Expand Down

0 comments on commit ff27bf7

Please sign in to comment.