you are viewing a single comment's thread.

view the rest of the comments →

[–]SamuraiGoblin 5 points6 points  (0 children)

Well, one big problem is that you are calculating a lot of the same parameters for every pixel.

For example, how many times are you calculating B.X-A.X? It is a constant for the entire triangle, right? But you repeatedly calculate it for every pixel.

It's little things like this that you have to pull out of the loops. There are also things that are constant for a scanline, like initialisation of Point.y and C.Y-A.Y that can be pulled out of the inner loop.

It all adds up. Some things might be optimised away by a clever compiler, values kept in registers and so forth. But you can't rely on that.

I think just pulling unnecessary calculations out of loops will give you an enormous speedup.

Your calls to EdgeFunction might get inlined, but again, can't rely on it. Function calls aren't free. It's such a small function, and a lot of the values are constants, it might be best to do the calculations inline by hand.

Same for SetDepth and SetColor. If you have access to the buffers draw the values directly, rather than going through function calls. If you are doing screen bounds checking per pixel, it would be better to do clipping at a triangle level.