OcclusionQuery Class

Used to perform an occlusion query against the latest drawn objects.

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

Syntax

public class OcclusionQuery : GraphicsResource

Remarks

An occlusion query is a technique that determines how many pixels were actually drawn during a set of draw calls. This is useful for certain rendering techniques and rendering optimizations.

An example of using this query follows:

      OcclusionQuery query = new OcclusionQuery(device);

      query.Begin();
      // Drawing simple objects, bounding areas, etc.
      query.End();

      // Do additional work here to provide enough time for the GPU to complete query execution.
      
      // Draw additional models
      if (query.IsComplete == true && query.PixelCount > 0)
      {
      // A non-zero pixel count means some of the low res model is visible
      // so let's draw the real version of it
      }
    

The number of non-occluded pixels (indicated by PixelCount) can differ based on the platform.

For Xbox 360 games, PixelCount represents the number of pixels modified by drawing. This includes GraphicsDevice.Clear calls and any drawing associated with sprite batches.

For Windows games, PixelCount represents the number of pixels that passed the depth and stencil tests. This does not include sprite batch drawing (because the depth test is turned off) or calls to GraphicsDevice.Clear.

To achieve consistent results across all platforms, use occlusion queries only when the depth buffer is enabled. In addition, avoid calling Clear or changing the assigned render target inside an occlusion query begin/end block.

See Also

Reference

OcclusionQuery Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP