UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ElementBatcher.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"
8#include "Layout/Clipping.h"
9#include "Stats/Stats.h"
10#include "SlateGlobals.h"
11#include "Styling/SlateTypes.h"
13
14class FSlateBatchData;
20struct FShaderParams;
23enum class ETextOverflowDirection : uint8;
24
26
34
36
38
44{
45public:
48
50 {
51 return BatchKey == Other.BatchKey && ShaderResource == Other.ShaderResource;
52 }
53
54 const FSlateShaderResource* GetShaderResource() const { return ShaderResource; }
55 const FShaderParams& GetShaderParams() const { return BatchKey.ShaderParams; }
56 ESlateBatchDrawFlag GetDrawFlags() const { return BatchKey.DrawFlags; }
57 ESlateDrawPrimitive GetPrimitiveType() const { return BatchKey.DrawPrimitiveType; }
58 ESlateShader GetShaderType() const { return BatchKey.ShaderType; }
59 ESlateDrawEffect GetDrawEffects() const { return BatchKey.DrawEffects; }
60 const TWeakPtr<ICustomSlateElement, ESPMode::ThreadSafe> GetCustomDrawer() const { return BatchKey.CustomDrawer; }
61 int32 GetInstanceCount() const { return BatchKey.InstanceCount; }
62 uint32 GetInstanceOffset() const { return BatchKey.InstanceOffset; }
63 const ISlateUpdatableInstanceBuffer* GetInstanceData() const { return BatchKey.InstanceData; }
64 int8 GetSceneIndex() const { return BatchKey.SceneIndex; }
65private:
66 struct FBatchKey
67 {
69 const FShaderParams ShaderParams;
70 const ESlateBatchDrawFlag DrawFlags;
71 const ESlateShader ShaderType;
72 const ESlateDrawPrimitive DrawPrimitiveType;
73 const ESlateDrawEffect DrawEffects;
74 const FClipStateHandle ClipStateHandle;
75 const int32 InstanceCount;
76 const uint32 InstanceOffset;
78 const int8 SceneIndex;
79
81 : ShaderParams(InShaderParams)
82 , DrawFlags(InDrawFlags)
83 , ShaderType(InShaderType)
84 , DrawPrimitiveType(InDrawPrimitiveType)
85 , DrawEffects(InDrawEffects)
86 , ClipStateHandle(InClipStateHandle)
87 , InstanceCount(InInstanceCount)
88 , InstanceOffset(InInstanceOffset)
90 , SceneIndex(InSceneIndex)
91 {
92 }
93
95 : ShaderParams(InShaderParams)
96 , DrawFlags(InDrawFlags)
97 , ShaderType(InShaderType)
98 , DrawPrimitiveType(InDrawPrimitiveType)
99 , DrawEffects(InDrawEffects)
100 , ClipStateHandle(InClipStateHandle)
101 , InstanceCount(InInstanceCount)
102 , InstanceOffset(InInstanceOffset)
104 , SceneIndex(-1)
105 {
106 }
107
110 , ShaderParams()
111 , DrawFlags(ESlateBatchDrawFlag::None)
112 , ShaderType(ESlateShader::Default)
113 , DrawPrimitiveType(ESlateDrawPrimitive::TriangleList)
114 , DrawEffects(ESlateDrawEffect::None)
115 , ClipStateHandle(InClipStateHandle)
116 , InstanceCount(0)
117 , InstanceOffset(0)
118 , SceneIndex(-1)
119 {}
120
121 bool operator==(const FBatchKey& Other) const
122 {
123 return DrawFlags == Other.DrawFlags
124 && ShaderType == Other.ShaderType
125 && DrawPrimitiveType == Other.DrawPrimitiveType
126 && DrawEffects == Other.DrawEffects
127 && ShaderParams == Other.ShaderParams
128 && ClipStateHandle == Other.ClipStateHandle
129 && CustomDrawer == Other.CustomDrawer
130 && InstanceCount == Other.InstanceCount
131 && InstanceOffset == Other.InstanceOffset
132 && InstanceData == Other.InstanceData
133 && SceneIndex == Other.SceneIndex;
134 }
135 };
136
138 FBatchKey BatchKey;
139
141 const FSlateShaderResource* ShaderResource;
142
143public:
150};
151
152
154{
155public:
158
160
162 const TArray<FSlateRenderBatch>& GetRenderBatches() const { return RenderBatches; }
163
166
169
170 int32 GetFirstRenderBatchIndex() const { return FirstRenderBatchIndex; }
172 int32 GetNumLayers() const { return NumLayers; }
173
174 int32 GetNumFinalBatches() const { return NumBatches; }
175
176 int32 GetMaxNumFinalVertices() const { return MaxNumFinalVertices; }
177 int32 GetMaxNumFinalIndices() const { return MaxNumFinalIndices; }
178
179 const FSlateVertexArray& GetFinalVertexData() const { return FinalVertexData; }
180 const FSlateIndexArray& GetFinalIndexData() const { return FinalIndexData; }
181
190
193
203 int8 SceneIndex);
204
205public:
207
208private:
209 void FillBuffersFromNewBatch(FSlateRenderBatch& Batch, FSlateVertexArray& FinalVertices, FSlateIndexArray& FinalIndices);
211private:
212
214 // todo allocator?
215 TArray<FSlateRenderBatch> RenderBatches;
216
218 FSlateVertexArray UncachedSourceBatchVertices;
219 FSlateIndexArray UncachedSourceBatchIndices;
220
221 FSlateVertexArray FinalVertexData;
222 FSlateIndexArray FinalIndexData;
223
224 int32 MaxNumFinalVertices = 0;
225 int32 MaxNumFinalIndices = 0;
226
227 int32 FirstRenderBatchIndex;
228
230 int32 NumLayers;
231
233 int32 NumBatches;
234
236 bool bIsStencilBufferRequired;
238 bool bRequiresVirtualTextureFeedback;
239};
240
241
246{
247public:
248
251
258
262 bool RequiresVsync() const { return bRequiresVsync; }
263
265 bool HasFXPassses() const { return NumPostProcessPasses > 0;}
266
267 bool CompositeHDRViewports() const { return bCompositeHDRViewports; }
268
269 ESlatePostRT GetUsedSlatePostBuffers() const { return UsedSlatePostBuffers; }
270
271 ESlatePostRT GetResourceUpdatingPostBuffers() const { return ResourceUpdatingPostBuffers; }
272
274
276
281
283 {
284 //NOTE: Using pow(x,2) instead of a full sRGB conversion has been tried, but it ended up
285 // causing too much loss of data in the lower levels of black.
286 return InLinearColor.ToFColor(bSRGBVertexColor);
287 }
288
289private:
290 void AddElementsInternal(const FSlateDrawElementMap& DrawElements, FVector2f ViewportSize);
291 void AddCachedElements(FSlateCachedElementData& CachedElementData, FVector2f ViewportSize);
292
304 template<typename ElementType, typename ElementAdder, typename ElementBatchParamCreator, typename ElementBatchReserver>
305 inline void GenerateIndexedVertexBatches(const FSlateDrawElementArray<ElementType>& DrawElements
309
313 template<ESlateVertexRounding Rounding>
314 void AddDebugQuadElement( const FSlateBoxElement& DrawElement);
315
319 template<typename ElementType>
320 void AddBoxElements( const FSlateDrawElementArray<ElementType>& DrawElement );
321
325 template<ESlateVertexRounding Rounding>
326 void AddTextElement( const FSlateTextElement& DrawElement );
327
331 template<ESlateVertexRounding Rounding>
332 void AddShapedTextElement( const FSlateShapedTextElement& DrawElement );
333
337 template<ESlateVertexRounding Rounding>
338 void AddGradientElement( const FSlateGradientElement& DrawElement );
339
343 void AddSplineElement( const FSlateSplineElement& DrawElement );
344
348 void AddLineElements(const FSlateDrawElementArray<FSlateLineElement>& DrawElements);
349
353 template<ESlateVertexRounding Rounding>
354 void AddViewportElement( const FSlateViewportElement& DrawElement );
355
359 template<ESlateVertexRounding Rounding>
360 void AddBorderElement( const FSlateBoxElement& DrawElement );
361
362 void AddCustomElement( const FSlateCustomDrawerElement& DrawElement );
363
364 void AddCustomVerts( const FSlateCustomVertsElement& DrawElement );
365
366 void AddPostProcessPass(const FSlatePostProcessElement& DrawElement, FVector2f WindowSize);
367
368 FSlateRenderBatch& CreateRenderBatch(
369 int32 Layer,
370 const FShaderParams& ShaderParams,
372 ESlateDrawPrimitive PrimitiveType,
373 ESlateShader ShaderType,
374 ESlateDrawEffect DrawEffects,
375 ESlateBatchDrawFlag DrawFlags,
376 int8 SceneIndex,
377 const FSlateClippingState* ClippingState)
378 {
379 return CreateRenderBatch(BatchData, Layer, ShaderParams, InResource, PrimitiveType, ShaderType, DrawEffects, DrawFlags, SceneIndex, ClippingState);
380 }
381
382 FSlateRenderBatch& CreateRenderBatch(
383 int32 Layer,
384 const FShaderParams& ShaderParams,
386 ESlateDrawPrimitive PrimitiveType,
387 ESlateShader ShaderType,
388 ESlateDrawEffect DrawEffects,
389 ESlateBatchDrawFlag DrawFlags,
390 const FSlateDrawElement& DrawElement)
391 {
392 return CreateRenderBatch(BatchData, Layer, ShaderParams, InResource, PrimitiveType, ShaderType, DrawEffects, DrawFlags, DrawElement);
393 }
394
395 FSlateRenderBatch& CreateRenderBatch(
397 int32 Layer,
398 const FShaderParams& ShaderParams,
400 ESlateDrawPrimitive PrimitiveType,
401 ESlateShader ShaderType,
402 ESlateDrawEffect DrawEffects,
403 ESlateBatchDrawFlag DrawFlags,
404 int8 SceneIndex,
405 const FSlateClippingState* ClippingState);
406
407 FSlateRenderBatch& CreateRenderBatch(
409 int32 Layer,
410 const FShaderParams& ShaderParams,
412 ESlateDrawPrimitive PrimitiveType,
413 ESlateShader ShaderType,
414 ESlateDrawEffect DrawEffects,
415 ESlateBatchDrawFlag DrawFlags,
416 const FSlateDrawElement& DrawElement);
417
418 const FSlateClippingState* ResolveClippingState(const FSlateDrawElement& DrawElement) const;
419
420 struct FShapedTextBuildContext
421 {
422 const class FShapedGlyphSequence* ShapedGlyphSequence;
423 const class FShapedGlyphSequence* OverflowGlyphSequence;
424 const UObject* FontMaterial;
425 const struct FFontOutlineSettings* OutlineSettings;
427 class FSlateFontCache* FontCache;
429 float TextBaseline;
430 float MaxHeight;
431 float StartLineX;
432 float StartLineY;
433 float LocalClipBoundingBoxLeft = 0;
434 float LocalClipBoundingBoxRight = 0;
435 int32 MaxGlyphCountToRender = -1;
436 int32 LayerId;
437 FColor FontTint;
438 ETextOverflowDirection OverflowDirection;
439 ETextOverflowPolicy OverflowPolicy;
440 bool bEnableCulling : 1;
441 bool bForceEllipsis : 1;
442
443 };
444
445 template<ESlateVertexRounding Rounding>
446 int32 BuildShapedTextSequence(const FShapedTextBuildContext& Context);
447private:
449 struct FMiddleEllipsisOverflowData
450 {
451 FMiddleEllipsisOverflowData()
452 : SkipIndexStart(INDEX_NONE)
453 , SkipIndexEnd(INDEX_NONE)
454 , LineX(0.f)
455 , LineY(0.f)
456 , EllipsisLineX(0.f)
457 , EllipsisLineY(0.f)
458 {}
459
460 int32 SkipIndexStart;
461 int32 SkipIndexEnd;
462 float LineX;
463 float LineY;
464 float EllipsisLineX;
465 float EllipsisLineY;
466 };
467
469 void CalculateMiddleEllipsisSkipIndexAndOffset(const FShapedTextBuildContext& InContext, ETextOverflowDirection InOverflowDirection, FMiddleEllipsisOverflowData& OutMiddleEllipsisData);
470
472 FSlateBatchData* BatchData;
473 FSlateBatchData* BatchDataHDR;
474
476 FSlateCachedElementList* CurrentCachedElementList;
477
479 const TArray<FSlateClippingState>* PrecachedClippingStates;
480
482 FSlateRenderingPolicy* RenderingPolicy;
483
484#if STATS
487
490
493
496
499
502
504#endif
505
507 int32 NumPostProcessPasses;
508
510 const float PixelCenterOffset;
511
513 const bool bSRGBVertexColor;
514
515 // true if any element in the batch requires vsync.
516 bool bRequiresVsync;
517
518 // true if viewports get composited as a separate pass, instead of being rendered directly to the render target. Useful for HDR displays
519 bool bCompositeHDRViewports;
520
521 // true if we added a resource that is using a slate post buffer
522 ESlatePostRT UsedSlatePostBuffers;
523
524 // true if a resource is updating a slate post buffer, if true we need to add a fence for the scene draw to complete before clearing unused post buffers
525 ESlatePostRT ResourceUpdatingPostBuffers;
526};
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define DECLARE_CYCLE_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:679
#define DECLARE_DWORD_COUNTER_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:682
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ETextOverflowDirection
Definition DrawElementTextOverflowArgs.h:9
int32 GSlateFeathering
Definition ElementBatcher.cpp:36
const uint32 MaxHeight
Definition GameplayMediaEncoder.cpp:50
ESlateDrawPrimitive
Definition RenderingCommon.h:49
ESlateBatchDrawFlag
Definition RenderingCommon.h:118
ESlateDrawEffect
Definition RenderingCommon.h:89
ESlateShader
Definition RenderingCommon.h:60
ESlatePostRT
Definition SlateRendererTypes.h:15
ETextOverflowPolicy
Definition SlateTypes.h:79
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition FontCache.h:334
Definition ElementBatcher.h:154
SLATECORE_API ~FSlateBatchData()
SLATECORE_API bool IsVirtualTextureFeedbackRequired() const
Definition ElementBatcher.cpp:113
SLATECORE_API void MergeRenderBatches()
Definition ElementBatcher.cpp:171
int32 GetMaxNumFinalIndices() const
Definition ElementBatcher.h:177
const FSlateVertexArray & GetFinalVertexData() const
Definition ElementBatcher.h:179
SLATECORE_API FSlateBatchData()
Definition ElementBatcher.cpp:78
SLATECORE_API bool IsStencilClippingRequired() const
Definition ElementBatcher.cpp:108
int32 GetFirstRenderBatchIndex() const
Definition ElementBatcher.h:170
SLATECORE_API void ResetData()
Definition ElementBatcher.cpp:88
int32 GetMaxNumFinalVertices() const
Definition ElementBatcher.h:176
const FSlateIndexArray & GetFinalIndexData() const
Definition ElementBatcher.h:180
friend FSlateElementBatcher
Definition ElementBatcher.h:206
int32 GetNumFinalBatches() const
Definition ElementBatcher.h:174
const TArray< FSlateRenderBatch > & GetRenderBatches() const
Definition ElementBatcher.h:162
SLATECORE_API void FillVertexAndIndexBuffer(uint8 *VertexBuffer, uint8 *IndexBuffer, bool bAbsoluteIndices)
FSlateRenderBatch & AddRenderBatch(int32 InLayer, const FShaderParams &InShaderParams, const FSlateShaderResource *InResource, ESlateDrawPrimitive InPrimitiveType, ESlateShader InShaderType, ESlateDrawEffect InDrawEffects, ESlateBatchDrawFlag InDrawFlags, int8 SceneIndex)
Definition ElementBatcher.cpp:118
int32 GetNumLayers() const
Definition ElementBatcher.h:172
Definition Clipping.h:207
Definition DrawElementTypes.h:46
Definition ElementBatcher.h:44
bool operator==(const FSlateElementBatch &Other) const
Definition ElementBatcher.h:49
int32 IndexArrayIndex
Definition ElementBatcher.h:149
ESlateShader GetShaderType() const
Definition ElementBatcher.h:58
const ISlateUpdatableInstanceBuffer * GetInstanceData() const
Definition ElementBatcher.h:63
int8 GetSceneIndex() const
Definition ElementBatcher.h:64
ESlateBatchDrawFlag GetDrawFlags() const
Definition ElementBatcher.h:56
int32 VertexArrayIndex
Definition ElementBatcher.h:147
ESlateDrawEffect GetDrawEffects() const
Definition ElementBatcher.h:59
uint32 NumElementsInBatch
Definition ElementBatcher.h:145
const FShaderParams & GetShaderParams() const
Definition ElementBatcher.h:55
const FSlateShaderResource * GetShaderResource() const
Definition ElementBatcher.h:54
const TWeakPtr< ICustomSlateElement, ESPMode::ThreadSafe > GetCustomDrawer() const
Definition ElementBatcher.h:60
ESlateDrawPrimitive GetPrimitiveType() const
Definition ElementBatcher.h:57
int32 GetInstanceCount() const
Definition ElementBatcher.h:61
uint32 GetInstanceOffset() const
Definition ElementBatcher.h:62
Definition ElementBatcher.h:246
bool CompositeHDRViewports() const
Definition ElementBatcher.h:267
bool RequiresVsync() const
Definition ElementBatcher.h:262
ESlatePostRT GetResourceUpdatingPostBuffers() const
Definition ElementBatcher.h:271
FColor PackVertexColor(const FLinearColor &InLinearColor) const
Definition ElementBatcher.h:282
void SetCompositeHDRViewports(bool bInCompositeHDRViewports)
Definition ElementBatcher.h:275
ESlatePostRT GetUsedSlatePostBuffers() const
Definition ElementBatcher.h:269
SLATECORE_API void AddElements(FSlateWindowElementList &ElementList)
Definition ElementBatcher.cpp:303
SLATECORE_API void ResetBatches()
Definition ElementBatcher.cpp:3961
SLATECORE_API ~FSlateElementBatcher()
Definition ElementBatcher.cpp:299
void SetResourceUpdatingPostBuffers(ESlatePostRT InResourceUpdatingPostBuffers)
Definition ElementBatcher.h:273
bool HasFXPassses() const
Definition ElementBatcher.h:265
Definition FontCache.h:756
Definition SlateRenderBatch.h:45
Definition RenderingPolicy.h:19
Definition SlateShaderResource.h:44
Definition DrawElements.h:220
Definition RenderingCommon.h:974
Definition Array.h:670
Definition SharedPointer.h:153
Definition TransformCalculus2D.h:682
Definition SharedPointer.h:1295
Definition Object.h:95
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
void DrawElement(int32 Dimension, TArray< FVector > &Points, EVisuProperty Property)
Definition Display.cpp:81
Definition Clipping.h:296
Definition Color.h:486
Definition SlateFontInfo.h:37
Definition Color.h:48
Definition RenderingCommon.h:187
Definition DrawElementTypes.h:423
Definition DrawElements.h:140
Definition DrawElements.h:48
Definition DrawElementTypes.h:688
Definition DrawElementTypes.h:727
Definition DrawElementTypes.h:550
Definition DrawElementTypes.h:752
Definition DrawElementTypes.h:512
Definition DrawElementTypes.h:564
Definition DrawElementTypes.h:476
Definition DrawElementTypes.h:671