Class OpenXRLayerUtility
A general-purpose helper class for composition layer support.
Inherited Members
Namespace: UnityEngine.XR.OpenXR.CompositionLayers
Assembly: Unity.XR.OpenXR.dll
Syntax
public static class OpenXRLayerUtility
Methods
AddActiveLayersToEndFrame(void*, void*, int, int)
Add native layer structs to the endFrameInfo
struct inside the UnityOpenXR lib - for custom layer type support
Declaration
public static void AddActiveLayersToEndFrame(void* layers, void* orders, int count, int layerByteSize)
Parameters
Type | Name | Description |
---|---|---|
void* | layers | Pointer to the native array of currently active composition layers. |
void* | orders | Pointer to the native array of order values for the currently active composition layers. |
int | count | Indicates the size of the layers and orders arrays. |
int | layerByteSize | Indicates the size in bytes of a single element of the given array of composition layers. |
Remarks
Layers sent must all be of the same type.Demonstrated in the OpenXRCustomLayerHandler class.
CreateStereoSwapchain(int, XrSwapchainCreateInfo, StereoSwapchainCallbackDelegate)
Create the XrSwapchainCreateInfo struct that is passed to OpenXR SDK to create a swapchain for stereo projection, like Projection layer type.
Declaration
public static void CreateStereoSwapchain(int layerId, XrSwapchainCreateInfo createInfo, OpenXRLayerUtility.StereoSwapchainCallbackDelegate callback = null)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
XrSwapchainCreateInfo | createInfo | The struct used to create the swapchain. |
OpenXRLayerUtility.StereoSwapchainCallbackDelegate | callback | Optional parameter that can be used if your composition layer needs to know the handles after swapchain creation. |
CreateSwapchain(int, XrSwapchainCreateInfo, bool, SwapchainCallbackDelegate)
Create the XrSwapchainCreateInfo struct that is passed to OpenXR SDK to create a swapchain.
Declaration
public static void CreateSwapchain(int layerId, XrSwapchainCreateInfo createInfo, bool isExternalSurface = false, OpenXRLayerUtility.SwapchainCallbackDelegate callback = null)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
XrSwapchainCreateInfo | createInfo | The struct used to create the swapchain. |
bool | isExternalSurface | Optional parameter that can be used when an external surface will be used, like when using the Android Surface feature. |
OpenXRLayerUtility.SwapchainCallbackDelegate | callback | Optional parameter that can be used if your composition layer needs to know the handle after swapchain creation. |
FindAndWriteToRenderTexture(LayerInfo, Texture, out RenderTexture)
Query the correct XR Textures for rendering and blit the layer textures.
Declaration
[Obsolete("OpenXRLayerUtility.FindAndWriteToRenderTexture is deprecated. If you want to query for a swapchain render texture then use OpenXRLayerUtility.RequestRenderTextureId instead", false)]
public static bool FindAndWriteToRenderTexture(CompositionLayerManager.LayerInfo layerInfo, Texture texture, out RenderTexture renderTexture)
Parameters
Type | Name | Description |
---|---|---|
LayerInfo | layerInfo | Container for the instance id and CompositionLayer component of the composition layer. |
Texture | texture | The source texture that will be written into the provided render texture. |
RenderTexture | renderTexture | The render texture that will be searched for and written to. Will be null if no render texture can be found for the provided layerInfo object. |
Returns
Type | Description |
---|---|
bool | True if a render texture was found and written to, false if the provided texture is null or if no render texture was found for the provided layerInfo object. |
FindAndWriteToStereoRenderTextures(LayerInfo, out RenderTexture, out RenderTexture)
Query the correct XR Textures for rendering and blit the layer textures (For Projection Layer type).
Declaration
[Obsolete("OpenXRLayerUtility.FindAndWriteToStereoRenderTextures is deprecated. If you want to query for a stereo swapchain render texture then use OpenXRLayerUtility.RequestStereoRenderTextureId instead", false)]
public static bool FindAndWriteToStereoRenderTextures(CompositionLayerManager.LayerInfo layerInfo, out RenderTexture renderTextureLeft, out RenderTexture renderTextureRight)
Parameters
Type | Name | Description |
---|---|---|
LayerInfo | layerInfo | Container for the instance id and CompositionLayer component of the composition layer. |
RenderTexture | renderTextureLeft | The left stereo render texture that will be searched for and written to. Will be null if no render textures can be found for the provided layerInfo object. |
RenderTexture | renderTextureRight | The right stereo render texture that will be searched for and written to. Will be null if no render textures can be found for the provided layerInfo object. |
Returns
Type | Description |
---|---|
bool | True if both render textures were found and written to, false if no texture was found on the TexturesExtension component of the layerInfo object or if no render texture was found for the provided layerInfo object. |
FindRenderTexture(LayerInfo)
Finds the render texture of the layer id.
Declaration
[Obsolete("OpenXRLayerUtility.FindRenderTexture is deprecated. If you want to query for a swapchain render texture then use OpenXRLayerUtility.RequestRenderTextureId instead", false)]
public static RenderTexture FindRenderTexture(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
LayerInfo | layerInfo | Container for the instance id and CompositionLayer component of the composition layer. |
Returns
Type | Description |
---|---|
RenderTexture | The render texture with the provided id or null if no render textrue with that id was found. |
FindRenderTexture(uint)
Finds the render texture of the give texture id.
Declaration
public static RenderTexture FindRenderTexture(uint texId)
Parameters
Type | Name | Description |
---|---|---|
uint | texId | The id of the render texture to find. |
Returns
Type | Description |
---|---|
RenderTexture | The render texture with the provided id or null if no render textrue with that id was found. |
GetCurrentAppSpace()
Helper method used get the current app space for any native composition layer structs that may require an associated XrSpace.
Declaration
public static ulong GetCurrentAppSpace()
Returns
Type | Description |
---|---|
ulong | A handle to the current app space. |
Remarks
Normally used when creating native composition layers.
GetDefaultColorFormat()
Return swapchain supported color format.
Declaration
public static long GetDefaultColorFormat()
Returns
Type | Description |
---|---|
long | The color format the swapchains will be using. |
GetExtensionsChain(LayerInfo, ExtensionTarget)
Helper method used to gather the extension components attached to a CompositionLayer GameObject. This method chains the native extension struct pointers of those extension components to initialize an OpenXR native object's Next pointer struct chain.
Declaration
public static void* GetExtensionsChain(CompositionLayerManager.LayerInfo layerInfo, CompositionLayerExtension.ExtensionTarget extensionTarget)
Parameters
Type | Name | Description |
---|---|---|
LayerInfo | layerInfo | Container for the instance id and CompositionLayer component of the composition layer. |
ExtensionTarget | extensionTarget | Represents what part of the composition layer to retrieve extensions for. |
Returns
Type | Description |
---|---|
void* | A pointer to the head of an array of native extension objects that will be associated with a composition layer. |
GetLayerAndroidSurfaceObject(int)
Return the Surface object for Android External Surface support (Android only).
Declaration
public static IntPtr GetLayerAndroidSurfaceObject(int layerId)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
Returns
Type | Description |
---|---|
IntPtr | Pointer to the android surface object. |
GetXRSession()
Helper method used get the XR session handle for any native composition layer structs that may require an associated XrSession.
Declaration
public static ulong GetXRSession()
Returns
Type | Description |
---|---|
ulong | A handle to the current xr session. |
ReleaseSwapchain(LayerInfo)
Releases the swapchain image associated with the layer id.
Declaration
[Obsolete("OpenXRLayerUtility.ReleaseSwapchain is deprecated. Swapchains are all automatically released by the graphics thread.", false)]
public static void ReleaseSwapchain(CompositionLayerManager.LayerInfo layerInfo)
Parameters
Type | Name | Description |
---|---|---|
LayerInfo | layerInfo | Container for the instance id and CompositionLayer component of the composition layer. |
ReleaseSwapchain(int)
Release and Destroy the swapchain according to the id provided.
Declaration
public static void ReleaseSwapchain(int layerId)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
RequestRenderTextureId(int, RenderTextureIdCallbackDelegate)
Submits a request to create or get an available render texture associated with the swapchain of the given layer id.
Declaration
public static void RequestRenderTextureId(int layerId, OpenXRLayerUtility.RenderTextureIdCallbackDelegate callback)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
OpenXRLayerUtility.RenderTextureIdCallbackDelegate | callback | Callback that will be invoked with the current render texture id to use for the layer's swapchain. |
Remarks
The callback will be invoked on the graphics thread. Work on the render texture must be done anywhere within the scene rendering phase (such as Application.OnBeforeRender).
RequestStereoRenderTextureIds(int, StereoRenderTextureIdsCallbackDelegate)
Submits a request to create or get an available stereo render texture associated with the stereo swapchain of the given layer id.
Declaration
public static void RequestStereoRenderTextureIds(int layerId, OpenXRLayerUtility.StereoRenderTextureIdsCallbackDelegate callback)
Parameters
Type | Name | Description |
---|---|---|
int | layerId | The instance id of the composition layer object. |
OpenXRLayerUtility.StereoRenderTextureIdsCallbackDelegate | callback | Callback that will be invoked with the current stereo render texture ids to use for the layer's swapchain |
Remarks
The callback will be invoked on the graphics thread. Work on the render textures must be done anywhere within the scene rendering phase (such as Application.OnBeforeRender).
SetDefaultLayerFlags(XrCompositionLayerFlags)
Sends what flags are to be added to the native default compostion layer.
Declaration
public static void SetDefaultLayerFlags(XrCompositionLayerFlags flags)
Parameters
Type | Name | Description |
---|---|---|
XrCompositionLayerFlags | flags | Flags to be added to the native default compostion layer. |
Remarks
Currently only called by the OpenXRDefautLayer class.
SetDefaultSceneLayerExtensions(void*)
Sends an array of extensions to be attached to the native default compostion layer.
Declaration
public static void SetDefaultSceneLayerExtensions(void* extensions)
Parameters
Type | Name | Description |
---|---|---|
void* | extensions | Pointer to the array of extensions to attach to the default compostion layer. |
Remarks
Currently only called by the OpenXRDefautLayer class.
WriteToRenderTexture(Texture, RenderTexture)
Handles transfering texture data to a render texture.
Declaration
public static void WriteToRenderTexture(Texture texture, RenderTexture renderTexture)
Parameters
Type | Name | Description |
---|---|---|
Texture | texture | The source texture that will be written into the provided render texture. |
RenderTexture | renderTexture | The render texture that will be written to. |