UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TextureInstanceState.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4TextureInstanceState.h: Definitions of classes used for texture streaming.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "TextureInstanceView.h"
13
15class ULevel;
16class UPrimitiveComponent;
18
25
26// Can be used either for static primitives or dynamic primitives
28{
29public:
40
62
69
76
78
81
82 // Will also remove bounds
86
87 // Similar to AddComponent, but ignore the streaming data bounds. Used for dynamic components. A faster implementation that does less processing.
90
91 FORCEINLINE bool HasComponentReferences(const UPrimitiveComponent* Component) const { return ComponentMap.Contains(Component); }
92
93 // Clears all internal references to the component and remove any associated record (e.g. FElements, Bounds). If RemovedRenderAssets is not null,
94 // render assets with all components removed will be added to the array.
96
97 // Clears all internal references to the component. Dynamic instance state will also add an entry to the pending remove list which will be used
98 // to remove the associated records (e.g. FElements, Bounds) when FlushPendingRemoveComponents is called.
99 bool RemoveComponentReferences(const UPrimitiveComponent* Component);
100
101 // Remove any record associated with pending remove components. Returns an array of render assets with all components removed.
103
105
106 void UpdateBounds(const UPrimitiveComponent* Component);
110
111 uint32 GetAllocatedSize() const;
112
113 // Generate the compiled elements.
116
119 void TrimBounds();
120 void OffsetBounds(const FVector& Offset);
121
122 FORCEINLINE int32 NumBounds() const { return Bounds4Components.Num(); }
123 FORCEINLINE bool HasComponent(int32 BoundIndex) const { return Bounds4Components[BoundIndex] != nullptr; }
124
125private:
126 typedef int32 FRemovedComponentHandle;
127
128 void RemoveComponentByHandle(FRemovedComponentHandle ElementIndex, FRemovedRenderAssetArray* RemovedRenderAssets);
129
130 void AddElement(const UPrimitiveComponent* Component, const UStreamableRenderAsset* Asset, int BoundsIndex, float TexelFactor, bool bForceLoad, int32*& ComponentLink);
131 // Returns the next elements using the same component.
132 void RemoveElement(int32 ElementIndex, int32& NextComponentLink, int32& BoundsIndex, const UStreamableRenderAsset*& Asset);
133
134 int32 AddBounds(const FBoxSphereBounds& Bounds, uint32 PackedRelativeBox, const UPrimitiveComponent* Component, float LastRenderTime, const FVector4& RangeOrigin, float MinDistanceSq, float MinRangeSq, float MaxRangeSq);
135 FORCEINLINE int32 AddBounds(const UPrimitiveComponent* Component);
136 void RemoveBounds(int32 Index);
137
138 EAddComponentResult AddComponentInternal(const FPreAddComponentPayload& Payload);
139 static EAddComponentResult AddComponentInternal(const UPrimitiveComponent* Component, FStreamingTextureLevelContext& LevelContext, float MaxAllowedUIDensity, FRenderAssetInstanceState* State, FPreAddComponentPayload* OutPreAddPayload);
140 static EAddComponentResult AddComponentIgnoreBoundsInternal(const UPrimitiveComponent* Component, FStreamingTextureLevelContext& LevelContext, FRenderAssetInstanceState* State, FPreAddComponentIgnoreBoundsPayload* OutPreAddPayload);
141
142 void AddRenderAssetElements(const UPrimitiveComponent* Component, const TArray<FPreAddRenderAssetElement>& RenderAssetElements, int32 BoundsIndex, int32*& ComponentLink);
143 void AddRenderAssetElements(const UPrimitiveComponent* Component, const TArrayView<FStreamingRenderAssetPrimitiveInfo>& RenderAssetInstanceInfos, int32 BoundsIndex, int32*& ComponentLink);
144
145private:
146
147 const bool bIsDynamicInstanceState;
148
153 TArray<const UPrimitiveComponent*> Bounds4Components;
154
155 TArray<int32> FreeBoundIndices;
156 TArray<int32> FreeElementIndices;
157
163 TArray<int32> BoundsToUnpack;
164
166 TArray<FRemovedComponentHandle> PendingRemoveComponents;
167
169
172};
173
174template <typename TTasks>
176{
177public:
178
182
184 {
185 Tasks.SyncResults();
186 }
187
189 {
190 Tasks.SyncResults();
191 return State.GetReference();
192 }
193
194 // Get State but must be constant as async tasks could be reading data.
196 {
197 return State.GetReference();
198 }
199
200 // Used when updating the state, but with no possible reallocation.
205
206 TTasks& GetTasks() { return Tasks; }
207 const TTasks& GetTasks() const { return Tasks; }
208
209protected:
213
216};
217
218template <typename TTasks>
#define FORCEINLINE
Definition AndroidPlatform.h:140
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
return true
Definition ExternalRpcRegistry.cpp:601
EAddComponentResult
Definition TextureInstanceState.h:20
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition TextureInstanceState.h:220
FRenderAssetInstanceState * SyncAndGetState()
Definition DynamicTextureInstanceManager.cpp:49
FRenderAssetDynamicInstanceStateTaskSync(FOnSyncDone &&InOnSyncDoneDelegate)
Definition TextureInstanceState.h:226
void Sync()
Definition DynamicTextureInstanceManager.cpp:38
DECLARE_DELEGATE_OneParam(FOnSyncDone, const FRemovedRenderAssetArray &)
Definition TextureInstanceState.h:176
FRenderAssetInstanceStateTaskSync()
Definition TextureInstanceState.h:179
FRenderAssetInstanceStateTaskSync(bool bForDynamicInstances)
Definition TextureInstanceState.h:210
FORCEINLINE FRenderAssetInstanceState * GetStateUnsafe()
Definition TextureInstanceState.h:201
TRefCountPtr< FRenderAssetInstanceState > State
Definition TextureInstanceState.h:214
FORCEINLINE void Sync()
Definition TextureInstanceState.h:183
TTasks & GetTasks()
Definition TextureInstanceState.h:206
FORCEINLINE FRenderAssetInstanceState * SyncAndGetState()
Definition TextureInstanceState.h:188
const TTasks & GetTasks() const
Definition TextureInstanceState.h:207
TTasks Tasks
Definition TextureInstanceState.h:215
FORCEINLINE const FRenderAssetInstanceState * GetState() const
Definition TextureInstanceState.h:195
Definition TextureInstanceState.h:28
bool MoveBound(int32 SrcBoundIndex, int32 DstBoundIndex)
Definition TextureInstanceState.cpp:934
FORCEINLINE bool HasComponent(int32 BoundIndex) const
Definition TextureInstanceState.h:123
EAddComponentResult AddComponentIgnoreBounds(const UPrimitiveComponent *Component, FStreamingTextureLevelContext &LevelContext)
Definition TextureInstanceState.cpp:569
int32 CompileElements()
Definition TextureInstanceState.cpp:827
static void PreAddComponent(const UPrimitiveComponent *Component, FStreamingTextureLevelContext &LevelContext, float MaxAllowedUIDensity, FPreAddComponentPayload &OutPayload)
Definition TextureInstanceState.cpp:381
int32 CheckRegistrationAndUnpackBounds(TArray< const UPrimitiveComponent * > &RemovedComponents)
Definition TextureInstanceState.cpp:905
void UpdateBounds(const UPrimitiveComponent *Component)
Definition TextureInstanceState.cpp:707
FORCEINLINE int32 NumBounds() const
Definition TextureInstanceState.h:122
bool RemoveComponentReferences(const UPrimitiveComponent *Component)
Definition TextureInstanceState.cpp:654
void GetReferencedComponents(TArray< const UPrimitiveComponent * > &Components) const
Definition TextureInstanceState.cpp:699
bool ConditionalUpdateBounds(int32 BoundIndex)
Definition TextureInstanceState.cpp:743
EAddComponentResult AddComponents(const TArray< FRenderAssetInstanceState::FPreAddComponentPayload > &Payloads, TFunctionRef< void(const FRenderAssetInstanceState::FPreAddComponentPayload &, EAddComponentResult)> OnAddFailedFunc)
Definition TextureInstanceState.cpp:329
void OffsetBounds(const FVector &Offset)
Definition TextureInstanceState.cpp:1048
void TrimBounds()
Definition TextureInstanceState.cpp:985
static void PreAddComponentIgnoreBounds(const UPrimitiveComponent *Component, FStreamingTextureLevelContext &LevelContext, FPreAddComponentIgnoreBoundsPayload &OutPayload)
Definition TextureInstanceState.cpp:552
void FlushPendingRemoveComponents(FRemovedRenderAssetArray &RemovedRenderAssets)
Definition TextureInstanceState.cpp:689
void RemoveComponent(const UPrimitiveComponent *Component, FRemovedRenderAssetArray *RemovedRenderAssets)
Definition TextureInstanceState.cpp:646
FORCEINLINE bool HasComponentReferences(const UPrimitiveComponent *Component) const
Definition TextureInstanceState.h:91
void UpdateLastRenderTimeAndMaxDrawDistance(int32 BoundIndex)
Definition TextureInstanceState.cpp:785
EAddComponentResult AddComponent(const UPrimitiveComponent *Component, FStreamingTextureLevelContext &LevelContext, float MaxAllowedUIDensity)
Definition TextureInstanceState.cpp:387
uint32 GetAllocatedSize() const
Definition TextureInstanceState.cpp:808
Definition TextureInstanceView.h:202
Definition TextureInstanceView.h:190
Definition TextureInstanceView.h:109
Definition TextureStreamingTypes.h:223
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition RefCounting.h:454
UE_FORCEINLINE_HINT ReferencedType * GetReference() const
Definition RefCounting.h:584
Definition Level.h:423
Definition StreamableRenderAsset.h:37
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition TextureInstanceState.h:42
float MinRangeSq
Definition TextureInstanceState.h:57
TArray< FPreAddRenderAssetElement > RenderAssets
Definition TextureInstanceState.h:60
uint32 PackedRelativeBox
Definition TextureInstanceState.h:54
FBoxSphereBounds InfoBounds
Definition TextureInstanceState.h:53
float MinDistanceSq
Definition TextureInstanceState.h:56
FVector RangeOrigin
Definition TextureInstanceState.h:55
FPreAddBounds(FBoxSphereBounds InInfoBounds, uint32 InPackedRelativeBox, bool bInIsPacked, const FVector &InRangeOrigin, float InMinDistanceSq, float InMinRangeSq, float InMaxRangeSq)
Definition TextureInstanceState.h:43
float MaxRangeSq
Definition TextureInstanceState.h:58
bool bIsPacked
Definition TextureInstanceState.h:59
TArray< FPreAddRenderAssetElement > RenderAssets
Definition TextureInstanceState.h:74
EAddComponentResult Result
Definition TextureInstanceState.h:73
const UPrimitiveComponent * Component
Definition TextureInstanceState.h:72
Definition TextureInstanceState.h:64
TArray< FPreAddBounds > Bounds
Definition TextureInstanceState.h:67
EAddComponentResult Result
Definition TextureInstanceState.h:66
const UPrimitiveComponent * Component
Definition TextureInstanceState.h:65
Definition TextureInstanceState.h:31
FPreAddRenderAssetElement(const UStreamableRenderAsset *InRenderAsset, float InMergedTexelFactor)
Definition TextureInstanceState.h:32
const UStreamableRenderAsset * RenderAsset
Definition TextureInstanceState.h:37
float MergedTexelFactor
Definition TextureInstanceState.h:38
Definition TextureStreamingTypes.h:37
Definition BoxSphereBounds.h:25