Sign in to follow this  
Belkacem

copy from backbuffer to rendertaget

Recommended Posts

Hello everyone

first :

i have an application that use 2 swap chain back buffer and render target buffer , and i want to copy data from the back buffer into the render target , and create render target view

OK , i will not ask you how to do everything but i do some codes but still i have some uncompleted code

ok

i create render target buffer like this
[code]
_Swp_Chain_desc.BufferCount = 1 ;
_Swp_Chain_desc.BufferDesc.Format = Buf.Format;
_Swp_Chain_desc.BufferDesc.Height = Buf.Height ;
_Swp_Chain_desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
_Swp_Chain_desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
_Swp_Chain_desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
_Swp_Chain_desc.BufferDesc.Width= Buf.Width ;
_Swp_Chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
_Swp_Chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
_Swp_Chain_desc.OutputWindow = hwnd ;
_Swp_Chain_desc.SampleDesc = Sample_Desc ;
_Swp_Chain_desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
_Swp_Chain_desc.Windowed= Windowed ;


if ( FAILED (::D3D11CreateDeviceAndSwapChain ( NULL , D3D_DRIVER_TYPE_HARDWARE , NULL ,D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS| D3D11_CREATE_DEVICE_BGRA_SUPPORT, Feature_Level_List
,_Number_Feature_Level_List , D3D11_SDK_VERSION , &_Swp_Chain_desc,&_SwapChain,&_Device ,&_featureLevel , &_DeviceContext )))


{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create Device or (and) SwapChain! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
} [/code]


and create the back buffer like this


[code] ::DXGI_SWAP_CHAIN_DESC desc ;
desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = 1000 ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= 1000 ;
desc.BufferUsage = DXGI_USAGE_BACK_BUFFER;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= Windowed ;


_Device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&gdevice));

IDXGIAdapter* pDXGIAdapter = NULL;
gdevice->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast<void**>(&pDXGIAdapter));

pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory));
factory->CreateSwapChain (gdevice , &desc , &pSwapChain );[/code]




her is the the problem

in general i create render target view like this and its work correctly

[code] if ( SUCCEEDED (_SwapChain->GetBuffer (0 , __uuidof(ID3D11Texture2D) , reinterpret_cast <void**>(&_Target_Tex2D))))
{

if ( FAILED( _Device->CreateRenderTargetView ( _Target_Tex2D , 0 , &_Target)))
{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create RenderTargetView! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}

}[/code]

but if i want to load the surface from the back buffer and use it as surface to create render target view i cant create the render target view but i cant create the surface from the back buffer

[code] if ( SUCCEEDED (pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&p_RT))) /// i succeeded here and get the value
{

if ( FAILED( _Device->CreateRenderTargetView (p_RT, 0 , &_Target))) /// but her i fail
{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create RenderTargetView! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}

}[/code]



is this the best idea or there are another one ( i feel there are good idea but i don't what is it )

thank you .........
in waiting.........

Share this post


Link to post
Share on other sites
I don't know the reason it's failing for you but I was surprised you need 2 swap chains for you app. Isn't what you really want just:
- create 1 swap chain (along with device)
- get back buffer from swap chain and create render target view for it
- create render target texture and create render target view for it
?

Share this post


Link to post
Share on other sites
[quote]get back buffer from swap chain and create render target view for it[/quote]

is that mean that the swap chain is create back buffer even if i pass
[code]DXGI_USAGE_RENDER_TARGET_OUTPUT[/code] in the device


the reason to use 2 swap chain is i want to do few process to the back buffer ( and its a image or another else after i load it)and its take lot of time
in the same time i want to show the result in render target view

for example i load image and calculate the normal bump and occlusion map ...etc int the back buffer and when the user modify the inputs i calculate
again without waiting exactly like crazybump

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this