O'Reilly logo

Graphics Shaders, 2nd Edition by Steve Cunningham, Mike Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1
The Fixed-Function
Graphics Pipeline
1
In your rst course in computer graphics, you probably used a graphics API
to help you create your projects. Because this book focuses on graphics using
OpenGL, we assume that your API was OpenGL, and in this chapter we
review the graphics pipeline as it is expressed in OpenGL versions 1.x. If you
used a dierent API, especially in a rst graphics course, your experience was
probably very close to the OpenGL approach. These APIs used a xed-function
pipeline, or a pipeline with a xed set of operations on vertices and fragments.
In the rest of this book, we will look at the shader capabilities of OpenGL ver-
sions 2.x and how you can use them to create eects that are dicult or impos-
sible with the xed-function pipeline.
2
1. The Fixed-Function Graphics Pipeline
The Traditional View
When you develop a graphics application with the OpenGL API, you dene
geometry, viewing, projection, and a number of appearance properties.
Objects’ geometries are dened by their vertices, their normals, and their
graphics primitives, specied by
glBegin-glEnd pairs that encompass points,
lines, geometry-compressed groups, or polygons. Viewing and projection are
each dened with a specic function. Appearance is specied by dening
color, shading, materials, and lighting, or texture mapping. This information
is all processed in a very straightforward way by the xed-function OpenGL
system, acting either in software or in a graphics card.
The simplest way to view OpenGL’s operations is to think of it as using
two connected operations: a vertex-processing operation and a pixel-processing
operation. Each operation in xed-function OpenGL has a pre-determined set
of capabilities. It is important to understand how the geometry and appear-
ance directives you give are carried out in the pipelines. When you work with
shaders, though, it is more than important to understand the pipelines; your
shaders will actually take over part of these operations, so you absolutely must
understand them.
The Vertex Operation
To create the geometry of a scene, you specify primitives and vertices, and
operations that act on each vertex and create its pixel coordinates in screen
space. The primitive you specied then determines the pixels that must be
lled to represent it, and any appearance information you specied is used to
determine how those pixels are to be colored in the pixel-processing operation.
The geometry part of the vertex processing follows the ow in Figure 1.1. The
geometry processing is carried out for each vertex independently of any infor-
mation on grouping in your specied primitive; the grouping information is
only used after the vertices nish the vertex processing.
The rst stage of the vertex operation denes the fundamental geom-
etry of your scene. The input to this stage is the set of vertex denitions (your
glVertex*, glNormal*, and glTexCoord* function calls) and the grouping de-
nition (your
glBegin(...) and glEnd( ) function calls) that you set for the
scene. Each piece of geometry is created, or modeled, in its own model space.
This coordinate space can be anything that makes it easy for you to dene
the vertices and relationships for your model. Modeling functions include any
operations you may need to create these denitions and often use mathemati-
cal functions operating in the model space. As we noted, the geometry might

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required