Problem with saving a render target view's content to a texture

Started by
5 comments, last by pnt1614 11 years, 11 months ago
If I create a new render target and bind to the pipeline with a render target view, then I save that render target view to a texture, it is okay.


#pragma region Setup the render target texture description
D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = 256;
textureDesc.Height = 256;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
V_RETURN( pd3dDevice->CreateTexture2D( &textureDesc, NULL, &g_pRenderTargetTexture ) );
#pragma endregion

#pragma region Setup the description of the render target view
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;
V_RETURN( pd3dDevice->CreateRenderTargetView( g_pRenderTargetTexture, &renderTargetViewDesc, &g_pRenderTargetView) );
#pragma endregion


However, if I get the current render target view, which is got with a function named DXUTGetD3D11RenderTargetView, then just render. But the same code, saving to a texture, it does not work, everything is black


ID3D11Resource *backbufferRes;
pRTV->GetResource(&backbufferRes);
D3D11_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = 0;
texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texDesc.Width = 640; // the current viewport is 640x480
texDesc.Height = 480;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D11_USAGE_DEFAULT;
ID3D11Texture2D *texture;
V( pd3dDevice->CreateTexture2D(&texDesc, 0, &texture) );
pd3dImmediateContext->CopyResource(texture, backbufferRes);
hr = D3DX11SaveTextureToFile( pd3dImmediateContext, texture, D3DX11_IFF_JPG, L"test.jpg");

SAFE_RELEASE( texture );
SAFE_RELEASE( backbufferRes );


I do not understand the reason, anybody have experienced this problem, help me please. Thank in advance.
Advertisement
The CopyResource call is probably failing because the backbuffer isn't the same format as the texture you're creating. You should pass the DEBUG flag when creating the device, and then it will tell you when something goes wrong.
I am using DXUT and the device is created automatically, so how to set DEBUG flag when it is being created?
i think you can forceenable the debuglayer aswell via the directx controllpanel.
"There will be major features. none to be thought of yet"
Generally I'd do a GetDesc on the backbuffer and then just modify the things I need to change - probably the handiest way of ensuring that formats/sizes/etc always match.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

In your "ModifyDeviceSettings" callback, set the "CreateFlags" member of the D3D11 settings to D3D11_CREATE_DEVICE_DEBUG
thank everyone, I got it.

This topic is closed to new replies.

Advertisement