DXSceneCreate |
public CustomRenderingContext CreateCustomRenderingContext( int width, int height, int preferedMultisampling, int supersamplingCount, Format backBufferFormat, Format depthStencilFormat, BackBufferReadyEventHandler renderedTextureReadyCallback, VirtualRealityProviderBase virtualRealityProvider, out DisposeList objectsToDispose )
The following example shows how to use CreateCustomRenderingContext to render to WPF's WriteableBitmap:
DisposeList objectsToDispose; int width = 512; int height = 512; int preferedMultisampling = 4; int frameNumber = 1; // increase that on each call var writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null); // Create custom RenderingContext with the required buffers and other resources - stored in objectsToDispose // Also define the callback method that will be called when the rendered image is available in main CPU memory var renderingContext = CreateCustomRenderingContext( width, height, preferedMultisampling, supersamplingCount, Format.B8G8R8A8_UNorm, Format.D32_Float, delegate (object sender, BackBufferReadyEventArgs e) { // delegate used by RenderToBitmap method - it is called when the scene is rendered to back buffer and it is available in main CPU memory writeableBitmap.Lock(); var viewportRect = new Int32Rect(0, 0, e.Width, e.Height); // Copy bitmap from e.Data.DataPointer to writeableBitmap writeableBitmap.WritePixels(viewportRect, e.Data.DataPointer, e.Data.SlicePitch, e.Data.RowPitch); writeableBitmap.AddDirtyRect(viewportRect); writeableBitmap.Unlock(); }, out objectsToDispose); // Make sure that frameNumber is increased on each call to ensure that update is called renderingContext.SetPerFrameData(frameNumber, ChangeNotifications.All); // render the scene with custom RenderingContext RenderScene(renderingContext); objectsToDispose.Dispose();