Graphics Reference
In-Depth Information
We have discussed how to calculate the orientation of a triangle. To
determine whether the triangle needs to be culled, we need to know the
facing of triangles that are to be culled. This is specified by the application
using the following API call:
void
glCullFace
(GLenum
mode
)
mode
specifies the facing of triangles that are to be culled. Valid values
are
GL_FRONT
,
GL_BACK
, and
GL_FRONT_AND_BACK
. The default
value is
GL_BACK
.
Last but not least, we need to know whether the culling operation
should be performed. The culling operation will be performed if the
GL_CULL_FACE
state is enabled. The
GL_CULL_FACE
state can be enabled or
disabled by the application using the following API calls:
void
glEnable
(GLenum
cap
)
void
glDisable
(GLenum
cap
)
where
cap
is set to
GL_CULL_FACE
. Initially, culling is disabled.
To recap, to cull appropriate triangles, an OpenGL ES application must
first enable culling using
glEnable
(
GL_CULL_FACE
), set the appropriate
cull face using
glCullFace
, and set the orientation of front-facing
triangles using
glFrontFace
.
Note:
Culling should always be enabled to avoid the GPU wasting time
rasterizing triangles that are not visible. Enabling culling should
improve the overall performance of the OpenGL ES application.
Consider the case where we are drawing two polygons that overlap each
other. You will most likely notice artifacts, as shown in Figure 7-11. These
artifacts, called
Z-fighting artifacts
, occur because of limited precision of
triangle rasterization, which can affect the precision of the depth values
generated per fragment, resulting in artifacts. The limited precision of
parameters used by triangle rasterization and generated depth values per
fragment will get better and better but will never be completely resolved.