- /* Then, render the reflection under the horizon */
- /* dst is already in place */
- src = background + HORIZON_HEIGHT * backgroundW;
+ /* Render the baked reflection one scanline below its place, so that
+ * the displacement that follows will be done in a cache-friendly way
+ */
+ src -= PIXEL_PADDING; /* We want to also fill the PADDING pixels here */
+ dst = backBuffer + (HORIZON_HEIGHT + 1) * BB_SIZE;
+ for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
+ memcpy(dst, src, (fb_width + PIXEL_PADDING) * 2);
+ src += backgroundW;
+ dst += BB_SIZE;
+ }
+
+ /* Perform displacement */
+ dst = backBuffer + HORIZON_HEIGHT * BB_SIZE + PIXEL_PADDING;
+ src = dst + BB_SIZE; /* The pixels to be displaced are 1 scanline below */