# What kind of culling does XNA do for me?

Which kinds of culling and clipping does XNA do for me as default, and which kinds does it not?

Z-culling? Backface culling? etc.

## 2 Answers

Z-culling (culls pixels that are behind already-drawn pixels in the Z-buffer) and back-face culling (culls triangles that are facing away from the camera) are handled by the DepthStencilState and RasterizerState respectively. These are state objects.

They are also the names of properties where you can set those state objects on the GraphicsDevice (MSDN).

The default values are:

DepthStencilState.Default (MSDN) which is set up to both read and write from the depth buffer.

RasterizerState.CullCounterClockwise (MSDN) which is set up to cull triangles where the vertices are counter-clockwise.

There are other built-in states available on the state objects, see the static members for each state object (MSDN: DepthStencilState, RasterizerState). Additionally you can create your own state objects that further customise the behaviour.

XNA itself does not provide any built-in culling mechanisms, except exposing those provided by the graphics device. These include Z-culling and backface-culling. You could also argue that the stencil buffer, scissor tests, and the viewport are also kinds of culling.

XNA does, however, provide some useful classes for adding your own, more advanced, object-level culling mechanisms. For example BoundingFrustum provides intersection tests to allow you to determine what objects (usually represented by a BoundingBox or BoundingSphere) are visible in your 3D camera.

This question and answer provide some useful information about how to decide where culling is appropriate.

The default value is CullMode.CounterClockwise. Options are:

• CullClockwiseFace - Cull back faces with clockwise vertices.
• CullCounterClockwiseFace - Cull back faces with counterclockwise vertices.
• None - Do not cull back faces.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.cullmode.aspx