[SDL] Quickly drawing an Array of pixels on the screen

Solra Bizna sbizna at tejat.net
Wed Jan 23 08:05:45 PST 2008


I can see two possible bottlenecks in your code.
First, it updates the entire screen, even though only a tiny fraction
of the pixels are changed. On the other hand, if you individually
update the changed pixels, you either get to create a massive array of
SDL_Rect or have the overhead of calling SDL_UpdateRect loads of
times. I'd leave this alone.
Second, your inner loop has a multiply which can't be pipelined.
As a remedy for the second bottleneck, try swapping the x and the y,
and having a separate counter for the y coordinate. Something like:
> for(i = 0, y = 0; i < n; i++, y += screen->pitch)
> {
>   bufp = (Uint8 *)screen->pixels + y + array[i];
>   *bufp = color;
> }
That way you replace the multiply with a couple of relatively cheap adds.
-:sigma.SB


More information about the SDL mailing list