Hello, I’m using UTexture2D::CreateTransient to create a dynamic texture updated at runtime to show the QR code. It works well on PC editor, but on PS5 the texture is completely wrong (seems to repeat itself and not being at the correct size).
UTexture2D *tex = nullptr;
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
//Load From File
TArray<uint8> RawFileData;
if (!FFileHelper::LoadFileToArray(RawFileData, *path)) {
INTLGameNativeLogInfo("------load raw file failed: %s \n", TCHAR_TO_UTF8(*path));
return NS_SLUA::LuaObject::pushNil(L);
}
EImageFormat format = ImageWrapperModule.DetectImageFormat(RawFileData.GetData(), RawFileData.Num());
if (format == EImageFormat::Invalid) {
INTLGameNativeLogInfo("-------load texture invalid format------\n");
return NS_SLUA::LuaObject::pushNil(L);
}
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(format);
//Create T2D!
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num())) {
int32 BitDepth = ImageWrapper->GetBitDepth();
int32 Width = ImageWrapper->GetWidth();
int32 Height = ImageWrapper->GetHeight();
INTLGameNativeLogInfo("INTLGameNative::LoadTexture BitDepth = %d, Width = %d, Height = %d, RawFileData Length = %d", BitDepth, Width, Height, RawFileData.Num());
#if UE_4_25_OR_LATER
TArray<uint8> UncompressedBGRA;
#else
const TArray<uint8>* UncompressedBGRA = NULL;
#endif
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA)) {
#if (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION >= 25) || (ENGINE_MAJOR_VERSION >= 5)
INTLGameNativeLogInfo("INTLGameNative::LoadTexture UncompressedBGRA Length = %d", UncompressedBGRA.GetAllocatedSize());
#else
INTLGameNativeLogInfo("INTLGameNative::LoadTexture UncompressedBGRA Length = %d", UncompressedBGRA->GetAllocatedSize());
#endif
tex = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
if (!tex) {
INTLGameNativeLogInfo("------create transient texture2D failed.\n");
return NS_SLUA::LuaObject::pushNil(L);
}
//Copy!
void* TextureData = tex->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
#if UE_4_25_OR_LATER
FMemory::Memcpy(TextureData, UncompressedBGRA.GetData(), UncompressedBGRA.Num());
#else
FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
#endif
tex->PlatformData->Mips[0].BulkData.Unlock();
tex->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
#if UE_4_25_OR_LATER
tex->MipLoadOptions = ETextureMipLoadOptions::OnlyFirstMip;
#endif
tex->LODGroup = TextureGroup::TEXTUREGROUP_UI;
tex->Filter = TextureFilter::TF_Nearest;
//Update!
tex->UpdateResource();
}
}
Any idea what could make it appear weird on PS5 ?