Reputation: 2604
This is mostly a theoretical question.
Let's say I want to draw a triangle on the screen. If I supply my vertex shader with 3 points in 3d, it will convert them to 3 points in 2d, in window coordinates, or screen coordinates. Basically 3 pixel coordinates on your monitor or display.
How, from here, does the graphics pipeline go about filling in this triangle, based on those three points? My guess is something like this:
Bound the triangle with a box by determining the upper and lower bounds for x and y like so:
Use Bresenham's line algorithm to draw the 3 edges of the triangle with 3 different colors. You cannot use the regular color buffer for this step.
Do this for every row of pixels in the box: Start from the leftmost pixel (in whereever you stored the results of step 2), go right until you hit an edge. Now, keep going right, coloring pixels in (running the fragment shader), and writing to the regular color buffer, until you hit a different line (hitting a different colored pixel in whereever the results of step 2 was stored). Then stop and go to the next line.
Draw the edges with the fragment shader in the regular color buffer.
This seems like a complicated and inefficient solution. How is it actually done?
Upvotes: 1
Views: 2347
Reputation: 372
Have a look at the scanline algorithm. It's basically moving a horizontal line from top to bottom, calculating the two intersections of this scanline with the triangle, then drawing a line between these two points.
Upvotes: 2