I am still somewhat new to pointer arithmetic. For our RenderWeirdGradient, for example, we fill the buffer by basically using a pointer we move across the memory (if I understand correctly). Say we wanted to fill just part of the buffer, my first thought is something like this:
for (int Y = StartY; Y < EndY; ++Y)
for(int X = StartX; X < EndX; ++X)
((uint32*)(Buffer->Memory))[(Y*Buffer->Width) + X] = Color;
Thinking of the equivalent using pointer arithmetic did not come as quickly to me, but I ended up with something like this:
uint8 *Row = (uint8 *)Buffer->Memory;
Row += (StartY * Buffer->Pitch);
for (int Y = 0; Y < Height; ++Y)
uint32 *Pixel = ((uint32*)(Row)) + StartX;
for(int X = 0; X < Width; ++X)
*Pixel++ = Color;
Row += Buffer->Pitch;
I think I heard somewhere that [ ] in C is just literally shorthand for pointer arithmetic, but I'm not sure if that's actually true?
I guess I'm wondering if it's worth stumbling through the pointer arithmetic with these kinds of loops for educational purposes if nothing else. Are there any performance / design considerations with this kind of thing?
Curious to hear any thoughts. Thanks ^-^