152
Chapter 14: Optimizing Rendering
Face Culling
When solid, three-dimensional geometry is rendered, the side of it facing away from the
camera is normally hidden by the side that faces the camera. For example, when a sphere
is rendered, you normally only see its front side.
You can avoid rendering the back side of a geometry using the setCullFace() method,
defined in csContext and csGeoSet as follows:
void setCullFace(csContext::CullFaceEnum cullFace);
The argument in setCullFace() specifies how much of a geometry is rendered. The
possible argument values, enumerated in csContext::CullFaceEnum(), include
• NO_CULL—Both front and back sides of geometries are rendered.
• FRONT_CULL—Only the back sides of all geometries are rendered.
• BACK_CULL—Only the front sides of all geometries are rendered.
• BOTH_CULL—Geometries are not rendered.
getCullFace() returns one of these values, whichever is current.
Not rendering either the front or back side of a geometry improves rendering
performance.
Back Patch Culling
Back patch culling, like back face culling, eliminates from the rendering process parts of
a geometry. Whereas back face culling is based on triangles, back patch culling is based
on primitives, such as a tristrip or trifan. If, for example, you want to cull back faces:
• Back face culling prevents all triangles on the back side of a geometry from being
rendered.
• Back patch culling prevents all primitives wholly on the back of the geometry from
being rendered.
If any part of a primitive is on the front of the geometry, the entire primitive is
rendered, regardless of what part is on the front or back of the geometry.
To optimize the performance of your application, you would commonly back patch cull
and then back face cull your scene graph.