My code uses the DDA algorithm, because that is the algorithm I use for drawing triangles and using two different algorithms would cause graphical glitches.
It uses rounded fixed point maths for one of the iterating values to ensure accuracy, and to ensure that polygons line up.
It has special cases for horizontal lines, because horizontal lines can be drawn two pixels at a time in good conditions and for vertical lines because they are common so a special case is faster.
All the other algorithms try to use pointer arithmetic wherever possible to remove multiplies, there is still a multiply in the function for drawing shallow lines which I intend to remove.
The main optimization is clipping
- If lines are completely outside the screen then they aren't drawn (best case).
- If lines potentially intersect the screen then it will draw them with clipping (worst case).
- If lines are completely within the scene then it will draw them without clipping (common case).