Can I get a byte array (ARGB) from D3D11Texture2D
?
DirectX 11 doesn't have the functions GetSurfaceLevel
and LockRect
.
Asked
Active
Viewed 3,729 times
2

Gilles 'SO- stop being evil'
- 104,111
- 38
- 209
- 254

gooseim
- 21
- 1
- 2
2 Answers
3
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().

alanw
- 645
- 6
- 10
1
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)
-
Perhaps the texture was created by a shader – jcoder Apr 04 '13 at 13:34
-
I must have the data of the existing texture in RAM in ARGB format. Thanks, I will look your example. – gooseim Apr 04 '13 at 14:07
-
Right, because creating a texture with a shader and reading it back is such an efficient way to do it. If you would have said, it was created though a frame buffer then... OK But in that case you would have access to it through the framebuffer API. – rioki Apr 04 '13 at 18:41
-
If I use the shaders it does not work. Can I resolve this problem? Where can I find the example of framebuffer API? – gooseim Apr 10 '13 at 10:53
-
This Q&A may help: http://stackoverflow.com/questions/120066/doing-readback-from-direct3d-textures-and-surfaces – rioki Apr 10 '13 at 11:21
-
Some functions in this example are deprecated in DirectX 11. – gooseim Apr 10 '13 at 12:40