liveBook · Manning

Rasterization pipeline

As explained in Systems Programming with Zig

A rasterization pipeline is a graphics-processing sequence that converts geometric primitives into shaded fragments and writes them to a framebuffer.

To draw a triangle with OpenGL, you supply geometry, configure the pipeline, and issue a draw call. The pipeline turns points in space into fragments, shades them, and writes the resulting image to a framebuffer. section 7.1.2 section 7.6

A draw call sets the pipeline in motion:

  • Vertex processing: A vertex shader runs for each vertex. It can move points or use matrix math to project a 3D scene onto the screen. section 7.1.2
  • Rasterization: Vertices are assembled into shapes, which are converted into fragments. section 7.1.2
  • Fragment processing: A fragment shader runs on each fragment and determines its color. Fragments are then assembled into an image. section 7.1.2 section 7.4.4
Figure 7.1 The rasterization pipeline
CH07 F01 hinsonhasty

Follow the pipeline from vertex processing through rasterization and fragment processing. section 7.1.2

One triangle

A draw call for one triangle processes three vertices in the vertex shader. The rasterized triangle produces fragments according to the screen space it occupies, and the fragment shader runs on each one. section 7.4.4

Vertex attributes provide the inputs for each vertex, usually including its position. Attribute data lives in buffers; the vertex shader works with one set of attributes at a time, allowing parallel processing. A vertex array object (VAO) preserves attribute state, including layouts and properties, for use with shader programs. section 7.4.4

Listing 7.12 An abstract object
var vao: c_uint = undefined;
c.glGenVertexArrays(1, &vao); #1
defer c.glDeleteVertexArrays(1, &vao); #2

Create a VAO name and arrange for its deletion with Zig’s defer. The VAO still needs vertex data to configure. section 7.4.4

How Systems Programming with Zig covers it

How deep it goes
Explains vertex processing, geometry assembly, fragment shading, and framebuffer output, with practical detail on vertex attributes and VAO state.
Examples
Uses a single triangle to relate three vertex shader executions to a screen-space-dependent number of fragments.
What you can do after
Apply it via OpenGL by supplying vertex data, configuring pipeline state, and issuing a draw call.
How it connects
Connects rasterization to vertex shaders, fragment shaders, vertex attributes, vertex array objects, and framebuffers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.