4

I am hoping this is a easy answer to an easy question which I cannot find an answer to.

How do I access the front buffer in Directx 11 / DXGI? I have found in Directx 9 you can use GetFrontBufferData() and you can use GetBuffer() in Directx 11 to get access to the backbuffer but there are problems with this. The backbuffer doesn't have calculations done to it that the front buffer does.

So I was wondering if there is something I am missing.

I could try using GetDisplaySurfaceData and unless I have mis-understood something then it wouldn't work because I am not always in full-screen mode.

Edit: Could someone let me know how the GetBuffer works in SwapChain for Directx 11. As I have read that antialiasing only occurs on the front buffer and never a backbuffer. Is 0 the first backbuffer? (Microsoft state that you can only use 0 in certain instances.)

Is it possible at all to get the Front Buffer in Directx 11?

Many thanks,

user2600628
  • 95
  • 1
  • 8
  • Why do you need the front buffer at all? Almost all rendering operations you can do, aside from AA, are done on the back buffer. – Alex Aug 27 '13 at 13:43
  • Because I want the AA. – user2600628 Aug 27 '13 at 14:00
  • When the swap chain is created you can specify multisampling, which will allow you to turn on MSAA. If you don't want MSAA, you can create the swap chain without multisampling and set AntialiasedLineEnable to true in the rasterizer state for the device. If neither of these work for you, disable automatic antialiasing, render your whole scene, then get the backbuffer and do AA through a custom shader. Other than that, there's not much else you can do. See [the community content here](http://msdn.microsoft.com/en-us/library/windows/desktop/ff476198(v=vs.85).aspx) for more info. – Alex Aug 27 '13 at 14:59

1 Answers1

3

You need to use the IDXGISwapChain::GetBuffer API to retrieve a swap chain surface ( use the uuid ID3D11Texture2D for the result type ).

Now, the swap chain buffers are not mapable, so you need to copy it to a staging resource.

  • Use ID3D11Texture2D::GetDesc to retrieve the surface description
  • Patch it with a D3D11_USAGE_STAGING usage and a cpu access flag of D3D11_CPU_ACCESS_READ
  • Create a temporary surface ID3D11Device::CreateTexture2D
  • Copy to the staging surface ID3D11DeviceContext::CopyResource

You now have a ID3D11Texture2D with the content of your swap chain buffer that allow you to use the ID3D11DeviceContext::Map API to read it on the CPU

galop1n
  • 8,573
  • 22
  • 36
  • 1
    As I understand that is the back buffer, or am I mistaken. If that is not the backbuffer where is the backbuffer? – user2600628 Aug 27 '13 at 13:04
  • The front buffer is not accessible with DXGI. It is rare to render to the back buffer directly and let the swap chain resolve the multisampling anyway. Create a single sample swap chain and an additional multi sample framebuffer, then call `ID3D11DeviceContext::ResolveSubresource` to merge the samples to the back buffer then do what i explain to dump it before presentation. – galop1n Aug 27 '13 at 13:55
  • When reading Microsoft, it states that only the FrontBuffer has been antialiased. Is this no longer true? – user2600628 Aug 27 '13 at 14:00
  • The swap chain is able to resolve a multi sample back buffer to a single sample front buffer for you and may also do some scaling to fit the image to the window. When you depends on an automatic service, it is common to loose control. That is the reason to do things by yourself, it lets you render some non antialiased surface like 2D interfaces after the `ResolveSubresource` call or with a manual full screen quad with a custom shader to merge fragments as you want. – galop1n Aug 27 '13 at 14:14