Click or drag to resize
AB4D logo

RenderingContextRegisterBackBufferMapping(BackBufferReadyEventHandler) Method

RegisterBackBufferMapping method is used to register a specified callback delegate that is called only once when the next frame is rendered. The render frame is also rendered into a special staging back buffer and that buffer is mapped so it can be accessed by the CPU (copied into main memory). This method creates an ad-hoc staging back buffer that is disposed after the stagingBackBufferMappedCallback is called. If you want to get multiple frames or specify your own staging back buffer the use the RegisterBackBufferMapping(Texture2D, Texture2DDescription, BackBufferReadyEventHandler) method.

Namespace: Ab3d.DirectX
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.0.8865.1045
Syntax
C#
public void RegisterBackBufferMapping(
	BackBufferReadyEventHandler stagingBackBufferMappedCallback
)

Parameters

stagingBackBufferMappedCallback  BackBufferReadyEventHandler
Delegate that is called when the staging back buffer has been mapped and is ready to be copied from GPU memory to the main memory
Remarks

RegisterBackBufferMapping method is used to register a specified callback delegate that is called only once when the next frame is rendered. The render frame is also rendered into a special staging back buffer and that buffer is mapped so it can be accessed by the CPU (copied into main memory).

This method creates an ad-hoc staging back buffer that is disposed after the stagingBackBufferMappedCallback is called.

If you want to get multiple frames or specify your own staging back buffer the use the RegisterBackBufferMapping(Texture2D, Texture2DDescription, BackBufferReadyEventHandler) method.

If the method is called with null value for delegate, then this cancels the previously registered delegate and disposes all created buffers.

The following example shows how to render the current scene to a WriteableBitmap (taken from Ab3d.DirectX.Client.Diagnostics project from DiagnosticsWindow.xaml.cs):

Example
// _renderedBitmap is a field of type WriteableBitmap and is used in the SaveRenderedBitmap (not shown here) // to save the rendered bitmap. DXView.DXScene.RenderingContext.RegisterBackBufferMapping(delegate (object sender, BackBufferReadyEventArgs e) { // We will copy rendered image into a new WriteableBitmap _renderedBitmap = new WriteableBitmap(e.Width, e.Height, 96, 96, PixelFormats.Bgra32, null); // delegate used by RenderToBitmap method - it is called when the scene is rendered to back buffer and it is available in main CPU memory _renderedBitmap.Lock(); var viewportRect = new Int32Rect(0, 0, e.Width, e.Height); // Copy bitmap from e.Data.DataPointer to writeableBitmap _renderedBitmap.WritePixels(viewportRect, e.Data.DataPointer, e.Data.SlicePitch, e.Data.RowPitch); _renderedBitmap.AddDirtyRect(viewportRect); _renderedBitmap.Unlock(); // We do not want to show SaveFileDialog inside a rendering pipeline. // So once we have the image in main memory in WriteableBitmap, we delay the invoke of saving bitmap and exit this callback Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(SaveRenderedBitmap)); }); // After we have subscribed to capture next frame, we can force rendering that frame DXView.Refresh();
See Also