Hello, I would like to know if would be convenient for Texture2D method of SetPixels to also allows receiving a NativeArray as argument.
I’m doing some native work that creates a mini “render buffer” to be applied to a Texture2D, but I need to copy the content back to a normal Color[ ] before calling SetPixels.
By allowing NativeArray as argument, we could work with native pixel processing and avoid a unnecessary array copy every frame.
Current code:
s_displayPixels = tex.GetPixels();
m_displayPixelsNative = new NativeArray<Color>(s_displayPixels.Length, Unity.Collections.Allocator.Persistent);
// < .... >
unsafe
{
void* ptr = m_displayPixelsNative.GetUnsafePtr();
for (int i = 0; i < s_displayPixels.Length; i++)
{
s_displayPixels[i] = *(Color*)((byte*)ptr + i * sizeof(Color));
}
}
tex.SetPixels(s_displayPixels);
tex.Apply();
Thank you