UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IStereoLayers.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 IStereoLayers.h: Abstract interface for adding in stereoscopically projected
5 layers on top of the world
6=============================================================================*/
7
8#pragma once
9
10#include "CoreMinimal.h"
11#include "StereoLayerShapes.h"
12#include "RHI.h"
13#include "HAL/Platform.h"
15#include "Engine/Texture.h"
16
18{
19
20 // The pointer to the shape of a stereo layer is wrapped in this simple class that clones and destroys the shape.
21 // This is to avoid having to implement non-default copy and assignment operations for the entire FLayerDesc struct.
22 struct FShapeWrapper
23 {
25 FShapeWrapper(IStereoLayerShape* InWrapped)
26 : Wrapped(InWrapped)
27 {}
28
29 FShapeWrapper(const FShapeWrapper& In) :
30 Wrapped(In.IsValid()?In.Wrapped->Clone():nullptr)
31 {}
32
33 FShapeWrapper(FShapeWrapper&& In)
34 {
35 Wrapped = MoveTemp(In.Wrapped);
36 }
37
38 FShapeWrapper& operator= (IStereoLayerShape* InWrapped)
39 {
41 return *this;
42 }
43
44 FShapeWrapper& operator= (const FShapeWrapper& In)
45 {
46 return operator=(In.IsValid() ? In.Wrapped->Clone() : nullptr);
47 }
48
49 FShapeWrapper& operator= (FShapeWrapper&& In)
50 {
51 Wrapped = MoveTemp(In.Wrapped);
52 return *this;
53 }
54
55 bool IsValid() const { return Wrapped.IsValid(); }
56 };
57
58public:
59
66
68 {
69 // Internally copies the texture on every frame for video, etc.
71 // Ignore the textures alpha channel, this makes the stereo layer opaque. Flag is ignored on Steam VR.
73 // Quad Y component will be calculated based on the texture dimensions
75 // The layer will intersect with the scene's depth. Currently only supported on Oculus platforms.
77 // Required on some platforms to enable rendering of external textures.
79 // When set, this layer will not be rendered.
80 LAYER_FLAG_HIDDEN = 0x00000020,
81 // When this is set and the HMD implementation is compatible, the layer will be copied to the spectator screen.
82 LAYER_FLAG_DEBUG = 0x00000040,
83 // Max flag value, update this when new flags are added!
85 };
86
87
92 {
93
95 : Shape(new FQuadLayer())
96 {
97 }
98
100 : Shape(InShape.Clone())
101 {
102 }
103
104 // silence warnings from uses of Texture and LeftTexture in generated constructors in Android builds
106 FLayerDesc(const FLayerDesc&) = default;
107 FLayerDesc(FLayerDesc&&) = default;
108 FLayerDesc& operator=(const FLayerDesc&) = default;
111
112 UE_DEPRECATED(5.6, "Reference the Id field directly")
114 UE_DEPRECATED(5.6, "Reference the Id field directly")
115 uint32 GetLayerId() const { return Id; }
117 bool HasValidTexture() const { return (TextureObj.IsValid() && TextureObj->GetResource() != nullptr) || Texture.IsValid(); }
119 bool IsVisible() const { return !(Flags & LAYER_FLAG_HIDDEN) && HasValidTexture(); }
120
121 // Layer IDs must be larger than 0
122 const static uint32 INVALID_LAYER_ID = 0;
123 // The layer's ID
125 // View space transform
127 // Size of rendered quad
129 // UVs of rendered quad in UE units
130 FBox2D UVRect = FBox2D(FVector2D(0.0f, 0.0f), FVector2D(1.0f, 1.0f));
131
132 // Size of texture that the compositor should allocate. Unnecessary if Texture is provided. The compositor will allocate a cubemap whose faces are of LayerSize if ShapeType is CubemapLayer.
134 // Render order priority, higher priority render on top of lower priority. Face-Locked layers are rendered on top of other layer types regardless of priority.
136 // Which space the layer is locked within
138 // which shape of layer it is. FQuadLayer is the only shape supported by all VR platforms.
139 // queries the shape of the layer at run time
140 template <typename T> bool HasShape() const { check(Shape.IsValid()); return Shape.Wrapped->GetShapeName() == T::ShapeName; }
141 // returns Shape cast to the supplied type. It's up to the caller to have ensured the cast is valid before calling this method.
142 template <typename T> T& GetShape() { check(HasShape<T>()); return *static_cast<T*>(Shape.Wrapped.Get()); }
143 template <typename T> const T& GetShape() const { check(HasShape<T>()); return *static_cast<const T*>(Shape.Wrapped.Get()); }
144 template <typename T, typename... InArgTypes> void SetShape(InArgTypes&&... Args) { Shape = FShapeWrapper(new T(Forward<InArgTypes>(Args)...)); }
145
146
147 // Texture mapped for right eye (if one texture provided, mono assumed)
148 // Layers known to the IStereoLayers will pin this texture in memory, preventing GC
150 UE_DEPRECATED(5.6, "Use TextureObj instead")
152 // Texture mapped for left eye (if one texture provided, mono assumed)
153 // Layers known to the IStereoLayers will pin this texture in memory, preventing GC
155 UE_DEPRECATED(5.6, "Use LeftTextureObj instead")
157 // Uses LAYER_FLAG_... -- See: ELayerFlags
159 private:
160 FShapeWrapper Shape;
161 };
162
163 PRAGMA_DISABLE_DEPRECATION_WARNINGS // for deprecated fields
166
174
180 virtual void DestroyLayer(uint32 LayerId) = 0;
181
200 virtual void PushLayerState(bool bPreserve = false) {};
201
207 virtual void PopLayerState() {}
208
212 virtual bool SupportsLayerState() { return false; }
213
221 virtual void HideBackgroundLayer() {}
222
227 virtual void ShowBackgroundLayer() {}
228
233 virtual bool IsBackgroundLayerVisible() const { return true; }
234
241 virtual void SetLayerDesc(uint32 LayerId, const FLayerDesc& InLayerDesc) = 0;
242
250 virtual bool GetLayerDesc(uint32 LayerId, FLayerDesc& OutLayerDesc) = 0;
251
260 virtual const FLayerDesc* FindLayerDesc(uint32 LayerId) const
261 {
262 return nullptr;
263 };
264
270 virtual void MarkTextureForUpdate(uint32 LayerId) = 0;
271
275 UE_DEPRECATED(5.6, "This unused function will be removed. Use IXRLoadingScreen::AddSplash instead")
277
281 UE_DEPRECATED(5.6, "Implement GetDebugLayerTextures_RenderThread instead.")
282 virtual bool ShouldCopyDebugLayersToSpectatorScreen() const final { return false; }
283
290
291public:
292 UE_DEPRECATED(5.6, "Use the UTextureRenderTarget2D overload instead.")
308
312 UE_DEPRECATED(5.6, "Implement GetDebugLayerTextures_RenderThread instead.")
314 {
315 Texture = nullptr;
316 LeftTexture = nullptr;
317 }
318
319protected:
321 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
322 bool bSplashIsShown = false;
323 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
324 bool bSplashShowMovie = false;
325 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
327 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
329 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
331 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
333 // UE_DEPRECATED(5.6, "Use IXRLoadingScreen::AddSplash instead")
336};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TTransform< double > FTransform
Definition MathFwd.h:53
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
FInt32Point FIntPoint
Definition MathFwd.h:124
UE::Math::TBox2< double > FBox2D
Definition MathFwd.h:56
UE_FORCEINLINE_HINT bool IsValid(const UObject *Test)
Definition Object.h:1875
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition UnrealType.h:3087
Definition StereoLayerShapes.h:28
Definition StereoLayerShapes.h:18
Definition IStereoLayers.h:18
virtual void SetLayerDesc(uint32 LayerId, const FLayerDesc &InLayerDesc)=0
virtual void HideBackgroundLayer()
Definition IStereoLayers.h:221
virtual TArray< FTextureRHIRef, TInlineAllocator< 2 > > GetDebugLayerTextures_RenderThread()
Definition IStereoLayers.h:289
virtual void GetAllocatedTexture(uint32 LayerId, FTextureRHIRef &Texture, FTextureRHIRef &LeftTexture)
Definition IStereoLayers.h:313
virtual bool GetLayerDesc(uint32 LayerId, FLayerDesc &OutLayerDesc)=0
virtual bool SupportsLayerState()
Definition IStereoLayers.h:212
ELayerFlags
Definition IStereoLayers.h:68
@ LAYER_FLAG_TEX_CONTINUOUS_UPDATE
Definition IStereoLayers.h:70
@ LAYER_FLAG_TEX_EXTERNAL
Definition IStereoLayers.h:78
@ LAYER_FLAG_MAX_VALUE
Definition IStereoLayers.h:84
@ LAYER_FLAG_DEBUG
Definition IStereoLayers.h:82
@ LAYER_FLAG_SUPPORT_DEPTH
Definition IStereoLayers.h:76
@ LAYER_FLAG_TEX_NO_ALPHA_CHANNEL
Definition IStereoLayers.h:72
@ LAYER_FLAG_HIDDEN
Definition IStereoLayers.h:80
@ LAYER_FLAG_QUAD_PRESERVE_TEX_RATIO
Definition IStereoLayers.h:74
virtual void PopLayerState()
Definition IStereoLayers.h:207
uint32 SplashLayerHandle
Definition IStereoLayers.h:334
FVector2D SplashScale
Definition IStereoLayers.h:332
ELayerType
Definition IStereoLayers.h:61
@ TrackerLocked
Definition IStereoLayers.h:63
@ WorldLocked
Definition IStereoLayers.h:62
@ FaceLocked
Definition IStereoLayers.h:64
virtual void DestroyLayer(uint32 LayerId)=0
virtual const FLayerDesc * FindLayerDesc(uint32 LayerId) const
Definition IStereoLayers.h:260
FTextureRHIRef SplashTexture
Definition IStereoLayers.h:326
virtual bool IsBackgroundLayerVisible() const
Definition IStereoLayers.h:233
virtual PRAGMA_ENABLE_DEPRECATION_WARNINGS uint32 CreateLayer(const FLayerDesc &InLayerDesc)=0
virtual void MarkTextureForUpdate(uint32 LayerId)=0
FTextureRHIRef SplashMovie
Definition IStereoLayers.h:328
virtual bool ShouldCopyDebugLayersToSpectatorScreen() const final
Definition IStereoLayers.h:282
virtual void PushLayerState(bool bPreserve=false)
Definition IStereoLayers.h:200
virtual FLayerDesc GetDebugCanvasLayerDesc(FTextureRHIRef Texture) final
Definition IStereoLayers.h:293
virtual void ShowBackgroundLayer()
Definition IStereoLayers.h:227
bool bSplashShowMovie
Definition IStereoLayers.h:324
virtual void UpdateSplashScreen() final
Definition IStereoLayers.h:276
PRAGMA_DISABLE_DEPRECATION_WARNINGS bool bSplashIsShown
Definition IStereoLayers.h:322
FVector SplashOffset
Definition IStereoLayers.h:330
Definition Array.h:670
UE_FORCEINLINE_HINT bool IsValid() const
Definition RefCounting.h:594
Definition UniquePtr.h:107
bool IsValid() const
Definition UniquePtr.h:280
Definition TextureRenderTarget2D.h:104
Definition Texture.h:1219
ENGINE_API FTextureResource * GetResource()
Definition Texture.cpp:250
Definition IStereoLayers.h:92
FVector2D QuadSize
Definition IStereoLayers.h:128
FLayerDesc & operator=(const FLayerDesc &)=default
PRAGMA_DISABLE_DEPRECATION_WARNINGS bool HasValidTexture() const
Definition IStereoLayers.h:117
FBox2D UVRect
Definition IStereoLayers.h:130
FLayerDesc()
Definition IStereoLayers.h:94
FTextureRHIRef Texture
Definition IStereoLayers.h:151
FLayerDesc(FLayerDesc &&)=default
static const uint32 INVALID_LAYER_ID
Definition IStereoLayers.h:122
bool HasShape() const
Definition IStereoLayers.h:140
FIntPoint LayerSize
Definition IStereoLayers.h:133
FLayerDesc(const IStereoLayerShape &InShape)
Definition IStereoLayers.h:99
uint32 Flags
Definition IStereoLayers.h:158
ELayerType PositionType
Definition IStereoLayers.h:137
int32 Priority
Definition IStereoLayers.h:135
PRAGMA_ENABLE_DEPRECATION_WARNINGS void SetLayerId(uint32 InId)
Definition IStereoLayers.h:113
T & GetShape()
Definition IStereoLayers.h:142
FLayerDesc & operator=(FLayerDesc &&)=default
void SetShape(InArgTypes &&... Args)
Definition IStereoLayers.h:144
const T & GetShape() const
Definition IStereoLayers.h:143
PRAGMA_DISABLE_DEPRECATION_WARNINGS FLayerDesc(const FLayerDesc &)=default
PRAGMA_ENABLE_DEPRECATION_WARNINGS bool IsVisible() const
Definition IStereoLayers.h:119
TWeakObjectPtr< class UTexture > TextureObj
Definition IStereoLayers.h:149
TWeakObjectPtr< class UTexture > LeftTextureObj
Definition IStereoLayers.h:154
uint32 GetLayerId() const
Definition IStereoLayers.h:115
FTextureRHIRef LeftTexture
Definition IStereoLayers.h:156
uint32 Id
Definition IStereoLayers.h:124
FTransform Transform
Definition IStereoLayers.h:126
Definition WeakObjectPtrTemplates.h:25
FORCEINLINE bool IsValid(bool bEvenIfPendingKill, bool bThreadsafeTest=false) const
Definition WeakObjectPtrTemplates.h:232
Definition IntPoint.h:25
static CORE_API const TTransform< double > Identity
Definition TransformNonVectorized.h:58
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79