問題描述
將 ID3D11Texture2D 轉換為內存緩衝區 (Convert ID3D11Texture2D into a memory buffer)
我們如何將ID3D11Texture2D
轉換為內存緩衝區?我有 ID3D11Texture2D*
並且需要從它讀取數據到內存緩衝區。
參考解法
方法 1:
You need to create a second texture with the same format/size, but create it as staging.
Cpu access flags needs to be set to D3D11_CPU_ACCESS_READ
and usage needs to be set to D3D11_USAGE_STAGING
.
Then you can call ID3D11DeviceContext::CopyResource
to copy from the texture to the staging one.
And then you call Map
to access data.