So, I’m trying copy many textures to a unique texture (to create a Texture Atlas), everything seems to work fine for smaller textures (until 64x64), above that, the BulkData seems to be locked and not loaded, what should I do in this case? force load these textures? wait for it to load? will it load any time? (I have ran the atlas texture generation code with a delay of 10s and the bigger textures still seem to not be in memory)
I basically reference the textures in a custom UPrimaryAsset:
And copy them:
for (const auto Texture : Textures)
{
FTexture2DMipMap& TextureMip = Texture->GetPlatformData()->Mips[0];
if (!TextureMip.BulkData.IsBulkDataLoaded())
{
UE_LOG(LogTemp, Warning, TEXT("Bulk Data not loaded, loading..."));
TextureMip.BulkData.LoadBulkDataWithFileReader();
if (!TextureMip.BulkData.IsBulkDataLoaded())
{
UE_LOG(LogTemp, Warning, TEXT("Bulk Data still not loaded..."));
}
}
if (TextureMip.BulkData.IsLocked())
{
UE_LOG(LogTemp, Error, TEXT("Locked resource!!! %s"),
*Texture->GetName());
continue;
}
void* SourceData = TextureMip.BulkData.Lock(LOCK_READ_ONLY);
if (!SourceData)
{
bool StreamedIn = Texture->IsFullyStreamedIn();
UE_LOG(LogTemp, Warning, TEXT("Couldn't lock the Source Data for texture %s"),
*Texture->GetName());
UE_LOG(LogTemp, Warning, TEXT("Bytes: %lld"), TextureMip.BulkData.GetBulkDataSize());
UE_LOG(LogTemp, Warning, TEXT("Streamed In? %d"), StreamedIn);
continue;
}
try
{
const FVector2D Position = PositionByTexture[Texture];
const auto TextureSize = Texture->GetImportedSize();
const auto TextureWidth = TextureSize.X;
const auto TextureHeight = TextureSize.Y;
for (int32 y = 0; y < TextureHeight; ++y)
{
for (int32 x = 0; x < TextureWidth; ++x)
{
int32 DestIndex = ((y + Position.Y) * AtlasWidth + (x + Position.X)) * 4;
int32 SourceIndex = (y * TextureWidth + x) * 4;
FMemory::Memcpy(static_cast<uint8*>(Data) + DestIndex,
static_cast<uint8*>(SourceData) + SourceIndex, 4);
}
}
}
catch (const std::exception& Error)
{
UE_LOG(LogTemp, Warning, TEXT("Error: %hs"), Error.what());
}
TextureMip.BulkData.Unlock();
}
The output for it is:
Also, this is general properties for the 128 texture: