Jump to content
  • Advertisement
Sign in to follow this  
Belkacem

copy from backbuffer to rendertaget

This topic is 2598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

_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);
}



and create the back buffer like this


::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 );





her is the the problem

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

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);
}

}


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

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);
}

}




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
Advertisement
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
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
DXGI_USAGE_RENDER_TARGET_OUTPUT 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
i find something may be help

i think that the technique that i want to use is display scan out and also have another name

off screen rendering

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!