How does a GPU actually draw stuff to the screen? How do you tell it what to draw? These are the type of questions we’ll explore in this post.

  • you send vertices to the GPU memory
  • you specify a vertex/fragment shader to use for each vertex/fragment
  • you tell the GPU to draw the verticies
    • drawing vertices itself doesn’t make much sense, so you also tell it how to interpret the vertices into primitives (triangles, lines, points)
    • for example, you can tell it to interpret each group of 3 vertices in your vertex list as a triangle, so it will essentially draw a bunch of triangles
  • GPU then starts the process of “drawing” your vertices/triangles
    • first, it runs your vertex shader on each vertex (in parallel)
      • vertex shader should transform your vertices into clip space
    • then it constructs primitives (triangles) from your vertices, and any primitives that are outside the view frustum are discarded (in parallel)
    • then it converts your vertices from clip space to NDC (in parallel)
    • then it applies a viewport transformation to your vertices (in parallel)
      • this maps from NDC to “screen space” or “back buffer space”
    • then it interpolates values for color/uv/normal/etc for fragments based on the surrounding vertices, and calls the fragment shader on each fragment (in parallel)
    • now you have a color for each fragment (pixel) in the backbuffer
    • GPU tells the display to show the backbuffer

TODO: did summary, now finish article