From ecc6fb6b0c260cbcad3cea98a0ec445dfa024980 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 31 Dec 2021 13:21:08 +0100 Subject: [PATCH] dxgsg9: Implement ability to get screenshot from multisample backbuffer Fixes #1225 --- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 0138463260..963cf96141 100644 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -2070,6 +2070,35 @@ do_framebuffer_copy_to_ram(Texture *tex, int view, int z, backbuffer -> GetDesc (&surface_description); + // We can't directly call GetRenderTargetData on a multisampled buffer. + // Instead, blit it into a temporary target. + if (surface_description.MultiSampleType != D3DMULTISAMPLE_NONE) { + IDirect3DSurface9 *resolved; + hr = _d3d_device->CreateRenderTarget(surface_description.Width, + surface_description.Height, + surface_description.Format, + D3DMULTISAMPLE_NONE, 0, FALSE, + &resolved, nullptr); + if (FAILED(hr)) { + dxgsg9_cat.error() + << "CreateRenderTarget failed" << D3DERRORSTRING(hr) << "\n"; + backbuffer->Release(); + return false; + } + + _d3d_device->StretchRect(backbuffer, nullptr, resolved, nullptr, D3DTEXF_NONE); + if (FAILED(hr)) { + dxgsg9_cat.error() + << "StretchRect failed" << D3DERRORSTRING(hr) << "\n"; + backbuffer->Release(); + resolved->Release(); + return false; + } + + backbuffer->Release(); + backbuffer = resolved; + } + pool = D3DPOOL_SYSTEMMEM; hr = _d3d_device->CreateOffscreenPlainSurface( surface_description.Width,