Just wanted to chime in with my solution.
As @RiccardoAxed already pointed out LoadRawPixelData does not work when the source texture does not already have mipmaps.
You can fix that by filling the source texture’s data into the destination NativeArray though:
var mmTexture = new Texture2D(texture.width, texture.height, texture.format, true);
var dst = mmTexture.GetRawTextureData<byte>();
var src = texture.GetRawTextureData<byte>();
NativeArray<byte>.Copy(src, dst, src.Length);
mmTexture.LoadRawTextureData(dst);
mmTexture.Apply(true, true);
But, at least in my use-case, the actual winner is this one:
var mmTexture = new Texture2D(texture.width, texture.height, texture.format, true);
mmTexture.SetPixelData(texture.GetRawTextureData<byte>(), 0);
mmTexture.Apply(true, true);
I’ve set up a little benchmark loading 110 images, most of them around 1920x1080, a mix of PNG (ARGB32) and JPG (RGB24).
The SetPixelData one overall reproducibly runs juuust a little faster with a ratio of about 1.1
Sometimes the LoadRawPixelData one outperforms the SetPixelData one though. I did not find a pattern why this is. I could not relate it to the images’ resolution or format. I also played around with the order in which the two different methods get executed but the SetPixelData one always is a tad faster overall.
Edit: One important distinction: Be sure to use the generic overload texture.GetRawTextureData<byte>()
as the non-generic method returns byte[ ] and performs measurably worse for me (ratio of 0.8).