UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BatchedElements.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 BatchedElements.h: Batched element rendering.
5=============================================================================*/
6
7#pragma once
8
11#include "RenderResource.h"
13#include "Math/DoubleFloat.h"
14
16class FHitProxyId;
17class FRHICommandList;
18class FSceneView;
19
20struct FBatchedPoint;
23
24enum EBlendMode : int;
26
37
40{
41 // Store LWC-scale positions per-vertex
42 // Could potentially optimize this by storing a global batch offset, along with relative position per-vertex, but this would be more complicated
43 // Could also pack this structure to save some space, W component of position is currently unused for example
48
50
56
62};
63
79
82
83
84
87 : public FRefCountedObject
88{
89
90public:
91
93 // LWC_TODO - InTransform should be a FMatrix44f, and/or should extend this with a method that takes FRelativeViewMatrices, to allow LWC-aware rendering with customized shaders
95
96};
97
98
99
102{
103public:
108
110 ENGINE_API void AddLine(const FVector& Start,const FVector& End,const FLinearColor& Color,FHitProxyId HitProxyId, float Thickness = 0.0f, float DepthBias = 0.0f, bool bScreenSpace = false);
111
113 ENGINE_API void AddTranslucentLine(const FVector& Start, const FVector& End, const FLinearColor& Color, FHitProxyId HitProxyId, float Thickness = 0.0f, float DepthBias = 0.0f, bool bScreenSpace = false);
114
116 ENGINE_API void AddPoint(const FVector& Position,float Size,const FLinearColor& Color,FHitProxyId HitProxyId);
117
122
124 ENGINE_API void AddTriangle(int32 V0,int32 V1,int32 V2,const FTexture* Texture,EBlendMode BlendMode);
125
128
130 ENGINE_API void AddTriangle(int32 V0,int32 V1,int32 V2,FBatchedElementParameters* BatchedElementParameters,ESimpleElementBlendMode BlendMode);
131
140
149
158
167
175 ENGINE_API void AddReserveLines(int32 NumLines, bool bDepthBiased = false, bool bThickLines = false);
176
179 const FVector& Position,
180 float SizeX,
181 float SizeY,
182 const FTexture* Texture,
183 const FLinearColor& Color,
184 FHitProxyId HitProxyId,
185 float U,
186 float UL,
187 float V,
188 float VL,
189 uint8 BlendMode,
190 float OpacityMaskRefVal
191 );
192
201 ENGINE_API bool Draw(FRHICommandList& RHICmdList, const FMeshPassProcessorRenderState& DrawRenderState, ERHIFeatureLevel::Type FeatureLevel, const FSceneView& View, bool bHitTesting, float Gamma = 1.0f, EBlendModeFilter::Type Filter = EBlendModeFilter::All, uint32 NumInstances = 1) const;
202
206 static ENGINE_API FSceneView CreateProxySceneView(const FMatrix& ProjectionMatrix, const FIntRect& ViewRect);
207
208 inline bool HasPrimsToDraw() const
209 {
210 return( LineVertices.Num() || Points.Num() || Sprites.Num() || MeshElements.Num() || ThickLines.Num() || WireTris.Num() > 0 );
211 }
212
215
217 ENGINE_API void Clear();
218
224 inline uint32 GetAllocatedSize( void ) const
225 {
226 return sizeof(*this) + Points.GetAllocatedSize() + WireTris.GetAllocatedSize() + WireTriVerts.GetAllocatedSize() + ThickLines.GetAllocatedSize()
227 + Sprites.GetAllocatedSize() + MeshElements.GetAllocatedSize() + MeshVertices.GetAllocatedSize();
228 }
229
230 UE_DEPRECATED(5.4, "EnableMobileHDREncoding is no longer supported")
232
234 {
235 public:
236 FAllocationInfo() = default;
237
238 private:
239 int32 NumLineVertices = 0;
240 int32 NumPoints = 0;
241 int32 NumWireTris = 0;
242 int32 NumWireTriVerts = 0;
243 int32 NumThickLines = 0;
244 int32 NumSprites = 0;
245 int32 NumMeshElements = 0;
246 int32 NumMeshVertices = 0;
247
248 friend FBatchedElements;
249 };
250
252 ENGINE_API void AddAllocationInfo(FAllocationInfo& AllocationInfo) const;
253
255 ENGINE_API void Reserve(const FAllocationInfo& AllocationInfo);
256
259
260private:
261
271 ENGINE_API void DrawPointElements(FRHICommandList& RHICmdList, const FMatrix& Transform, const uint32 ViewportSizeX, const uint32 ViewportSizeY, const FVector& CameraX, const FVector& CameraY, const uint32 NumInstances) const;
272
273 TArray<FSimpleElementVertex> LineVertices;
274
275 struct FBatchedPoint
276 {
277 FVector Position;
278 float Size;
279 FColor Color;
280 FColor HitProxyColor;
281 };
283
284 struct FBatchedWireTris
285 {
286 float DepthBias;
287 };
289
290 mutable TResourceArray<FSimpleElementVertex> WireTriVerts;
291
292 struct FBatchedThickLines
293 {
295 FVector End;
296 float Thickness;
298 FColor HitProxyColor;
299 float DepthBias;
300 uint32 bScreenSpace;
301 };
303
304 struct FBatchedSprite
305 {
307 float SizeX;
308 float SizeY;
309 const FTexture* Texture;
311 FColor HitProxyColor;
312 float U;
313 float UL;
314 float V;
315 float VL;
316 float OpacityMaskRefVal;
317 uint8 BlendMode;
318 };
320
321 struct FBatchedMeshElement
322 {
324 uint32 MinVertex;
328 TArray<uint16> Indices;
330 const FTexture* Texture;
332 TRefCountPtr<FBatchedElementParameters> BatchedElementParameters;
334 ESimpleElementBlendMode BlendMode;
336 FDepthFieldGlowInfo GlowInfo;
337 };
338
340 int32 MaxMeshIndicesAllowed;
342 int32 MaxMeshVerticesAllowed;
343
344 TArray<FBatchedMeshElement> MeshElements;
345 TArray<FSimpleElementVertex> MeshVertices;
346
350 ENGINE_API void PrepareShaders(
351 FRHICommandList& RHICmdList,
352 FGraphicsPipelineStateInitializer& GraphicsPSOInit,
354 ERHIFeatureLevel::Type FeatureLevel,
355 ESimpleElementBlendMode BlendMode,
356 const FDFRelativeViewMatrices& ViewMatrices,
357 FBatchedElementParameters* BatchedElementParameters,
358 const FTexture* Texture,
359 bool bHitTesting,
360 float Gamma,
361 const FDepthFieldGlowInfo* GlowInfo = nullptr,
362 const FSceneView* View = nullptr,
363 float OpacityMaskRefVal = .5f
364 ) const;
365};
366
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
ENGINE_API TGlobalResource< FSimpleElementVertexDeclaration > GSimpleElementVertexDeclaration
Definition BatchedElements.cpp:107
#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
EBlendMode
Definition EngineTypes.h:245
ESimpleElementBlendMode
Definition SceneTypes.h:191
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BatchedElements.h:88
virtual void BindShaders(FRHICommandList &RHICmdList, FGraphicsPipelineStateInitializer &GraphicsPSOInit, ERHIFeatureLevel::Type InFeatureLevel, const FMatrix &InTransform, const float InGamma, const FMatrix &ColorWeights, const FTexture *Texture)=0
Definition BatchedElements.h:234
Definition BatchedElements.h:102
ENGINE_API void AddPoint(const FVector &Position, float Size, const FLinearColor &Color, FHitProxyId HitProxyId)
Definition BatchedElements.cpp:198
ENGINE_API void AddLine(const FVector &Start, const FVector &End, const FLinearColor &Color, FHitProxyId HitProxyId, float Thickness=0.0f, float DepthBias=0.0f, bool bScreenSpace=false)
Definition BatchedElements.cpp:129
void EnableMobileHDREncoding(bool bInEnableHDREncoding)
Definition BatchedElements.h:231
ENGINE_API void AddAllocationInfo(FAllocationInfo &AllocationInfo) const
Definition BatchedElements.cpp:1483
ENGINE_API void AddTriangleExtensive(int32 V0, int32 V1, int32 V2, FBatchedElementParameters *BatchedElementParameters, const FTexture *Texture, ESimpleElementBlendMode BlendMode, const FDepthFieldGlowInfo &GlowInfo=FDepthFieldGlowInfo())
Definition BatchedElements.cpp:266
ENGINE_API void Reserve(const FAllocationInfo &AllocationInfo)
Definition BatchedElements.cpp:1495
ENGINE_API void AddSprite(const FVector &Position, float SizeX, float SizeY, const FTexture *Texture, const FLinearColor &Color, FHitProxyId HitProxyId, float U, float UL, float V, float VL, uint8 BlendMode, float OpacityMaskRefVal)
Definition BatchedElements.cpp:412
ENGINE_API void AddTriangle(int32 V0, int32 V1, int32 V2, const FTexture *Texture, EBlendMode BlendMode)
Definition BatchedElements.cpp:226
ENGINE_API void ReserveTriangles(int32 NumMeshTriangles, const FTexture *Texture, ESimpleElementBlendMode BlendMode)
Definition BatchedElements.cpp:396
bool HasPrimsToDraw() const
Definition BatchedElements.h:208
ENGINE_API int32 AddVertex(const FVector4 &InPosition, const FVector2D &InTextureCoordinate, const FLinearColor &InColor, FHitProxyId HitProxyId)
Definition BatchedElements.cpp:211
ENGINE_API void AddReserveLines(int32 NumLines, bool bDepthBiased=false, bool bThickLines=false)
Definition BatchedElements.cpp:353
ENGINE_API void AddTranslucentLine(const FVector &Start, const FVector &End, const FLinearColor &Color, FHitProxyId HitProxyId, float Thickness=0.0f, float DepthBias=0.0f, bool bScreenSpace=false)
Definition BatchedElements.cpp:165
ENGINE_API int32 AddVertexf(const FVector4f &InPosition, const FVector2f &InTextureCoordinate, const FLinearColor &InColor, FHitProxyId HitProxyId)
Definition BatchedElements.cpp:218
ENGINE_API bool Draw(FRHICommandList &RHICmdList, const FMeshPassProcessorRenderState &DrawRenderState, ERHIFeatureLevel::Type FeatureLevel, const FSceneView &View, bool bHitTesting, float Gamma=1.0f, EBlendModeFilter::Type Filter=EBlendModeFilter::All, uint32 NumInstances=1) const
Definition BatchedElements.cpp:894
ENGINE_API FBatchedElements()
Definition BatchedElements.cpp:121
ENGINE_API void AddReserveTriangles(int32 NumMeshTriangles, const FTexture *Texture, ESimpleElementBlendMode BlendMode)
Definition BatchedElements.cpp:380
uint32 GetAllocatedSize(void) const
Definition BatchedElements.h:224
ENGINE_API void ReserveVertices(int32 NumMeshVerts)
Definition BatchedElements.cpp:341
ENGINE_API void Clear()
Definition BatchedElements.cpp:1471
ENGINE_API void AddReserveVertices(int32 NumMeshVerts)
Definition BatchedElements.cpp:336
static ENGINE_API FSceneView CreateProxySceneView(const FMatrix &ProjectionMatrix, const FIntRect &ViewRect)
Definition BatchedElements.cpp:883
Definition RHIResources.h:4572
Definition HitProxies.h:86
Definition RHICommandList.h:455
Definition RHICommandList.h:3819
Definition RefCounting.h:252
Definition RenderResource.h:37
Definition SceneView.h:1425
Definition BatchedElements.h:68
virtual ENGINE_API ~FSimpleElementVertexDeclaration()
ENGINE_API FSimpleElementVertexDeclaration()
FVertexDeclarationRHIRef VertexDeclarationRHI
Definition BatchedElements.h:70
ENGINE_API FSimpleElementVertexDeclaration(FSimpleElementVertexDeclaration &&)
virtual ENGINE_API void InitRHI(FRHICommandListBase &RHICmdList) override
Definition BatchedElements.cpp:89
virtual ENGINE_API void ReleaseRHI() override
Definition BatchedElements.cpp:101
Definition RenderResource.h:354
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT SIZE_T GetAllocatedSize(void) const
Definition Array.h:1059
Definition RenderResource.h:543
Definition DynamicRHIResourceArray.h:31
Definition BatchedElements.h:28
Type
Definition BatchedElements.h:30
@ None
Definition BatchedElements.h:31
@ All
Definition BatchedElements.h:34
@ OpaqueAndMasked
Definition BatchedElements.h:32
@ Translucent
Definition BatchedElements.h:33
Position
Definition MultiBoxExtender.h:27
Type
Definition RHIFeatureLevel.h:20
@ Color
Definition MeshPaintVisualize.h:20
int
Definition TestServer.py:515
@ End
Definition GeoEnum.h:101
@ Start
Definition GeoEnum.h:100
constexpr FVertex MaxVertex
Definition GraphConvert.h:26
Definition LineBatchComponent.h:62
Definition Color.h:486
Definition SceneRelativeViewMatrices.h:44
Definition DoubleFloat.h:117
Definition EngineTypes.h:4031
Definition Color.h:48
Definition MeshPassProcessor.h:2118
Definition BatchedElements.h:40
FLinearColor Color
Definition BatchedElements.h:46
ENGINE_API FSimpleElementVertex()
FDFVector4 Position
Definition BatchedElements.h:44
FVector2f TextureCoordinate
Definition BatchedElements.h:45
FColor HitProxyIdColor
Definition BatchedElements.h:47