Skip to content

Commit

Permalink
fix: determine the GrahpicsFormat at runtime (#980)
Browse files Browse the repository at this point in the history
- fix MissingReferenceException
- determine the graphicsFormat at runtime
  • Loading branch information
homuler committed Aug 5, 2023
1 parent c777113 commit 514a0a9
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>());
_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;

Expand All @@ -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<byte>());
_texture.Apply();
_ = RevokeNativeTexturePtr();
Expand Down

0 comments on commit 514a0a9

Please sign in to comment.