Click or drag to resize
AB4D logo

DXSceneCreateCustomRenderingContext(Int32, Int32, Int32, BackBufferReadyEventHandler, DisposeList) Method

Creates a CustomRenderingContext with all needed DirectX buffers and views that can be used to call RenderScene with custom RenderingContext. The created RenderingContext can be used in RenderScene(RenderingContext, Boolean) or RenderScene(RenderingContext, Boolean, Boolean, DXScene) methods.

Namespace: Ab3d.DirectX
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.0.8865.1045
Syntax
C#
public CustomRenderingContext CreateCustomRenderingContext(
	int width,
	int height,
	int preferedMultisampling,
	BackBufferReadyEventHandler renderedTextureReadyCallback,
	out DisposeList objectsToDispose
)

Parameters

width  Int32
width of the rendered bitmap
height  Int32
height of the rendered bitmap
preferedMultisampling  Int32
multisampling count that is used to render the image (used if possible)
renderedTextureReadyCallback  BackBufferReadyEventHandler
Delegate that is called when the scene is rendered. In this delegate it is possible to read the memory with the rendered buffer.
objectsToDispose  DisposeList
DisposeList with all the created objects that need to be disposed when they are no longer used

Return Value

CustomRenderingContext
CustomRenderingContext with all needed DirectX buffers and views
Example

The following example shows how to use CreateCustomRenderingContext to render to WPF's WriteableBitmap:

C#
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, 
      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();
See Also