How to obtain the underlying backbuffer render target

I’m trying to implement a screen shot function but I can’t find out how to obtain a reference to the underlying backbuffer render target. Whenever I worked with native DirectX I always used this to quickly save screenshots but I can’t seem to find anything about it in Monogame.

Render to a render target and use Texture2D.GetData then save the data or use Texture2D.SaveToPng/Texture2D.SaveToJpeg. I have a PR up to implement GraphicsDevice.GetBackBufferData so you can get texture data directly from the back buffer, but that’s currently not implemented in the develop version.

Alternatively you can use reflection to get the DX handle (assuming DX is the backed you’re using) and go from there. You can check MonoGame source code to see how to get it. This is not cross platform though, and it’s easier to let MG do the heavy lifting.

Alright I’ll try the backdoor method since I do have some experience with reflection in C#. It doesn’t matter to me atm as Windows is the only platform I plan on supporting right now.

Edit: Actually now that I think about it, the render target method is much cleaner given how my rendering system is setup lol. Even if the other method would probably be more efficient.

Rendering that one frame to a render target is definitely the recommended approach. I have done this for previous released titles.