Some small improvements to the FB Passthrough tool to allow passthrough on startup, andbe a little more defensive.
@@ -8,6 +8,8 @@ namespace StereoKit.Framework
bool extAvailable;
bool enabled;
bool enabledPassthrough;
+ bool enableOnInitialize;
+ bool passthroughRunning;
XrPassthroughFB activePassthrough = new XrPassthroughFB();
XrPassthroughLayerFB activeLayer = new XrPassthroughLayerFB();
@@ -24,11 +26,13 @@ namespace StereoKit.Framework
}
} }
- public PassthroughFBExt()
+ public PassthroughFBExt() : this(true) { }
+ public PassthroughFBExt(bool enabled = true)
{
if (SK.IsInitialized)
Log.Err("PassthroughFBExt must be constructed before StereoKit is initialized!");
Backend.OpenXR.RequestExt("XR_FB_passthrough");
+ enableOnInitialize = enabled;
}
public bool Initialize()
@@ -38,6 +42,8 @@ namespace StereoKit.Framework
Backend.OpenXR.ExtEnabled("XR_FB_passthrough") &&
LoadBindings();
+ if (enableOnInitialize)
+ EnabledPassthrough = true;
return true;
}
@@ -57,15 +63,19 @@ namespace StereoKit.Framework
void StartPassthrough()
{
+ if (!extAvailable) return;
+ if (passthroughRunning) return;
+ passthroughRunning = true;
+
oldColor = Renderer.ClearColor;
oldSky = Renderer.EnableSky;
- xrCreatePassthroughFB(
+ XrResult result = xrCreatePassthroughFB(
Backend.OpenXR.Session,
new XrPassthroughCreateInfoFB(XrPassthroughFlagsFB.IS_RUNNING_AT_CREATION_BIT_FB),
out activePassthrough);
- xrCreatePassthroughLayerFB(
+ result = xrCreatePassthroughLayerFB(
Backend.OpenXR.Session,
new XrPassthroughLayerCreateInfoFB(activePassthrough, XrPassthroughFlagsFB.IS_RUNNING_AT_CREATION_BIT_FB, XrPassthroughLayerPurposeFB.RECONSTRUCTION_FB),
out activeLayer);
@@ -76,6 +86,9 @@ namespace StereoKit.Framework
void EndPassthrough()
{
+ if (!passthroughRunning) return;
+ passthroughRunning = false;
+
xrPassthroughPauseFB (activePassthrough);
xrDestroyPassthroughLayerFB(activeLayer);
xrDestroyPassthroughFB (activePassthrough);
