Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!

We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 steven166   Members   -  Reputation: 234


Posted 23 May 2012 - 08:45 PM

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;
        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.


#2 MJP   Moderators   -  Reputation: 11569


Posted 23 May 2012 - 11:25 PM

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.

#3 steven166   Members   -  Reputation: 234


Posted 24 May 2012 - 12:44 AM

I am using DXUT and the device is created automatically, so how to set DEBUG flag when it is being created?

#4 Tordin   Members   -  Reputation: 604


Posted 24 May 2012 - 04:24 AM

i think you can forceenable the debuglayer aswell via the directx controllpanel.
"There will be major features. none to be thought of yet"

#5 mhagain   Crossbones+   -  Reputation: 8136


Posted 24 May 2012 - 05:24 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

#6 MJP   Moderators   -  Reputation: 11569


Posted 24 May 2012 - 09:58 AM

In your "ModifyDeviceSettings" callback, set the "CreateFlags" member of the D3D11 settings to D3D11_CREATE_DEVICE_DEBUG

#7 steven166   Members   -  Reputation: 234


Posted 24 May 2012 - 09:36 PM

thank everyone, I got it.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.