Handle damage tracking with upscaling correctly
Whenever we scale up a buffer, the damage region has to be scaled appropriately as well. Doing this naively (region_scaled = region * scale
) causes some issues though because of linear filtering, which causes pixels around the actually damaged region to be affected as well. To calculate which pixels are affected in the destination buffer, we can use an algorithm like this:
- pad the damage region by one source buffer pixel
- map that padded region to the destination buffer, as a floating point region
- calculate the aligned region of that destination buffer region
- "unpad" the resulting region by one destination buffer pixel. These pixels are exclusively affected by pixels around the actually damaged region, so they don't need to be repainted