locked
DirectXTK large offscreen RenderTarget cannot copy to small Backbuffer RenderTarget

    Question

  • I have create a RenderTarget with size 1920x1080,
    but the screen size is 1366x768.

    I draw all image to the 1920x1080 RT, and then draw the 1920x1080 RT's image to 1366x768 backbuffer RT.

    I found only the 1366x768 rect image be draw to 1920x1080 RT.

    I want to know whether the DirectXTK SpriteBatch clip the 1920x1080 RT to 1366x768 RT?

    【use 1920x1080 RT draw to 1366x768 screen backbuffer】

    1920x1080 RT draw to 1366x768 screen

    【not use 1920x1080 RT, only use one backbuffer】

    not use 1920x1080 RT

    【the code use 1920x1080 RT darw to 1366x768 RT】

     CD3D11_TEXTURE2D_DESC sceneDesc(DXGI_FORMAT_B8G8R8A8_UNORM, 1920, 1080,
      1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
     DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D(&sceneDesc, nullptr,
      m_sceneTex.GetAddressOf()));
     DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView(m_sceneTex.Get(), nullptr,
      m_sceneRT.ReleaseAndGetAddressOf()));
     DX::ThrowIfFailed(m_d3dDevice->CreateShaderResourceView(m_sceneTex.Get(), nullptr,
      m_sceneSRV.ReleaseAndGetAddressOf()));

    //... sceneRT is 1920x1080 m_d3dContext->OMSetRenderTargets(1, m_sceneRT.GetAddressOf(), nullptr); //... m_sprites->Begin(SpriteSortMode_Deferred, m_states->NonPremultiplied(), nullptr, nullptr, nullptr, nullptr, transformMaxtrix); // ... draw all image to 1920x1080 RT m_sprites->End(); ID3D11RenderTarge

    tView *const targets[1] = { m_deviceResources->GetBackBufferRenderTargetView() }; m_deviceResources->GetDepthStencilView()); m_d3dContext->OMSetRenderTargets(1, targets, nullptr);  m_sprites->Begin(SpriteSortMode_Deferred, m_states->NonPremultiplied(),
    nullptr, nullptr, nullptr, nullptr, transformMaxtrix);m_sprites->Draw(m_sceneSRV.Get(), dstRect, &srcRect, Colors::White); m_sprites->Draw(m_sceneSRV.Get(), dstRect, &srcRect, Colors::White);

    m_sprites->End(); ID3D11ShaderResourceView* null[] = { nullptr, nullptr }; m_d3dContext->PSSetShaderResources(0, 2, null);

    I think may be the SpriteBatch.Draw be clip by the DirectXTK,
    so the image outside the 1366x768 rect can't draw on the 1920x1080 RT.

    Please tell me how to fix it!


    • Edited by lihuipeng49 Tuesday, February 10, 2015 11:38 AM
    Tuesday, February 10, 2015 7:50 AM

Answers

  • You are use OMSetRenderTargets to change targets, but you are failing to call RSSetViewports to reflect the change in size. This wouldn't be an issue if your backbuffer were larger than your intermediate render target, but since you are going the other way the original viewport is clipping your intermediate render target.

    Also, you should not need srcRect for your final spritebatch draw.

    Tuesday, February 10, 2015 7:37 PM

All replies

  • I'll have our DirectX guru check out this post.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 10, 2015 1:22 PM
    Moderator
  • You are use OMSetRenderTargets to change targets, but you are failing to call RSSetViewports to reflect the change in size. This wouldn't be an issue if your backbuffer were larger than your intermediate render target, but since you are going the other way the original viewport is clipping your intermediate render target.

    Also, you should not need srcRect for your final spritebatch draw.

    Tuesday, February 10, 2015 7:37 PM