The function can be found here:
UTexture2D::UpdateTextureRegions | Unreal Engine Documentation
And it’s really annoying because the Wiki is just…wrong.
If you look you can see the function takes a template function as it’s final argument but when you scroll down you’ll see it lists the old final argument as a boolean.
This post shows how to use the function:
UpdateTextureRegions Pitch - Rendering - Epic Developer Community Forums
But the problem I’m having is I can’t figure out how to implement the DataCleanUpFunc in a class and I can’t seem to find any examples.
So maybe this is a more of a generic C++ question but how do I declare a Template function as a member function?
The wiki is beyond frustrating. I really wish they’d add an example on how to use things.
Any help will be greatly appreciated!
henryLiu
(henryLiu)
August 27, 2019, 1:05am
2
Looks like the interface of UpdateTextureRegions changed, but those note haven’t updated yet.
DataCleanupFunc have its own default implement, which means do nothing:
TFunction<void(uint8* SrcData, const FUpdateTextureRegion2D* Regions)> DataCleanupFunc = ](uint8*, const FUpdateTextureRegion2D*){}
DataCleanupFunc like below would be similar to bFreeData is true, any variables in DataCleanupFunc has to be thread safe:
TFunction<void(uint8*, const FUpdateTextureRegion2D*)> DataCleanupFunc = [this](uint8* InTextureData, const FUpdateTextureRegion2D* InRegions)
{
delete InTextureData;
delete InRegions;
};
Lyverbe
(Lyverbe)
January 8, 2021, 4:08pm
3
I’ve spent the last 45 minutes trying to figure out how it works. Finally…
.H
static TFunction<void(uint8* SrcData, const FUpdateTextureRegion2D* Regions)> CleanMemory(uint8* srcData, const FUpdateTextureRegion2D* regions);
.CPP
TFunction<void(uint8* SrcData, const FUpdateTextureRegion2D* Regions)> UMyClass::CleanMemory(uint8* srcData, const FUpdateTextureRegion2D* regions)
{
delete srcData;
delete regions;
return 0;
}
Usage
destTexture->UpdateTextureRegions(0, 1, updateTextureRegion, BufferPitch, BytesPerPixel, newTextureBuffer, &CleanMemory);
2 Likes