UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MetalViewport.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 MetalViewport.h: Metal viewport RHI definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "MetalRHIPrivate.h"
10#include "PixelFormat.h"
11#include "RHIResources.h"
12#include "MetalResources.h"
13
14#if PLATFORM_MAC
15#include "Mac/CocoaTextView.h"
16@interface FMetalView : FCocoaTextView
17@end
18#endif
20
21#if PLATFORM_VISIONOS
22#import <CompositorServices/CompositorServices.h>
23#endif
24
25class FMetalSurface;
26class FMetalDevice;
27
35
37
38#if PLATFORM_VISIONOS
39namespace MetalRHIVisionOS
40{
43}
44#endif
45
47
49{
50public:
53
55
56 TRefCountPtr<FMetalSurface> GetBackBuffer(EMetalViewportAccessFlag Accessor) const;
57 CA::MetalDrawable* GetDrawable(EMetalViewportAccessFlag Accessor);
58 MTL::Texture* GetDrawableTexture(EMetalViewportAccessFlag Accessor);
59 MTL::Texture* GetCurrentTexture(EMetalViewportAccessFlag Accessor);
60 void ReleaseDrawable(void);
61
62 // supports pulling the raw MTLTexture
63 virtual void* GetNativeBackBufferTexture() const override { return GetBackBuffer(EMetalViewportAccessRenderer).GetReference(); }
64 virtual void* GetNativeBackBufferRT() const override { return (const_cast<FMetalViewport *>(this))->GetDrawableTexture(EMetalViewportAccessRenderer); }
65
66#if PLATFORM_MAC
67 NSWindow* GetWindow() const;
68#endif
69
70#if PLATFORM_MAC || PLATFORM_VISIONOS
71 virtual void SetCustomPresent(FRHICustomPresent* InCustomPresent) override
72 {
73 CustomPresent = InCustomPresent;
74 }
75
76 virtual FRHICustomPresent* GetCustomPresent() const override { return CustomPresent; }
77#endif
78
79 void Present(FMetalCommandQueue& CommandQueue, bool bLockToVsync);
80 void Swap();
81
82#if PLATFORM_VISIONOS
84 void PresentImmersive(const MetalRHIVisionOS::PresentImmersiveParams* Params);
85#endif
86
87private:
88 uint32 GetViewportIndex(EMetalViewportAccessFlag Accessor) const;
89
90private:
91#if PLATFORM_VISIONOS
93#endif
94
95 FMetalDevice& Device;
96 CA::MetalDrawable* Drawable;
97 TRefCountPtr<FMetalSurface> BackBuffer[2];
98 mutable FCriticalSection Mutex;
99
100 MTL::Texture* DrawableTextures[2];
101
102 uint32 DisplayID;
104 volatile int32 FrameAvailable;
105 TRefCountPtr<FMetalSurface> LastCompleteFrame;
106 bool bIsFullScreen;
107
108#if PLATFORM_IOS && !PLATFORM_TVOS && !PLATFORM_VISIONOS
109 uint32 SizeX;
110 uint32 SizeY;
115#endif
116
117#if PLATFORM_MAC
118 FMetalView* View;
119#endif
120
121#if PLATFORM_MAC || PLATFORM_VISIONOS
122 FCustomPresentRHIRef CustomPresent;
123#endif
124};
125
126template<>
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
EMetalViewportAccessFlag
Definition MetalViewport.h:29
@ EMetalViewportAccessRenderer
Definition MetalViewport.h:31
@ EMetalViewportAccessDisplayLink
Definition MetalViewport.h:33
@ EMetalViewportAccessRHI
Definition MetalViewport.h:30
@ EMetalViewportAccessGame
Definition MetalViewport.h:32
void(^ FMetalViewportPresentHandler)(uint32 CGDirectDisplayID, double OutputSeconds, double OutputDuration)
Definition MetalViewport.h:46
EPixelFormat
Definition PixelFormat.h:16
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CocoaTextView.cpp:7
Definition IDelegateInstance.h:14
Definition MetalCommandQueue.h:39
Definition MetalDevice.h:102
Definition MetalResources.h:206
Definition MetalViewport.h:49
virtual void * GetNativeBackBufferTexture() const override
Definition MetalViewport.h:63
virtual void * GetNativeBackBufferRT() const override
Definition MetalViewport.h:64
Definition RHIResources.h:4294
Definition RHIResources.h:2515
Definition RefCounting.h:454
UE_FORCEINLINE_HINT ReferencedType * GetReference() const
Definition RefCounting.h:584
UE::FRecursiveMutex Mutex
Definition MeshPaintVirtualTexture.cpp:164
FMetalViewport TConcreteType
Definition MetalViewport.h:129
Definition MetalRHIPrivate.h:204