Reputation: 21
Can I get a byte array (ARGB) from D3D11Texture2D
?
DirectX 11 doesn't have the functions GetSurfaceLevel
and LockRect
.
Upvotes: 2
Views: 4073
Reputation: 665
Use Map/Unmap functions on your DeviceContext. This will only work for texture types that support reading.
eg
D3D11_MAP eMapType = D3D11_MAP_READ;
D3D11_MAPPED_SUBRESOURCE mappedResource;
pDeviceContext->Map(m_pTexture, 0, eMapType, NULL, &mappedResource);
BYTE* pYourBytes = (BYTE*)mappedResource.pData;
unsigned int uiPitch = mappedResource.RowPitch;
// Do stuff here
pDevice->GetDeviceContext()->Unmap(m_pTexture, 0);
If you want to read out the contents of a render texture then you will need to first create a staging texture of the same format as your render texture then copy the render texture to the staging texture using DeviceContext->CopyResource().
Upvotes: 3
Reputation: 6118
Why would you want to read back the data of a texture? You hold the data in RAM, then upload it to VRAM. You should still have it in RAM or on disk. AM I missing something?
You may want to look at how it was solved in DirectX 11 framebuffer capture (C++, no Win32 or D3DX)
Upvotes: 1