D3DImage.SetBackBuffer Method (D3DResourceType, IntPtr)


Assigns a Direct3D surface as the source of the back buffer.

Namespace:   System.Windows.Interop
Assembly:  PresentationCore (in PresentationCore.dll)

public void SetBackBuffer(
	D3DResourceType backBufferType,
	IntPtr backBuffer


Type: System.Windows.Interop.D3DResourceType

The type of Direct3D surface. Must be a valid D3DResourceType.

Type: System.IntPtr

The Direct3D surface to assign as the back buffer.

Exception Condition

The D3DImage has not been locked by a call to the Lock or TryLock methods.


backBufferType is not a valid D3DResourceType.


The creation parameters for backBuffer do not meet the requirements for the backBufferType-or-The backBuffer device is not valid.

Call the SetBackBuffer method to assign a Direct3D surface to the back buffer.


Performance depends greatly on the settings of the Direct3D surface. For more information, see Performance Considerations for Direct3D9 and WPF Interoperability.

Calling the SetBackBuffer(D3DResourceType, IntPtr) overload is identical to calling the SetBackBuffer(D3DResourceType, IntPtr, Boolean) overload with the enableSoftwareFallback parameter set to false. When you call SetBackBuffer(D3DResourceType, IntPtr) or call SetBackBuffer(D3DResourceType, IntPtr, Boolean) with the enableSoftwareFallback parameter set to false, the rendering system releases its reference to the back buffer when front buffer becomes unavailable and nothing is displayed. When the front buffer is available again, the rendering system raises the IsFrontBufferAvailableChanged event to notify your WPF application. You can create an event handler for the IsFrontBufferAvailableChanged event to restart rendering again with a valid Direct3D surface. To restart rendering, you must call SetBackBuffer.

The following list shows the required back buffer settings for the IDirect3DSurface9 type.

  • D3DFMT_A8R8G8B8 or D3DFMT_X8R8G8B8



Multisampling is allowed on IDirect3DSurface9Ex surfaces only.

The following code example shows how to call the SetBackBuffer method to assign a Direct3D surface. For more information, see Walkthrough: Hosting Direct3D9 Content in WPF.

// Repeatedly calling SetBackBuffer with the same IntPtr is 
// a no-op. There is no performance penalty.
d3dimg.SetBackBuffer(D3DResourceType.IDirect3DSurface9, pSurface);
d3dimg.AddDirtyRect(new Int32Rect(0, 0, d3dimg.PixelWidth, d3dimg.PixelHeight));


for access to unmanaged resources. Security action: Demand. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

.NET Framework
Available since 3.0
Return to top