Class OpenXRCustomLayerHandler<T>
Provides a base implementation for the Open
Inherited Members
Namespace: UnityEngine .XR.OpenXR .CompositionLayers
Assembly: Unity.XR.OpenXR.dll
Syntax
public abstract class OpenXRCustomLayerHandler<T> : OpenXRLayerProvider.ILayerHandler, IDisposable where T : struct
Type Parameters
Name | Description |
---|---|
T | The native OpenXR structure of the composition layer to handle. |
Remarks
The Open
The abstract methods that you must implement handle the custom aspects of your layer. These methods include:
- Create
Swapchain(Layer Info, out Swapchain Create Info) - Create
Native Layer(Layer Info, Swapchain Created Output, out T) - Modify
Native Layer(Layer Info, ref T)
You are not required to implement a custom layer handler based on this abstract class, but doing so should be
easier than implementing the Open
You must register your concrete layer handler object with
Register
Constructors
OpenXRCustomLayerHandler()
Initializes and returns an instance of this OpenXRCustomLayerHandler<T>
while also setting the singleton instance member.
Declaration
protected OpenXRCustomLayerHandler()
Fields
Instance
Singleton instance of this specific handler.
Declaration
protected static OpenXRCustomLayerHandler<T> Instance
Field Value
Type | Description |
---|---|
Open |
actionsForMainThread
Thread safe queue used to dispatch callbacks that may come from other threads such as the swapchain creation on the graphics thread.
Declaration
protected ConcurrentQueue<Action> actionsForMainThread
Field Value
Type | Description |
---|---|
Concurrent |
m_nativeLayers
Mapping of instance ids and native layer structs to help determine what layers are currently set to be active.
Declaration
protected Dictionary<int, T> m_nativeLayers
Field Value
Type | Description |
---|---|
Dictionary<int, T> |
Methods
ActiveNativeLayer(LayerInfo, ref T)
Override this method to modify a native composition layer struct in response to when it is active. An active compositon layer will invoke this every frame.
Declaration
protected virtual bool ActiveNativeLayer(CompositionLayerManager.LayerInfo layerInfo, ref T nativeLayer)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer that is active. |
T | nativeLayer | A reference to the native OpenXR structure of the composition layer that is active. |
Returns
Type | Description |
---|---|
bool | Bool indicating success or failure. A failure case will result in the native composition layer struct not being added into the final XrFrameEndInfo struct. |
CreateLayer(LayerInfo)
Implements the Open
Declaration
public void CreateLayer(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer being created. |
CreateNativeLayer(LayerInfo, SwapchainCreatedOutput, out T)
Declaration
protected abstract bool CreateNativeLayer(CompositionLayerManager.LayerInfo layerInfo, OpenXRCustomLayerHandler<T>.SwapchainCreatedOutput swapchainOutput, out T nativeLayer)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | |
Open |
swapchainOutput | |
T | nativeLayer |
Returns
Type | Description |
---|---|
bool |
CreateSwapchain(LayerInfo, out SwapchainCreateInfo)
Declaration
protected abstract bool CreateSwapchain(CompositionLayerManager.LayerInfo layerInfo, out OpenXRCustomLayerHandler<T>.SwapchainCreateInfo swapchainCreateInfo)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | |
Open |
swapchainCreateInfo |
Returns
Type | Description |
---|---|
bool |
CreateSwapchainAsync(LayerInfo)
Calls Create
Declaration
protected virtual void CreateSwapchainAsync(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer that was just created. |
Dispose()
Implements method from IDisposable that is called by the Open
Declaration
public void Dispose()
Dispose(bool)
Clears all maps and disposes any created native arrays.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Determines if this method was called from the Dispose() method or the finalizer. |
~OpenXRCustomLayerHandler()
Declaration
protected ~OpenXRCustomLayerHandler()
ModifyLayer(LayerInfo)
Implements the Open
Declaration
public virtual void ModifyLayer(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer that was modified. |
ModifyNativeLayer(LayerInfo, ref T)
Override this method to modify a native composition layer struct in response to changes on the associated Unity.XR.CompositionLayers.Layers.LayerData object or any extension components on the Unity.XR.CompositionLayers.CompositionLayer GameObject.
Declaration
protected abstract bool ModifyNativeLayer(CompositionLayerManager.LayerInfo layerInfo, ref T nativeLayer)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer that was modified. |
T | nativeLayer | A reference to the native OpenXR structure of the composition layer that was modified. The concrete implementation of this method should update the values of the structure as appropriate. |
Returns
Type | Description |
---|---|
bool | A bool indicating success or failure. |
Remarks
You must reinitialize the Next pointer with OpenXRLayerUtility.GetExtensionsChain(CompositionLayerManager.LayerInfo, Unity.XR.CompositionLayers.CompositionLayerExtension.ExtensionTarget) to get any potential updates from extension components.
Examples
Modifies an XrCompositionLayerQuad struct with new transform and extension information.
protected override bool ModifyNativeLayer(CompositionLayerManager.LayerInfo layerInfo, ref XrCompositionLayerQuad nativeLayer)
{
var data = layerInfo.Layer.LayerData as QuadLayerData;
var transform = layerInfo.Layer.GetComponent<Transform>();
nativeLayer.Pose = new XrPosef(transform.position, transform.rotation);
nativeLayer.Size = new XrExtend2Df()
{
width = data.GetScaledSize(transform.lossyScale).x,
height = data.GetScaledSize(transform.lossyScale).y
};
unsafe
{
nativeLayer.Next = OpenXRLayerUtility.GetExtensionsChain(layerInfo, CompositionLayerExtension.ExtensionTarget.Layer);
}
return true;
}
OnCreatedSwapchain(LayerInfo, SwapchainCreatedOutput)
This method is dispatched to the main thread inside On
Declaration
protected virtual void OnCreatedSwapchain(CompositionLayerManager.LayerInfo layerInfo, OpenXRCustomLayerHandler<T>.SwapchainCreatedOutput swapchainOutput)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer that was just created. |
Open |
swapchainOutput | Information regarding the swapchain that was created for this layer, such as the associated swapchain handle. |
OnUpdate()
Implements the Open
Declaration
public virtual void OnUpdate()
Remarks
This implementation carries out two tasks. It dequeues actions for the main thread like dispatch when
the swapchain has been
created and it adds all the active layers to the endFrameInfo
struct in the native UnityOpenXR lib.
RemoveLayer(int)
Implements the Open
Declaration
public virtual void RemoveLayer(int removedLayerId)
Parameters
Type | Name | Description |
---|---|---|
int | removedLayerId | The instance id of the CompositionLayer component that was removed. |
ResizeNativeArrays()
Ensures that the native arrays are of the same size as the m_nativeLayers map.
Declaration
protected virtual void ResizeNativeArrays()
SetActiveLayer(LayerInfo)
Implements the Open
Declaration
public virtual void SetActiveLayer(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
Layer |
layerInfo | Container for the instance id and CompositionLayer component of the composition layer being set to active. |