If already have a DirectX texture in hand, what is the fast(low CPU utilization) way to get a RGB24 buffer in main RAM from it (skip the A)?
Strictly the format is DXGI_FORMAT_B8G8R8A8_UNORM, does this mean ARGB?
I'm using https://github.com/bmharper/WindowsDesktopDuplicationSample to capture Windows desktop and the result is to be converted into RGB24 lossless format in main RAM.
The existing code copy GPU texture to CPU texture then use memcpy to copy each line of the RGBA32 data to main RAM:
ID3D11Texture2D* gpuTex = nullptr;
hr = deskRes->QueryInterface(__uuidof(ID3D11Texture2D), (void**) &gpuTex);
....
ID3D11Texture2D* cpuTex = nullptr;
hr = D3DDevice->CreateTexture2D(&desc, nullptr, &cpuTex);
....
D3DDeviceContext->CopyResource(cpuTex, gpuTex);
....
D3D11_MAPPED_SUBRESOURCE sr;
hr = D3DDeviceContext->Map(cpuTex, 0, D3D11_MAP_READ, 0, &sr);
....
for (int y = 0; y < (int) desc.Height; y++)
memcpy(Latest.Buf.data() + y * desc.Width * 4, (uint8_t*) sr.pData + sr.RowPitch * y, desc.Width * 4);
Some possible way:
(1) Is it possible to let GPU convert the texture to RGB24 texture before copy it to CPU texture? How to do this in DX?
(2) If not, some assembly code to replace the line memcpy
memcpy(Latest.Buf.data() + y * desc.Width * 4, (uint8_t*) sr.pData + sr.RowPitch * y, desc.Width * 4);
to do RGBA32 to RGB24 conversion for a line may be the best way, can some example or reference be provided?