next up previous contents
Next: 18.2 Optimizing Your Application Up: 18.1 What Is Pipeline Previous: 18.1.2.3 Rasterization Bottlenecks

   
18.1.3 Measuring Depth Complexity

Finding depth complexity, or how many fragments were generated for each pixel in a rendered scene, is important for analyzing rasterization performance. It indicates how well polygons are distributed across the framebuffer and how many fragments were generated and discarded - clues for application tuning.

One way to show depth complexity is to use the color values of the pixels in the scene to indicate the number of times a pixel was written. It is relatively easy to draw an image representing depth complexity with the stencil buffer. The basic approach is simple. Increment a pixel's stencil value every time the pixel is written. When the scene is finished, read back the stencil buffer and display it in the color buffer, color coding the different stencil values.

This technique generates a count of the number of fragments generated for each pixel, whether the depth test failed or not. By changing the stencil operations, a similar technique could be used to count the number of fragments discarded after failing the depth test or to count the number of times a pixel was covered by fragments passing the depth test.

Here's the procedure in more detail:

1.
Clear the depth and stencil buffer:
glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2.
Enable stenciling:
glEnable(GL_STENCIL_TEST);
3.
Set up the proper stencil parameters:
glStencilFunc(GL_ALWAYS, 0, 0);
glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
4.
Draw the scene.
5.
Read back the stencil buffer with glReadPixels() using GL_STENCIL_INDEX as the format argument.
6.
Draw the stencil buffer to the screen using glDrawPixels() with GL_COLOR_INDEX as the format argument.

You can control the mapping of stencil values to colors by glPixelMap(). You can map the stencil values to either RGBA or color index values, depending on the type of color buffer to which you're writing. In color index mode, you must turn on the color mapping with glPixelTransferiGL_MAP_COLOR, GL_TRUE(GL_MAP_COLOR, GL_TRUE).


next up previous contents
Next: 18.2 Optimizing Your Application Up: 18.1 What Is Pipeline Previous: 18.1.2.3 Rasterization Bottlenecks
David Blythe
1999-08-06