UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeTextureStorageProvider.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 "Algo/Accumulate.h"
12#include "LandscapeEdgeFixup.h"
13#include "LandscapeTextureStorageProvider.generated.h"
14
17class UTexture2D;
18
19USTRUCT()
21{
23
24
25 UPROPERTY()
26 int32 SizeX = 0;
28 UPROPERTY()
29 int32 SizeY = 0;
31 UPROPERTY()
32 bool bCompressed = false;
33
35
37};
38
40{
41public:
44
45 // ********************************************************
46 // ********* FLandscapeTextureStorageMipProvider implementation **********
47 // ********************************************************
48
49 void Init(const FTextureUpdateContext& Context, const FTextureUpdateSyncOptions& SyncOptions) final override;
50 int32 GetMips(const FTextureUpdateContext& Context, int32 StartingMipIndex, const FTextureMipInfoArray& MipInfos, const FTextureUpdateSyncOptions& SyncOptions) final override;
51 bool PollMips(const FTextureUpdateSyncOptions& SyncOptions) final override;
52 void AbortPollMips() final override;
53 void CleanUp(const FTextureUpdateSyncOptions& SyncOptions) final override;
54 void Cancel(const FTextureUpdateSyncOptions& SyncOptions) final override;
55 ETickThread GetCancelThread() const final override;
56
57private:
58 // the Factory (that actually has the mip data)
60
61 // A structured with information about which file contains which mips.
62 struct FIORequest
63 {
65 TUniquePtr<IBulkDataIORequest> BulkDataIORequest;
66 uint8* DestMipData = nullptr;
67 };
68
69 // Pending async requests created in GetMips().
71
72 // We make a copy of this, as it is provided in GetMips, and we fill it out in PollMips
73 FTextureMipInfoArray DestMipInfos;
74
75 int32 FirstRequestedMipIndex = INDEX_NONE;
76
77 // The asset name, used to log IO errors.
78 FName TextureName;
79 // Whether async read requests must be created with high priority (executes faster).
80 bool bPrioritizedIORequest = false;
81 // Whether async read requests where cancelled for any reasons.
82 bool bIORequestCancelled = false;
83 // Whether async read requests were required to abort through AbortPollMips().
84 bool bIORequestAborted = false;
85
86 // A callback to be executed once all IO pending requests are completed.
87 FBulkDataIORequestCallBack AsyncFileCallBack;
88
89 // Helper to create the AsyncFileCallBack -- which can handle IO Request completions (and will trigger the next step to be scheduled via SyncOptions.RescheduleCallback())
90 void CreateAsyncFileCallback(const FTextureUpdateSyncOptions& SyncOptions);
91
92 void ClearIORequests();
93};
94
95
96
98{
99 // This class is actually a "Modifier" in that it doesn't provide any mips, it only modifies mips provided by the default providers
100 // It relies on some assumptions about the existing provider execution that are currently true, but may not remain true forever:
101 // 1) that all providers are executed, even if they are not actually handling any mips
102 // 2) that all default providers do NOT modify mip data in PollMips (this is true for both FTexture2DMipDataProvider_IO and FTexture2DMipDataProvider_DDC currently)
103 // this allows us to modify mip data in PollMips and not worry about being stomped on.
104 // IF either of these cease to be true, we should probably write a first class FTextureMipDataModifier path, and convert this to be a modifier instead of a provider.
105
106public:
109
110 // ****************************************************************************
111 // ********* FLandscapeTextureMipEdgeOverrideProvider implementation **********
112 // ****************************************************************************
113
114 void Init(const FTextureUpdateContext& Context, const FTextureUpdateSyncOptions& SyncOptions) final override;
115 int32 GetMips(const FTextureUpdateContext& Context, int32 StartingMipIndex, const FTextureMipInfoArray& MipInfos, const FTextureUpdateSyncOptions& SyncOptions) final override;
116 bool PollMips(const FTextureUpdateSyncOptions& SyncOptions) final override;
117 void CleanUp(const FTextureUpdateSyncOptions& SyncOptions) final override;
118 void Cancel(const FTextureUpdateSyncOptions& SyncOptions) final override;
119 ETickThread GetCancelThread() const final override;
120
121private:
122 // the Edge Fixup (that actually has the edge override data)
123 ULandscapeHeightmapTextureEdgeFixup* EdgeFixup = nullptr;
124
125 // We make a copy of this, as it is provided in GetMips, and we fill it out in PollMips
126 FTextureMipInfoArray DestMipInfos;
127
128 // The asset name, used to log IO errors.
129 FName TextureName;
130};
131
132
133// serves as a hook into the texture streaming process, allowing us to inject edge data
134UCLASS(NotBlueprintable, MinimalAPI, Within = Texture2D)
136{
138public:
139 TObjectPtr<UTexture2D> Texture; // should be the same as GetOuter()
140 TObjectPtr<ULandscapeHeightmapTextureEdgeFixup> EdgeFixup; // assigned when the EdgeFixup is Active
141
143
145
146 virtual void Serialize(FArchive& Ar) override;
147 static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
148
160
165 virtual bool WillProvideMipDataWithoutDisk() const
166 {
167 return true;
168 }
169};
170
171
172UCLASS(NotBlueprintable, MinimalAPI, Within = Texture2D)
174{
176
177public:
178
179 int32 NumNonOptionalMips = 0;
180 int32 NumNonStreamingMips = 0;
181 FVector LandscapeGridScale = FVector(ForceInit);
182
185
186 // Reference to the edge fixup on the Texture, if any. (This can be null, if edge fixup is disabled)
187 // It is set when the Texture's landscape component is registered.
189
190 #if WITH_EDITORONLY_DATA
193 #endif // WITH_EDITORONLY_DATA
194
195 void SetupEdgeFixup(ULandscapeHeightmapTextureEdgeFixup* EdgeFixup);
196
197 // compress the mip data.
198 static void CompressMipToBulkData(int32 MipIndex, int32 MipSizeX, int32 MipSizeY, uint8* SourceData, int32 SourceDataBytes, FByteBulkData& DestBulkData);
199 static void CopyMipToBulkData(int32 MipIndex, int32 MipSizeX, int32 MipSizeY, uint8* SourceData, int32 SourceDataBytes, FByteBulkData& DestBulkData);
200
201 // decompress the mip data. Currently operates in-place (though this could be changed in the future)
202 void DecompressMip(uint8* SourceData, int64 SourceDataBytes, uint8* DestData, int64 DestDataBytes, int32 MipIndex);
204
205 virtual void Serialize(FArchive& Ar) override;
206 static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
207
218
223 virtual bool WillProvideMipDataWithoutDisk() const
224 {
225 return true;
226 }
227
228 // load mip data (used to access preloaded inline mips for creating the initial version of the texture)
229 virtual bool GetInitialMipData(int32 FirstMipToLoad, TArrayView<void*> OutMipData, TArrayView<int64> OutMipSize, FStringView DebugContext) override;
230
231 // return the initial streaming state of the texture
232 virtual FStreamableRenderResourceState GetResourcePostInitState(const UTexture* Owner, bool bAllowStreaming) override;
233
234 bool DoesMipDataExist(int32 MipIndex)
235 {
236 // we need to check the bulk data exists (might not for optional mips)
237 return Mips.IsValidIndex(MipIndex) && Mips[MipIndex].BulkData.DoesExist();
238 }
239
241 {
242 int32 Index = MipIndex;
243 if (Mips.IsValidIndex(Index))
244 {
245 return &Mips[Index];
246 }
247 return nullptr;
248 }
249
251 {
252 return Algo::TransformAccumulate(Mips, [](const FLandscapeTexture2DMipMap& Mip) -> int32 { return Mip.BulkData.GetBulkDataSize(); }, 0);
253 }
254};
#define check(expr)
Definition AssertionMacros.h:314
const FIoFilenameHash INVALID_IO_FILENAME_HASH
Definition BulkData.h:69
uint32 FIoFilenameHash
Definition BulkData.h:68
@ INDEX_NONE
Definition CoreMiscDefines.h:150
@ ForceInit
Definition CoreMiscDefines.h:155
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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
#define FVector
Definition IOSSystemIncludes.h:8
void Init()
Definition LockFreeList.h:4
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
COREUOBJECT_API int64 GetBulkDataSize() const
Definition BulkData.cpp:770
Definition LandscapeTextureStorageProvider.h:98
~FLandscapeTextureMipEdgeOverrideProvider()
Definition LandscapeTextureStorageProvider.cpp:34
ETickThread GetCancelThread() const final override
Definition LandscapeTextureStorageProvider.cpp:109
Definition LandscapeTextureStorageProvider.h:40
Definition NameTypes.h:617
Definition UObjectGlobals.h:2492
Definition TextureMipDataProvider.h:92
ETickThread
Definition TextureMipDataProvider.h:106
Definition ArrayView.h:139
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
Definition UniquePtr.h:107
Definition LandscapeEdgeFixup.h:205
Definition LandscapeTextureStorageProvider.h:136
TObjectPtr< ULandscapeHeightmapTextureEdgeFixup > EdgeFixup
Definition LandscapeTextureStorageProvider.h:140
virtual bool WillProvideMipDataWithoutDisk() const
Definition LandscapeTextureStorageProvider.h:165
TObjectPtr< UTexture2D > Texture
Definition LandscapeTextureStorageProvider.h:139
virtual FTextureMipDataProvider * AllocateMipDataProvider(UTexture *Asset) override
Definition LandscapeTextureStorageProvider.h:155
Definition LandscapeTextureStorageProvider.h:174
virtual FTextureMipDataProvider * AllocateMipDataProvider(UTexture *Asset) override
Definition LandscapeTextureStorageProvider.h:214
const FLandscapeTexture2DMipMap * GetMip(int32 MipIndex)
Definition LandscapeTextureStorageProvider.h:240
TArray< FLandscapeTexture2DMipMap > Mips
Definition LandscapeTextureStorageProvider.h:183
virtual bool WillProvideMipDataWithoutDisk() const
Definition LandscapeTextureStorageProvider.h:223
TObjectPtr< UTexture2D > Texture
Definition LandscapeTextureStorageProvider.h:184
int32 GetTotalBytes() const
Definition LandscapeTextureStorageProvider.h:250
TObjectPtr< ULandscapeHeightmapTextureEdgeFixup > EdgeFixup
Definition LandscapeTextureStorageProvider.h:188
void DecompressMipOriginalUnoptimized(uint8 *SourceData, int64 SourceDataBytes, uint8 *DestData, int64 DestDataBytes, int32 MipIndex)
bool DoesMipDataExist(int32 MipIndex)
Definition LandscapeTextureStorageProvider.h:234
Definition Object.h:95
Definition Texture2D.h:26
Definition TextureAllMipDataProviderFactory.h:26
Definition TextureMipDataProviderFactory.h:24
Definition Texture.h:1219
T TransformAccumulate(const A &Input, MapT MapOp, T Init, OpT Op)
Definition Accumulate.h:71
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition LandscapeTextureStorageProvider.h:21
FByteBulkData BulkData
Definition LandscapeTextureStorageProvider.h:34
Definition StreamableRenderResourceState.h:23
Definition TextureMipDataProvider.h:65
Definition TextureMipDataProvider.h:48
Definition ObjectPtr.h:488