March 21, 2005

Managed DirectX Inconsistencies

Explain this to me if you can.

The following code will take a screenshot of whatever is in the backbuffer at the time it is called:

Public Sub SaveScreenshot(ByVal filename As String, Optional ByVal fileformat As ImageFileFormat = ImageFileFormat.Bmp)
Dim backbuffer As Surface = VideoDevice.GetBackBuffer(0, 0, BackBufferType.Mono)
SurfaceLoader.Save(filename, fileformat, backbuffer)
backbuffer.Dispose()
End Sub

...which means that Managed DirectX is extracting the back buffer to system memory, converting the surface to a GDI+ image, and exporting the image to a file.

I'm fine with that, and I support the functionality. So, if Managed DirectX can handle that, why won't it let me extract out the back buffer to system memory so that I can do some intense back buffer effects?

2 comments:

Larry O'Brien said...

I've just been facing the same thing and have been intending to see if a memory-mapped file would do the trick. Have you tried this approach?

Michael Russell said...

I tried using SurfaceLoader.SaveToStream, re-reading it back in, and then disposing of the stream, but the GC's killed my performance, as would be expected.

Fact of the matter is that I shouldn't have to convert it to an image and then read it back in. If DirectX has the ability to suck the bits out of the back buffer, why isn't it exposed to us?