TStereoLayerManager

Partial implementation of the Layer management code for the [IStereoLayers](API\Runtime\Engine\IStereoLayers) interface.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

HeadMountedDisplay

Header

/Engine/Source/Runtime/HeadMountedDisplay/Public/StereoLayerManager.h

Include

#include "StereoLayerManager.h"

Syntax

template<typename LayerType>
class TStereoLayerManager : public IStereoLayers

Remarks

Partial implementation of the Layer management code for the IStereoLayers interface. Implements adding, deleting and updating layers regardless of how they are rendered.

A class that wishes to implement the IStereoLayer interface can extend this class instead. The template argument should be a type for storing layer data. It should have a constructor matching the following: LayerType(const FLayerDesc& InLayerDesc); ... and implement the following function overloads: void SetLayerId(uint32 InId), uint32 GetLayerId() const, bool GetLayerDescMember(LayerType& Layer, FLayerDesc& OutLayerDesc), void SetLayerDescMember(LayerType& Layer, const FLayerDesc& Desc), and void MarkLayerTextureForUpdate(LayerType& Layer)

To perform additional bookkeeping each time individual layers are changed, you can override the following protected method: UpdateLayer(LayerType& Layer, uint32 LayerId, bool bIsValid) It is called whenever CreateLayer, DestroyLayer, SetLayerDesc and MarkTextureForUpdate are called.

Simple implementations that do not to track additional data per layer may use FLayerDesc directly. The FSimpleLayerManager subclass can be used in that case and it implements all the required glue functions listed above.

To access the layer data from your subclass, you have the following protected interface: bool GetStereoLayersDirty() Returns true if layer data have changed since the status was last cleared ForEachLayer(...) pass in a lambda to iterate through each existing layer. CopyLayers(TArray<LayerType>& OutArray, bool bMarkClean = true) Copies the layers into OutArray. CopySortedLayers(TArray<LayerType>& OutArray, bool bMarkClean = true) Copies the layers into OutArray sorted by their priority. WithLayer(uint32 LayerId, TFunction<void(LayerType*)> Func) Finds the layer by Id and passes it to Func or nullptr if not found. The last two methods will clear the layer dirty flag unless you pass in false as the optional final argument.

Thread safety: Updates and the two protected access methods use a critical section to ensure atomic access to the layer structures. Therefore, it is probably better to copy layers before performing time consuming operations using CopyLayers and reserve ForEachLayer for simple processing or operations where you need to know the user-facing layer id. The WithLayer method is useful if you already know the id of a layer you need to access in a thread safe manner.

Constructors

Name Description

Public function

TStereoLayerManager()

Destructors

Name Description

Public function Virtual

~TStereoLayerManager()

Functions

Name Description

Protected function

void

 

CopyLayers

(
    TArray< LayerType >& OutArray,
    bool bMarkClean
)

Protected function

void

 

CopySortedLayers

(
    TArray< LayerType >& OutArray,
    bool bMarkClean
)

Protected function

void

 

ForEachLayer

(
    TFunction< void, LayerType&...,
    bool bMarkClean
)

Protected function

bool

 

GetStereoLayersDirty()

Protected function Virtual Const

void

 

UpdateLayer

(
    LayerType& Layer,
    uint32 LayerId,
    bool bIsValid
)

Protected function

void

 

WithLayer

(
    uint32 LayerId,
    TFunction< void> F...
)

Overridden from IStereoLayers

Name Description

Public function Virtual

uint32

 

CreateLayer

(
    const FLayerDesc& InLayerDesc
)

Creates a new layer from a given texture resource, which is projected on top of the world as a quad.

Public function Virtual

void

 

DestroyLayer

(
    uint32 LayerId
)

Destroys the specified layer, stopping it from rendering over the world.

Public function Virtual

void

 

GetAllocatedTexture

(
    uint32 LayerId,
    FTextureRHIRef& Texture,
    FTextureRHIRef& LeftTexture
)

Get texture reference to HMD swapchain to avoid the copy path, useful for continuous update layers

Public function Virtual

bool

 

GetLayerDesc

(
    uint32 LayerId,
    FLayerDesc& OutLayerDesc
)

Get the currently set layer description

Public function Virtual

void

 

HideBackgroundLayer()

Optional method to hide the 3D scene and only render the stereo overlays.

Public function Virtual Const

bool

 

IsBackgroundLayerVisible()

Tell if the background layer is visible.

Public function Virtual

void

 

MarkTextureForUpdate

(
    uint32 LayerId
)

Marks this layers texture for update

Public function Virtual

void

 

PopLayerState()

Restores the stereo layer state from the last save state.

Public function Virtual

void

 

PushLayerState

(
    bool bPreserve
)

Saves the current stereo layer state on a stack to later restore them.

Public function Virtual

void

 

SetLayerDesc

(
    uint32 LayerId,
    const FLayerDesc& InLayerDesc
)

Set the a new layer description

Public function Virtual

void

 

ShowBackgroundLayer()

Optional method to undo the effect of hiding the 3D scene. No-op if not supported by the platform.

Public function Virtual

bool

 

SupportsLayerState()

Returns true if the StereoLayers implementation supports saving and restoring state using Push/PopLayerState()

Public function Virtual

void

 

UpdateSplashScreen()

Update splash screens from current state

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss