right now I have a client and server. The server is making screenshots and sending them to my client in byte.
Here I'm getting the bytes and putting them into my texture:
private IEnumerator RenderImage(byte[] values)
{
var texture = new Texture2D(128, 128);
texture.LoadImage(values); // <-- is running on main thread -> lag
texture.Apply();
RawImage.texture = texture;
yield return null;
}
This works but its causes a short freeze on the hololens, for maybe 1/2 second.
1. I've read a lot of times that LoadImage will run on main thread and you cant move it somewhere else.
2. Using Texture2D.LoadRawTextureData should work faster and fix my problem. But using it, it throws the exception that Im not providing enough data. Writing something like
var texture = new Texture2D(128, 128, TextureFormat.RGBA32, false);
wont fixe the problem.
Does sb know how encode the bytes in a more efficient way or a way that the main thread doesn't get stuck having to decode a image?
--EDIT-- I forgot to say that I'm using this Main-Thread-Dispatcher, but its not helping:
private void OnMessageReceived(byte[] values)
{
UnityMainThreadDispatcher.Instance().Enqueue(RenderImage(values));
}
private IEnumerator RenderImage(byte[] values)
{
var texture = new Texture2D(128, 128, TextureFormat.RGBA32, false);
texture.LoadImage(values); // <-- is running on main thread -> lag
texture.Apply();
RawImage.texture = texture;
yield return null;
}