How to copy FrontBuffer to BackBuffer in DirectX11

I want to render the surface base on the the last surface. So I try to copy FrontBuffer to BackBuffer, but 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 do this work?

Replay

You can't Map a swapchain buffer as they are not necessarily created in CPU-readable memory. You could in theory copy it to a CPU staging resource, but the performance would be terrible.

A better option is to create another render target that you do your drawing on to, then you copy that texture to the backbuffer for Present. Then you can render your next scene on the same render target. The performance here is probably not as good as just rendering the whole scene again, but it really depends on what exactly you are doing.

Category: directx Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.108 (s). 12 q(s)