霍洛伦斯 - 统一:负载图冻结主线程



现在我有一个客户端和服务器。服务器正在制作屏幕截图,并将其发送给我的客户端。


在这里,我得到了字节并将其放入我的纹理中:

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;
}

这有效,但在Hololens上引起了短暂的冻结,可能是1/2秒。

1。我已经阅读了很多次, loadImage 将在主线程上运行,并且您无法将其移动到其他地方。
2。使用 texture2d.loadrawtexturedata 应该更快地工作并解决我的问题。但是使用它,它引发了一个例外,即我没有提供足够的数据。写
var texture = new Texture2D(128, 128, TextureFormat.RGBA32, false);之类的东西不会解决问题。

SB知道如何以更有效的方式编码字节,或者主线程不会被卡住而不必解码图像?

- 编辑 - 我忘了说我正在使用此主线程读数,但没有帮助:

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;
}

好,我通过使用服务器和此Nativ渲染插件解决了问题。渲染插件使用Direct3D和Renderapi来设置纹理。

最新更新