version 2.5.0
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
// Copyright HTC Corporation All Rights Reserved.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
using UnityEngine.XR.OpenXR.Features;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.XR.OpenXR.Features;
|
||||
#endif
|
||||
|
||||
namespace VIVE.OpenXR.CompositionLayer
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[OpenXRFeature(UiName = "VIVE XR Composition Layer (Extra Settings) (Beta)",
|
||||
Desc = "Enable this feature to use the Composition Layer Extra Settings.",
|
||||
Company = "HTC",
|
||||
DocumentationLink = "..\\Documentation",
|
||||
OpenxrExtensionStrings = kOpenxrExtensionStrings,
|
||||
Version = "1.0.0",
|
||||
BuildTargetGroups = new[] { BuildTargetGroup.Android },
|
||||
FeatureId = featureId
|
||||
)]
|
||||
#endif
|
||||
public class ViveCompositionLayerExtraSettings : OpenXRFeature
|
||||
{
|
||||
const string LOG_TAG = "VIVE.OpenXR.ViveCompositionLayer.ExtraSettings";
|
||||
static void DEBUG(string msg) { Debug.Log(LOG_TAG + " " + msg); }
|
||||
static void WARNING(string msg) { Debug.LogWarning(LOG_TAG + " " + msg); }
|
||||
static void ERROR(string msg) { Debug.LogError(LOG_TAG + " " + msg); }
|
||||
|
||||
/// <summary>
|
||||
/// Settings Editor Enable Sharpening or Not.
|
||||
/// </summary>
|
||||
public bool SettingsEditorEnableSharpening = false;
|
||||
|
||||
/// <summary>
|
||||
/// Support Sharpening or Not.
|
||||
/// </summary>
|
||||
public bool supportSharpening = false;
|
||||
|
||||
/// <summary>
|
||||
/// Settings Editor Sharpening Mode
|
||||
/// </summary>
|
||||
public XrSharpeningModeHTC SettingsEditorSharpeningMode = XrSharpeningModeHTC.FAST;
|
||||
|
||||
/// <summary>
|
||||
/// Settings Editor Sharpening Levell
|
||||
/// </summary>
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float SettingsEditorSharpeningLevel = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The feature id string. This is used to give the feature a well known id for reference.
|
||||
/// </summary>
|
||||
public const string featureId = "vive.openxr.feature.compositionlayer.extrasettings";
|
||||
|
||||
/// <summary>
|
||||
/// OpenXR specification.
|
||||
/// </summary>
|
||||
public const string kOpenxrExtensionStrings = "XR_HTC_composition_layer_extra_settings";
|
||||
|
||||
#region OpenXR Life Cycle
|
||||
private bool m_XrInstanceCreated = false;
|
||||
/// <summary>
|
||||
/// The XR instance is created or not.
|
||||
/// </summary>
|
||||
public bool XrInstanceCreated
|
||||
{
|
||||
get { return m_XrInstanceCreated; }
|
||||
}
|
||||
private XrInstance m_XrInstance = 0;
|
||||
protected override bool OnInstanceCreate(ulong xrInstance)
|
||||
{
|
||||
foreach (string kOpenxrExtensionString in kOpenxrExtensionStrings.Split(' '))
|
||||
{
|
||||
if (!OpenXRRuntime.IsExtensionEnabled(kOpenxrExtensionString))
|
||||
{
|
||||
WARNING("OnInstanceCreate() " + kOpenxrExtensionString + " is NOT enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
m_XrInstanceCreated = true;
|
||||
m_XrInstance = xrInstance;
|
||||
DEBUG("OnInstanceCreate() " + m_XrInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnInstanceDestroy(ulong xrInstance)
|
||||
{
|
||||
m_XrInstanceCreated = false;
|
||||
DEBUG("OnInstanceDestroy() " + m_XrInstance);
|
||||
}
|
||||
|
||||
private XrSystemId m_XrSystemId = 0;
|
||||
protected override void OnSystemChange(ulong xrSystem)
|
||||
{
|
||||
m_XrSystemId = xrSystem;
|
||||
DEBUG("OnSystemChange() " + m_XrSystemId);
|
||||
}
|
||||
|
||||
private bool m_XrSessionCreated = false;
|
||||
/// <summary>
|
||||
/// The XR session is created or not.
|
||||
/// </summary>
|
||||
public bool XrSessionCreated
|
||||
{
|
||||
get { return m_XrSessionCreated; }
|
||||
}
|
||||
private XrSession m_XrSession = 0;
|
||||
protected override void OnSessionCreate(ulong xrSession)
|
||||
{
|
||||
m_XrSession = xrSession;
|
||||
m_XrSessionCreated = true;
|
||||
DEBUG("OnSessionCreate() " + m_XrSession);
|
||||
}
|
||||
|
||||
private bool m_XrSessionEnding = false;
|
||||
/// <summary>
|
||||
/// The XR session is ending or not.
|
||||
/// </summary>
|
||||
public bool XrSessionEnding
|
||||
{
|
||||
get { return m_XrSessionEnding; }
|
||||
}
|
||||
|
||||
protected override void OnSessionBegin(ulong xrSession)
|
||||
{
|
||||
m_XrSessionEnding = false;
|
||||
DEBUG("OnSessionBegin() " + m_XrSession);
|
||||
|
||||
//enable Sharpening
|
||||
if (OpenXRRuntime.IsExtensionEnabled("XR_HTC_composition_layer_extra_settings"))
|
||||
{
|
||||
ViveCompositionLayer_UpdateSystemProperties(m_XrInstance, m_XrSystemId);
|
||||
supportSharpening = ViveCompositionLayer_IsSupportSharpening();
|
||||
if (supportSharpening && SettingsEditorEnableSharpening)
|
||||
{
|
||||
EnableSharpening(SettingsEditorSharpeningMode, SettingsEditorSharpeningLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSessionEnd(ulong xrSession)
|
||||
{
|
||||
m_XrSessionEnding = true;
|
||||
DEBUG("OnSessionEnd() " + m_XrSession);
|
||||
}
|
||||
|
||||
protected override void OnSessionDestroy(ulong xrSession)
|
||||
{
|
||||
m_XrSessionCreated = false;
|
||||
DEBUG("OnSessionDestroy() " + xrSession);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Wrapper Functions
|
||||
private const string ExtLib = "viveopenxr";
|
||||
|
||||
[DllImportAttribute(ExtLib, EntryPoint = "viveCompositionLayer_UpdateSystemProperties")]
|
||||
private static extern int VIVEOpenXR_ViveCompositionLayer_UpdateSystemProperties(XrInstance instance, XrSystemId system_id);
|
||||
private int ViveCompositionLayer_UpdateSystemProperties(XrInstance instance, XrSystemId system_id)
|
||||
{
|
||||
return VIVEOpenXR_ViveCompositionLayer_UpdateSystemProperties(instance, system_id);
|
||||
}
|
||||
|
||||
[DllImportAttribute(ExtLib, EntryPoint = "viveCompositionLayer_IsSupportSharpening")]
|
||||
private static extern bool VIVEOpenXR_ViveCompositionLayer_IsSupportSharpening();
|
||||
private bool ViveCompositionLayer_IsSupportSharpening()
|
||||
{
|
||||
return VIVEOpenXR_ViveCompositionLayer_IsSupportSharpening();
|
||||
}
|
||||
|
||||
[DllImportAttribute(ExtLib, EntryPoint = "viveCompositionLayer_enableSharpening")]
|
||||
private static extern int VIVEOpenXR_ViveCompositionLayer_enableSharpening(XrSharpeningModeHTC sharpeningMode, float sharpeningLevel);
|
||||
/// <summary>
|
||||
/// Enable the sharpening setting applying to the projection layer.
|
||||
/// </summary>
|
||||
/// <param name="sharpeningMode">The sharpening mode in <see cref="XrSharpeningModeHTC"/>.</param>
|
||||
/// <param name="sharpeningLevel">The sharpening level in float [0, 1].</param>
|
||||
/// <returns>True for success.</returns>
|
||||
public bool EnableSharpening(XrSharpeningModeHTC sharpeningMode, float sharpeningLevel)
|
||||
{
|
||||
return (VIVEOpenXR_ViveCompositionLayer_enableSharpening(sharpeningMode, sharpeningLevel) == 0);
|
||||
}
|
||||
|
||||
[DllImportAttribute(ExtLib, EntryPoint = "viveCompositionLayer_disableSharpening")]
|
||||
private static extern int VIVEOpenXR_ViveCompositionLayer_DisableSharpening();
|
||||
/// <summary>
|
||||
/// Disable the sharpening setting on the projection layer.
|
||||
/// </summary>
|
||||
/// <returns>True for success</returns>
|
||||
public bool DisableSharpening()
|
||||
{
|
||||
return (VIVEOpenXR_ViveCompositionLayer_DisableSharpening() == 0);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f26de592e4135874baf6e64cc94183be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright HTC Corporation All Rights Reserved.
|
||||
// Copyright HTC Corporation All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -67,65 +67,6 @@ namespace VIVE.OpenXR.CompositionLayer
|
||||
}
|
||||
|
||||
}
|
||||
public struct XrCompositionLayerFlags : IEquatable<UInt64>
|
||||
{
|
||||
private readonly UInt64 value;
|
||||
|
||||
public XrCompositionLayerFlags(UInt64 u)
|
||||
{
|
||||
value = u;
|
||||
}
|
||||
|
||||
public static implicit operator UInt64(XrCompositionLayerFlags xrBool)
|
||||
{
|
||||
return xrBool.value;
|
||||
}
|
||||
public static implicit operator XrCompositionLayerFlags(UInt64 u)
|
||||
{
|
||||
return new XrCompositionLayerFlags(u);
|
||||
}
|
||||
|
||||
public bool Equals(XrCompositionLayerFlags other)
|
||||
{
|
||||
return value == other.value;
|
||||
}
|
||||
public bool Equals(UInt64 other)
|
||||
{
|
||||
return value == other;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is XrCompositionLayerFlags && Equals((XrCompositionLayerFlags)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return value.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public static bool operator ==(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.Equals(b); }
|
||||
public static bool operator !=(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return !a.Equals(b); }
|
||||
public static bool operator >=(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value >= b.value; }
|
||||
public static bool operator <=(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value <= b.value; }
|
||||
public static bool operator >(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value > b.value; }
|
||||
public static bool operator <(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value < b.value; }
|
||||
public static XrCompositionLayerFlags operator +(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value + b.value; }
|
||||
public static XrCompositionLayerFlags operator -(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value - b.value; }
|
||||
public static XrCompositionLayerFlags operator *(XrCompositionLayerFlags a, XrCompositionLayerFlags b) { return a.value * b.value; }
|
||||
public static XrCompositionLayerFlags operator /(XrCompositionLayerFlags a, XrCompositionLayerFlags b)
|
||||
{
|
||||
if (b.value == 0)
|
||||
{
|
||||
throw new DivideByZeroException();
|
||||
}
|
||||
return a.value / b.value;
|
||||
}
|
||||
}
|
||||
|
||||
public struct XrSwapchainCreateFlags : IEquatable<UInt64>
|
||||
{
|
||||
@@ -288,6 +229,36 @@ namespace VIVE.OpenXR.CompositionLayer
|
||||
public XrColor4f colorScale;
|
||||
public XrColor4f colorBias;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct XrCompositionLayerSharpeningSettingHTC
|
||||
{
|
||||
public XrStructureType type;
|
||||
public IntPtr next;
|
||||
public XrSharpeningModeHTC mode;
|
||||
public float sharpeningLevel;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct XrCompositionLayerSuperSamplingSettingHTC
|
||||
{
|
||||
public XrStructureType type;
|
||||
public IntPtr next;
|
||||
public XrSuperSamplingModeHTC mode;
|
||||
}
|
||||
public enum XrSharpeningModeHTC
|
||||
{
|
||||
FAST = 0,
|
||||
NORMAL = 1,
|
||||
QUALITY = 2,
|
||||
AUTOMATIC = 3,
|
||||
}
|
||||
public enum XrSuperSamplingModeHTC
|
||||
{
|
||||
FAST = 0,
|
||||
NORMAL = 1,
|
||||
QUALITY = 2,
|
||||
AUTOMATIC = 3,
|
||||
}
|
||||
|
||||
public enum GraphicsAPI
|
||||
{
|
||||
GLES3 = 1,
|
||||
@@ -410,29 +381,6 @@ namespace VIVE.OpenXR.CompositionLayer
|
||||
}
|
||||
};
|
||||
/// <summary>
|
||||
/// The XrCompositionLayerBaseHeader structure is not intended to be directly used, but forms a basis for defining current and future structures containing composition layer information. The XrFrameEndInfo structure contains an array of pointers to these polymorphic header structures.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct XrCompositionLayerBaseHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// The XrStructureType of this structure.
|
||||
/// </summary>
|
||||
public XrStructureType type;
|
||||
/// <summary>
|
||||
/// Next is NULL or a pointer to the next structure in a structure chain, such as XrPassthroughMeshTransformInfoHTC.
|
||||
/// </summary>
|
||||
public IntPtr next;
|
||||
/// <summary>
|
||||
/// A bitmask of XrCompositionLayerFlagBits describing flags to apply to the layer.
|
||||
/// </summary>
|
||||
public XrCompositionLayerFlags layerFlags;
|
||||
/// <summary>
|
||||
/// The XrSpace in which the layer will be kept stable over time.
|
||||
/// </summary>
|
||||
public XrSpace space;
|
||||
};
|
||||
/// <summary>
|
||||
/// The application can specify the XrPassthroughColorHTC to adjust the alpha value of the passthrough. The range is between 0.0f and 1.0f, 1.0f means opaque.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
||||
@@ -18,7 +18,7 @@ using UnityEditor.XR.OpenXR.Features;
|
||||
namespace VIVE.OpenXR.CompositionLayer.Passthrough
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[OpenXRFeature(UiName = "VIVE XR Composition Layer (Passthrough)",
|
||||
[OpenXRFeature(UiName = "VIVE XR Composition Layer (Passthrough) (Deprecated)",
|
||||
Desc = "Enable this feature to use the HTC Passthrough feature.",
|
||||
Company = "HTC",
|
||||
DocumentationLink = "..\\Documentation",
|
||||
@@ -28,6 +28,7 @@ namespace VIVE.OpenXR.CompositionLayer.Passthrough
|
||||
FeatureId = featureId
|
||||
)]
|
||||
#endif
|
||||
[Obsolete("This class is deprecated. Please use VivePassthrough instead.")]
|
||||
public class ViveCompositionLayerPassthrough : OpenXRFeature
|
||||
{
|
||||
const string LOG_TAG = "VIVE.OpenXR.ViveCompositionLayerPassthrough";
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace VIVE.OpenXR.CompositionLayer.Passthrough
|
||||
{
|
||||
[Obsolete("This enumeration is deprecated. Please use XrStructureType instead.")]
|
||||
//[StructLayout(LayoutKind.Sequential)]
|
||||
public enum XrStructureTypeHTC
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace VIVE.OpenXR.CompositionLayer.Passthrough
|
||||
XR_TYPE_COMPOSITION_LAYER_PASSTHROUGH_HTC = 1000317004,
|
||||
}
|
||||
|
||||
[Obsolete("This enumeration is deprecated. Please use VIVE.OpenXR.Passthrough.PassthroughLayerForm instead.")]
|
||||
public enum PassthroughLayerForm
|
||||
{
|
||||
///<summary> Fullscreen Passthrough Form</summary>
|
||||
@@ -24,6 +26,7 @@ namespace VIVE.OpenXR.CompositionLayer.Passthrough
|
||||
Projected = 1
|
||||
}
|
||||
|
||||
[Obsolete("This enumeration is deprecated. Please use VIVE.OpenXR.Passthrough.ProjectedPassthroughSpaceType instead.")]
|
||||
public enum ProjectedPassthroughSpaceType
|
||||
{
|
||||
///<summary>
|
||||
|
||||
Reference in New Issue
Block a user