After spending quite a few hours on optimizing a software renderer, I realized if you have to do multiple color manipulation on a pixel, it’s might be just faster to represent it in 3 separate channel instead of of rrggbb format throughout the rendering process.
Imagine we have the following tasks:
- change the brightness level of a pixel,
- then alpha blend it with another pixel,
- then average it with neighboring pixels.
Each of the task requires us to
A. extract the r, g, b channel from the pixel,
B. apply changes to each channel and
C. convert it back to rrggbb format.
As a result the total amount of work is 3 x A + 3 x B + 3 x C. However if pixels are represented in separate r g b channels, we won’t need step A and C any more. That reduces the total work to 3 x B + C (we need a single step C at the end since only pixel in the format rrggbb can be written to the screen buffer)
That’s just my Theory…