From Cradle to Framebuffer
Before any pixels appear on the screen, your models must pass through an obstacle course of manipulations and challenges called the graphics pipeline. The pipeline roughly follows these stages:
- A geometric model is loaded or generated by your application and uploaded to the GPU in VBOs.
- The application issues a draw call.
- The vertex shader transforms the vertices, passing each through a series of coordinate systems that are convenient for performing various operations.
- Primitives that extend outside of the viewport are clipped so only their visible portions continue on through the pipeline.
- The positions of the clipped vertices are transformed into pixel coordinates.
- The fragment shader computes the colors of the fragments that fall between the surviving vertices.
- Fragments are tested to see if their colors should be written to the framebuffer. One typical test rejects any fragments that are farther from the viewer than a fragment drawn earlier.
- The colors of the surviving fragments either overwrite or blend with colors already written to the framebuffer.
You explored some of these stages in earlier chapters. For example, you've seen how to issue draw calls and write shaders for simple models defined in a small region of a 2D coordinate system. In this chapter, we open up all of space so that we can render complex 3D scenes containing many models. By the chapter's end, you'll be able to answer the following questions:
- What are the coordinate spaces that a model passes through on its way to being rasterized?
- How can we change what chunk of a virtual world is rendered into the viewport?
- How can we change the region of the viewport in which we render so that we may draw mini-maps and split-screens?
- Which color should be assigned to a pixel if many fragments are contending for it in a complex scene?
Once you've got a handle on this graphics pipeline, you'll be able to put the human viewer into a scene full of moving 3D models.