diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs index 70c6fef12..7c0881e95 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs @@ -123,13 +123,21 @@ public AsyncGPUReadbackRequest ReadTextureAsync(Texture src) throw new InvalidOperationException("Failed to read texture on GPU"); } - return AsyncGPUReadback.Request(_texture, 0); + return AsyncGPUReadback.Request(_texture, 0, (req) => + { + if (_texture == null) + { + return; + } + _texture.LoadRawTextureData(req.GetData()); + _texture.Apply(); + }); } public AsyncGPUReadbackRequest ReadTextureAsync(Texture src, bool flipVertically, bool flipHorizontally) { - // TODO: determine the format at runtime - var tmpRenderTexture = RenderTexture.GetTemporary(src.width, src.height, 32, GraphicsFormat.R8G8B8A8_UNorm); + var graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(format, true); + var tmpRenderTexture = RenderTexture.GetTemporary(src.width, src.height, 32, graphicsFormat); var currentRenderTexture = RenderTexture.active; RenderTexture.active = tmpRenderTexture; @@ -151,6 +159,10 @@ public AsyncGPUReadbackRequest ReadTextureAsync(Texture src, bool flipVertically return AsyncGPUReadback.Request(tmpRenderTexture, 0, (req) => { + if (_texture == null) + { + return; + } _texture.LoadRawTextureData(req.GetData()); _texture.Apply(); _ = RevokeNativeTexturePtr();