GraphicsDevice.ResolveBackBuffer Method (Texture2D, Int32)

Copies the contents of the back buffer at the specified index to a texture.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public void ResolveBackBuffer (
         Texture2D resolveTarget,
         int backBufferIndex
)

Parameters

  • resolveTarget
    Texture to update with the resolved back buffer. This texture must be created with a usage type of ResourceUsage.ResolveTarget.
  • backBufferIndex
    Index of the back buffer to resolve.

Exceptions

Exception type Condition
ArgumentException

One of the following conditions is true:

  • resolveTarget was not created with ResourceUsage.ResolveTarget.
  • backBufferIndex is not valid. Note that on Xbox 360, there is only one back buffer available and backBufferIndex must be zero.
ArgumentNullException resolveTarget is null
InvalidOperationException ResolveBackBuffer may not be called when the current render target is null. Use ResolveBackBuffer instead.

Remarks

On Xbox 360, the back buffer is cleared when ResolveBackBuffer is called.

Warning

On Xbox 360, all render targets (including the back buffer) share the same memory. Because of this, the previous content of any render target is lost when the render target is changed with SetRenderTarget or when Present is called, which has the same effect as swapping the render target.

To preserve the data in a render target, it is necessary to resolve it, either with ResolveRenderTarget or ResolveBackBuffer. Just remember to resolve the render target before switching the render target to avoid losing data that you want to preserve.

Example

In this example, a new Texture2D is created for use as a render target, the data is initialized with a call to ResolveBackBuffer, and the generation of mipmaps for the resolved render target is requested.

Texture2D renderTargetTexture;

renderTargetTexture = new Texture2D(
    graphics.GraphicsDevice, 
    graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
    graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, 
    0, 
    ResourceUsage.ResolveTarget | ResourceUsage.AutoGenerateMipMap, 
    graphics.GraphicsDevice.PresentationParameters.BackBufferFormat,
    ResourceManagementMode.Manual 
    );

graphics.GraphicsDevice.ResolveBackBuffer( renderTargetTexture );
renderTargetTexture.GenerateMipMaps( TextureFilter.Linear );

See Also

Reference

GraphicsDevice Class
GraphicsDevice Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista