// Copyright HTC Corporation All Rights Reserved.
using System;
using System.Runtime.InteropServices;
namespace VIVE.OpenXR.Feature
{
public interface IViveFeatureWrapper
{
///
/// OnInstanceCreate might be called multiple times. Because many features might be using the same instance.
///
///
///
///
public bool OnInstanceCreate(XrInstance xrInstance, IntPtr xrGetInstanceProcAddr);
///
/// OnInstanceDestroy might be called multiple times. Because many features might be using the same instance.
///
public void OnInstanceDestroy();
}
public class ViveFeatureWrapperBase where T : ViveFeatureWrapperBase, new()
{
private static readonly Lazy lazyInstance = new Lazy(() => new T());
public static T Instance => lazyInstance.Value;
// Set true in yourfeature's OnInstanceCreate
public bool IsInited { get; protected set; } = false;
///
/// If the feature is inited not successfully, Set this true. Use to avoid multiple inits.
///
public bool TryInited { get; protected set; } = false;
public OpenXRHelper.xrGetInstanceProcAddrDelegate xrGetInstanceProcAddr;
///
/// Complete the xrGetInstanceProcAddr by set the pointer received in OnInstanceCreate
///
///
public void SetGetInstanceProcAddrPtr(IntPtr intPtr)
{
if (intPtr == null || intPtr == IntPtr.Zero)
throw new Exception("xrGetInstanceProcAddr is null");
xrGetInstanceProcAddr = Marshal.GetDelegateForFunctionPointer(intPtr);
}
}
}