Reputation: 1725
I need this variable to be TRUE so that I can use MapDesktopSurface of IDXGIOutputDuplication
How do we set this to true. What previous settings can be done.
Here is a link
http://msdn.microsoft.com/en-us/library/windows/desktop/hh404622(v=vs.85).aspx
Upvotes: 3
Views: 796
Reputation: 101
I faced the same problem...So this is what you need to do:
The MapDesktopSurface method will most of the times return DXGI_ERROR_UNSUPPORTED as the image is not in the system memory, but in GPU memory.
In this case, you need to transfer that image from GPU memory to System memory.
So how to do that?
Create a descriptor for ID3D11Texture2D
of type D3D11_TEXTURE12D_DESC
.
Use GetDesc
on the image(ID3D11Texture2D
) that you acquired using IDXGIOutputDuplication::AcquireNextFrame
to fill in the descriptor.
This descriptor that you get has frameDescriptor.Usage
set to D3D11_USAGE_DEFAULT
.
You need to set the descriptor with following parameters (let others remain as it is):
frameDescriptor.Usage = D3D11_USAGE_STAGING;
frameDescriptor.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
frameDescriptor.BindFlags = 0;
frameDescriptor.MiscFlags = 0;
frameDescriptor.MipLevels = 1;
frameDescriptor.ArraySize = 1;
frameDescriptor.SampleDesc.Count = 1;
Now, create a new staging buffer (ID3D11Texture2D
) using the above descriptor as follows:
m_Device->CreateTexture2D(&frameDescriptor, NULL, &newId3d11Texture2D);
Copy the contents of the acquired image to your staging buffer as follows:
m_DeviceContext->CopyResource(newId3d11Texture2D, m_AcquiredDesktopImage);
Important: Release the acquired frame using IDXGIOutputDuplication::ReleaseFrame()
Now you can process this newTexture (newId3d11Texture2D
) as you wish!!!!!
Map it if you want...
This should be enough for answering your query...if you want more information, you can always check out the msdn pages or ask through comments...
Upvotes: 2