I want to render the surface base on the the last surface.
So I try to copy FrontBuffer
to BackBuffer
, but it does not work:
//Get the BackBuffer(it will be FrontBuffer after SwapChain swapped the BackBuffer and FrontBuffer)
ID3D11Texture2D* backBufferTexture1 = NULL;
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture1);
D3D11_MAPPED_SUBRESOURCE mapResource1;
HRESULT result1 = m_pID3DContext->Map(backBufferTexture1, 0, D3D11_MAP_READ, 0, &mapResource1);
assert(result1 == S_OK);
swapChain->Present(1,0); //swap the BackBuffer and FrontBuffer
//Get the BackBuffer
ID3D11Texture2D* backBufferTexture2 = NULL;
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture2);
D3D11_MAPPED_SUBRESOURCE mapResource2;
HRESULT result2 = m_pID3DContext->Map(backBufferTexture2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource2);
assert(result2 == S_OK);
//Copy the FrontBuffer to the BackBuffer
memcpy(mapResource2.pData, mapResource1.pData, sizeof(mapResource1.pData));
m_pID3DContext->Unmap(backBufferTexture1, 0);
m_pID3DContext->Unmap(backBufferTexture2, 0);
The result1
and result2
both return E_INVALIDARG One or more arguments are invalid. How could I get this to work?