UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DrawElements.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "Tasks/Task.h"
10
15class SWidget;
16class SWindow;
17struct FSlateBrush;
20
39
41
98
99
106{
108
110 void ClearCachedElements();
111 void RemoveFromCache();
112
113 bool IsOwnedByWidget(const SWidget* Widget) const;
114
115 bool IsValid() const { return Ptr.IsValid(); }
116 bool HasCachedElements() const;
117
118 bool operator!=(FSlateCachedElementsHandle& Other) const { return Ptr != Other.Ptr; }
119
121private:
123 : Ptr(DataPtr)
124 {
125 }
126
127private:
129};
130
140{
143
145 void Empty();
146
149
151
153
154 template<EElementType ElementType>
156 {
158
159 TSharedPtr<FSlateCachedElementList> List = CacheHandle.Ptr.Pin();
160
161#if WITH_SLATE_DEBUGGING
163#endif
164
165 FSlateDrawElementArray<FSlateElementType>& Container = List->DrawElements.Get<(uint8)ElementType>();
166 FSlateElementType& NewElement = Container.AddDefaulted_GetRef();
167 NewElement.SetIsCached(true);
168
169 // Check if slow vs checking a flag on the list to see if it contains new data.
170 ListsWithNewData.AddUnique(List.Get());
171
173
175 {
176 // We need to cache this clip state for the next time the element draws
178 List->AddCachedClipState(CachedClipState);
179 NewElement.SetCachedClippingState(&CachedClipState.ClippingState.Get());
180 }
181
182 return NewElement;
183 }
184
186 void RemoveCachedRenderBatches(const TArray<int32>& CachedRenderBatchIndices);
187
190
191 const TSparseArray<FSlateRenderBatch>& GetCachedBatches() const { return CachedBatches; }
192 const TArray<TSharedPtr<FSlateCachedElementList>>& GetCachedElementLists() const { return CachedElementLists; }
193
195
196 TArrayView<FSlateCachedElementList* const> GetListsWithNewData() const { return MakeArrayView(ListsWithNewData.GetData(), ListsWithNewData.Num()); }
197private:
199 void RemoveList(FSlateCachedElementsHandle& CacheHandle);
200
201private:
202
205
208
211
213 TArray<FSlateCachedClipState> CachedClipStates;
214};
215
220{
222public:
230
232
235 {
237 return WeakPaintWindow.IsValid() ? RawPaintWindow : nullptr;
238 }
239
242 {
244 // Note: This assumes that the PaintWindow is safe to pin and is not accessed by another thread
245 return RenderTargetWindow != nullptr ? RenderTargetWindow : GetPaintWindow();
246 }
247
250 {
251 return UncachedDrawElements;
252 }
253
259
264 template<EElementType ElementType = EElementType::ET_NonMapped>
266 {
268
269 const bool bAllowCache = CachedElementDataListStack.Num() > 0 && WidgetDrawStack.Num() && !WidgetDrawStack.Top().bIsVolatile;
270
271 if (bAllowCache)
272 {
273 // @todo get working with slate debugging
275 }
276 else
277 {
278 FSlateDrawElementMap& Elements = UncachedDrawElements;
279 FSlateDrawElementArray<FSlateElementType>& Container = Elements.Get<(uint8)ElementType>();
280 const int32 InsertIdx = Container.AddDefaulted();
281
282#if WITH_SLATE_DEBUGGING
285#endif
286
288 return NewElement;
289 }
290 }
291
296
297
298 //--------------------------------------------------------------------------
299 // CLIPPING
300 //--------------------------------------------------------------------------
301
304 int32 GetClippingStackDepth() const { return ClippingManager.GetStackDepth(); }
306 SLATECORE_API void PopClip();
308
309
310 FSlateClippingManager& GetClippingManager() { return ClippingManager; }
311 const FSlateClippingManager& GetClippingManager() const { return ClippingManager; }
312
313 //--------------------------------------------------------------------------
314 // PIXEL SNAPPING
315 //--------------------------------------------------------------------------
316
320
321 //--------------------------------------------------------------------------
322 // DEFERRED PAINTING
323 //--------------------------------------------------------------------------
324
330 {
331 public:
333
334 SLATECORE_API int32 ExecutePaint(int32 LayerId, FSlateWindowElementList& OutDrawElements, const FSlateRect& MyCullingRect) const;
335
337
338 private:
339 // Used for making copies.
340 FDeferredPaint(const FDeferredPaint& Copy, const FPaintArgs& InArgs);
341
342 const TWeakPtr<const SWidget> WidgetToPaintPtr;
343 const FPaintArgs Args;
344 const FGeometry AllottedGeometry;
345 const FWidgetStyle WidgetStyle;
346 const bool bParentEnabled;
347 };
348
350
351 int32 PaintDeferred(int32 LayerId, const FSlateRect& MyCullingRect);
352
353 bool ShouldResolveDeferred() const { return bNeedsDeferredResolve; }
354
357
358 TArray< TSharedPtr<FDeferredPaint> > GetDeferredPaintList() const { return DeferredPaintList; }
359
360
361 //--------------------------------------------------------------------------
362 // FAST PATH
363 //--------------------------------------------------------------------------
364
371
377
379 void PushCachedElementData(FSlateCachedElementData& CachedElementData);
381
382 //--------------------------------------------------------------------------
383 // OTHER
384 //--------------------------------------------------------------------------
385
390
391
393 {
394 FinishMergeRenderBatches();
395 return BatchData;
396 }
397
399 {
400 FinishMergeRenderBatches();
401 return BatchDataHDR;
402 }
403
405
407
410
412 {
413 if (GetCurrentCachedElementData() != nullptr)
414 {
415 return CachedElementDataList[CachedElementDataListStack.Top()]->GetListsWithNewData();
416 }
417 else
418 {
420 }
421 }
422private:
424 template<EElementType ElementType>
425 TSlateDrawElement<ElementType>& AddCachedElement()
426 {
427 FSlateCachedElementData* CurrentCachedElementData = GetCurrentCachedElementData();
429
430 FWidgetDrawElementState& CurrentWidgetState = WidgetDrawStack.Top();
431 check(!CurrentWidgetState.bIsVolatile);
432
433 if (!CurrentWidgetState.CacheHandle.IsValid())
434 {
435 CurrentWidgetState.CacheHandle = CurrentCachedElementData->AddCache(CurrentWidgetState.Widget);
436 }
437
438 return CurrentCachedElementData->AddCachedElement<ElementType>(CurrentWidgetState.CacheHandle, GetClippingManager(), CurrentWidgetState.Widget);
439 }
440
441 TArrayView<FSlateCachedElementData* const> GetCachedElementDataList() const { return MakeArrayView(CachedElementDataList.GetData(), CachedElementDataList.Num()); }
442
443 FSlateCachedElementData* GetCurrentCachedElementData() const { return CachedElementDataListStack.Num() ? CachedElementDataList[CachedElementDataListStack.Top()] : nullptr; }
444
445 SLATECORE_API void StartMergeRenderBatches();
446 SLATECORE_API void FinishMergeRenderBatches();
447
448private:
453 TWeakPtr<SWindow> WeakPaintWindow;
454 SWindow* RawPaintWindow;
455
456 FMemStackBase MemManager;
463 SWindow* RenderTargetWindow;
464
466 FSlateBatchData BatchData;
467
469 FSlateBatchData BatchDataHDR;
470
471 UE::Tasks::FTask MergeBatchDataTask;
472
474 FSlateClippingManager ClippingManager;
475
477 TArray<EWidgetPixelSnapping, TInlineAllocator<4>> PixelSnappingMethodStack;
478
483 TArray< TSharedPtr<FDeferredPaint> > DeferredPaintList;
484
485 bool bNeedsDeferredResolve;
486 TArray<int32> ResolveToDeferredIndex;
487
488 // Begin Fast Path
489
491 struct FWidgetDrawElementState
492 {
493 FWidgetDrawElementState(FSlateCachedElementsHandle& InCurrentHandle, bool bInIsVolatile, const SWidget* InWidget)
494 : CacheHandle(InCurrentHandle)
496 , bIsVolatile(bInIsVolatile)
497 {
498 }
499
500 FSlateCachedElementsHandle CacheHandle;
501 const SWidget* Widget;
502 bool bIsVolatile;
503 };
504
506 FSlateDrawElementMap UncachedDrawElements;
507
510 TArray<int32, TInlineAllocator<4>> CachedElementDataListStack;
511 // End Fast Path
512
514 FVector2f WindowSize;
515
517 bool bIsInGameLayer;
518};
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define STAT(x)
Definition Stats.h:44
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EElementType
Definition DrawElementCoreTypes.h:35
typename TTupleElement<(uint8) ElementType, FSlateDrawElementMap >::Type::ElementType TSlateDrawElement
Definition DrawElementCoreTypes.h:200
ESlateDrawPrimitive
Definition RenderingCommon.h:49
ESlateBatchDrawFlag
Definition RenderingCommon.h:118
ESlateDrawEffect
Definition RenderingCommon.h:89
ESlateShader
Definition RenderingCommon.h:60
CORE_API bool IsInSlateThread()
Definition ThreadingBase.cpp:222
CORE_API bool IsInGameThread()
Definition ThreadingBase.cpp:185
EWidgetPixelSnapping
Definition WidgetPixelSnapping.h:15
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition MemStack.h:78
Definition UnrealTemplate.h:321
Definition PaintArgs.h:23
Definition UObjectGlobals.h:2492
Definition ElementBatcher.h:154
Definition Clipping.h:329
TSharedRef< FSlateClippingState, ESPMode::ThreadSafe > ClippingState
Definition Clipping.h:335
Definition Clipping.h:343
int32 GetStackDepth() const
Definition Clipping.h:356
Definition Clipping.h:207
Definition Clipping.h:61
static SLATECORE_API FDrawElementType ElementTypeAdded
Definition SlateDebugging.h:326
Definition DrawElementTypes.h:46
Definition ElementBatcher.h:246
Definition SlateRect.h:26
Definition SlateRenderBatch.h:45
Definition SlateResourceHandle.h:16
Definition SlateShaderResource.h:44
Definition DrawElements.h:220
SLATECORE_API void PopClipToStackIndex(int32 Index)
Definition DrawElements.cpp:305
SLATECORE_API void PopClip()
Definition DrawElements.cpp:300
SLATECORE_API void SetIsInGameLayer(bool bInGameLayer)
Definition DrawElements.cpp:68
bool ShouldResolveDeferred() const
Definition DrawElements.h:353
const FSlateDrawElementMap & GetUncachedDrawElements() const
Definition DrawElements.h:249
FSlateBatchData & GetBatchData()
Definition DrawElements.h:392
void PopCachedElementData()
Definition DrawElements.cpp:216
TArrayView< FSlateCachedElementList *const > GetCurrentCachedElementWithNewData() const
Definition DrawElements.h:411
SLATECORE_API void QueueDeferredPainting(const FDeferredPaint &InDeferredPaint)
Definition DrawElements.cpp:142
SLATECORE_API void BeginDeferredGroup()
Definition DrawElements.cpp:166
SLATECORE_API FSlateDrawElement & AddUninitializedLookup(EElementType InElementType=EElementType::ET_NonMapped)
Definition DrawElements.cpp:221
SLATECORE_API int32 GetClippingIndex() const
Definition DrawElements.cpp:290
SLATECORE_API void ResetElementList()
Definition DrawElements.cpp:338
UE::Slate::FDeprecateVector2DResult GetWindowSize() const
Definition DrawElements.h:255
SLATECORE_API EWidgetPixelSnapping GetPixelSnappingMethod() const
Definition DrawElements.cpp:324
SLATECORE_API void SetRenderTargetWindow(SWindow *InRenderTargetWindow)
Definition DrawElements.cpp:329
SWindow * GetPaintWindow() const
Definition DrawElements.h:234
SLATECORE_API ~FSlateWindowElementList()
Definition DrawElements.cpp:63
SLATECORE_API FSlateCachedElementsHandle PopPaintingWidget(const SWidget &CurrentWidget)
Definition DrawElements.cpp:194
TSlateDrawElement< ElementType > & AddUninitialized()
Definition DrawElements.h:265
FSlateClippingManager & GetClippingManager()
Definition DrawElements.h:310
void PushCachedElementData(FSlateCachedElementData &CachedElementData)
Definition DrawElements.cpp:209
const FSlateClippingManager & GetClippingManager() const
Definition DrawElements.h:311
SLATECORE_API void EndDeferredGroup()
Definition DrawElements.cpp:171
SLATECORE_API bool GetIsInGameLayer()
Definition DrawElements.cpp:73
SLATECORE_API int32 PushClip(const FSlateClippingZone &InClipZone)
Definition DrawElements.cpp:283
SLATECORE_API int32 PushPixelSnappingMethod(EWidgetPixelSnapping InPixelSnappingMethod)
Definition DrawElements.cpp:310
SLATECORE_API void PopPixelSnappingMethod()
Definition DrawElements.cpp:316
int32 GetClippingStackDepth() const
Definition DrawElements.h:304
TArray< TSharedPtr< FDeferredPaint > > GetDeferredPaintList() const
Definition DrawElements.h:358
FSlateBatchData & GetBatchDataHDR()
Definition DrawElements.h:398
SLATECORE_API void PushPaintingWidget(const SWidget &CurrentWidget, int32 StartingLayerId, FSlateCachedElementsHandle &CurrentCacheHandle)
Definition DrawElements.cpp:176
void AddReferencedObjects(FReferenceCollector &Collector)
Definition DrawElements.cpp:376
int32 PaintDeferred(int32 LayerId, const FSlateRect &MyCullingRect)
Definition DrawElements.cpp:147
SLATECORE_API TOptional< FSlateClippingState > GetClippingState() const
Definition DrawElements.cpp:295
SWindow * GetRenderWindow() const
Definition DrawElements.h:241
Definition WidgetStyle.h:15
Definition SWidget.h:165
Definition SWindow.h:243
Definition ArrayView.h:139
Definition Array.h:670
Definition SharedPointer.h:692
Definition SharedPointer.h:153
ObjectType & Get() const
Definition SharedPointer.h:474
Definition SparseArray.h:524
Definition SharedPointer.h:1295
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, Mode > Pin() const &
Definition SharedPointer.h:1512
UE_FORCEINLINE_HINT bool IsValid() const
Definition SharedPointer.h:1535
FDeprecateSlateVector2D FDeprecateVector2DResult
Definition SlateVector2.h:469
U16 Index
Definition radfft.cpp:71
Definition Geometry.h:40
Definition RenderingCommon.h:187
Definition SlateBrush.h:239
Definition DrawElements.h:140
TArrayView< FSlateCachedElementList *const > GetListsWithNewData() const
Definition DrawElements.h:196
void Empty()
Definition DrawElements.cpp:417
FSlateRenderBatch & AddCachedRenderBatch(FSlateRenderBatch &&NewBatch, int32 &OutIndex)
Definition DrawElements.cpp:454
void CleanupUnusedClipStates()
Definition DrawElements.cpp:483
FSlateCachedElementsHandle AddCache(const SWidget *Widget)
Definition DrawElements.cpp:437
FSlateCachedClipState & FindOrAddCachedClipState(const FSlateClippingState *RefClipState)
Definition DrawElements.cpp:470
const TArray< TSharedPtr< FSlateCachedElementList > > & GetCachedElementLists() const
Definition DrawElements.h:192
const TSparseArray< FSlateRenderBatch > & GetCachedBatches() const
Definition DrawElements.h:191
void AddReferencedObjects(FReferenceCollector &Collector)
Definition DrawElements.cpp:508
void RemoveCachedRenderBatches(const TArray< int32 > &CachedRenderBatchIndices)
Definition DrawElements.cpp:462
static const FSlateClippingState * GetClipStateFromParent(const FSlateClippingManager &ParentClipManager)
Definition DrawElements.cpp:395
TSlateDrawElement< ElementType > & AddCachedElement(FSlateCachedElementsHandle &CacheHandle, const FSlateClippingManager &ParentClipManager, const SWidget *CurrentWidget)
Definition DrawElements.h:155
SLATECORE_API void ValidateWidgetOwner(TSharedPtr< FSlateCachedElementList > List, const SWidget *CurrentWidget)
Definition DrawElements.cpp:409
Definition DrawElements.h:48
void ClearCachedElements()
Definition DrawElements.cpp:521
SLATECORE_API ~FSlateCachedElementList()
Definition DrawElements.cpp:516
void Initialize()
Definition DrawElements.h:56
FSlateRenderBatch & AddRenderBatch(int32 InLayer, const FShaderParams &InShaderParams, const FSlateShaderResource *InResource, ESlateDrawPrimitive InPrimitiveType, ESlateShader InShaderType, ESlateDrawEffect InDrawEffects, ESlateBatchDrawFlag InDrawFlags, int8 SceneIndex)
Definition DrawElements.cpp:529
FSlateCachedElementData * ParentData
Definition DrawElements.h:94
const SWidget * OwningWidget
Definition DrawElements.h:92
TArray< int32 > CachedRenderBatchIndices
Definition DrawElements.h:89
SLATECORE_API bool IsEmpty()
Definition DrawElements.cpp:566
FSlateCachedElementList(FSlateCachedElementData *InParentData, const SWidget *InWidget)
Definition DrawElements.h:49
void AddCachedClipState(FSlateCachedClipState &ClipStateToCache)
Definition DrawElements.cpp:542
FSlateCachedFastPathRenderingData * CachedRenderingData
Definition DrawElements.h:96
FSlateCachedElementData * GetOwningData()
Definition DrawElements.h:65
void AddReferencedObjects(FReferenceCollector &Collector)
Definition DrawElements.cpp:547
SLATECORE_API int32 NumElements()
Definition DrawElements.cpp:583
FSlateDrawElementMap DrawElements
Definition DrawElements.h:87
Definition DrawElements.h:106
void RemoveFromCache()
Definition DrawElements.cpp:643
FSlateCachedElementsHandle()
Definition DrawElements.h:120
static FSlateCachedElementsHandle Invalid
Definition DrawElements.h:109
bool operator!=(FSlateCachedElementsHandle &Other) const
Definition DrawElements.h:118
void ClearCachedElements()
Definition DrawElements.cpp:635
bool HasCachedElements() const
Definition DrawElements.cpp:664
bool IsValid() const
Definition DrawElements.h:115
bool IsOwnedByWidget(const SWidget *Widget) const
Definition DrawElements.cpp:654
Definition DrawElements.h:29
~FSlateCachedFastPathRenderingData()
Definition DrawElements.h:30
FSlateVertexArray Vertices
Definition DrawElements.h:36
FSlateIndexArray Indices
Definition DrawElements.h:37
TArray< FSlateCachedClipState, TInlineAllocator< 1 > > CachedClipStates
Definition DrawElements.h:35
Definition SlateDebugging.h:117
Definition DrawElementTypes.h:395
Definition DrawElements.h:330
SLATECORE_API int32 ExecutePaint(int32 LayerId, FSlateWindowElementList &OutDrawElements, const FSlateRect &MyCullingRect) const
Definition DrawElements.cpp:125
Definition Optional.h:131