Give the mock-game backends one source of truth for the test pattern

The animated pattern math (background sweep, moving 24px bar, frame-
counter block) was copy-pasted across all five clear-based backends
(dx9/dx10/dx11/dx12/gl). The backends MUST render an identical image --
the capture test decodes the same frame-counter block from each -- so a
drift between copies would be a silent test hazard.

Factor it into one frame_pattern() helper (plus kBarWidth) in
render_backend.hpp; each backend now consumes the computed bg/bar_x/code
values with its own API's clear/fill. mock_game_test still decodes every
backend correctly.
This commit is contained in:
2026-07-12 09:35:45 +02:00
parent 1eee482165
commit 9a736cf477
6 changed files with 53 additions and 51 deletions

View File

@@ -37,6 +37,32 @@ inline std::uint32_t rgb_to_frame(std::uint8_t r, std::uint8_t g, std::uint8_t b
// Size (px) of the top-left frame-counter block the test samples.
inline constexpr std::uint32_t kFrameBlock = 64;
// Width (px) of the moving vertical bar.
inline constexpr std::uint32_t kBarWidth = 24;
// The animated pattern the mock renders for one frame, computed once so every backend draws the
// IDENTICAL image (the capture test compares backends). Each backend consumes these values with its
// own API's clear/fill calls: an animated full-screen background, a kBarWidth-wide full-height white
// bar at bar_x, and the top-left kFrameBlock-square frame-counter block whose colour encodes `frame`.
struct FramePattern
{
std::uint8_t bg_r, bg_g, bg_b; // background; each channel sweeps at a different rate -> motion
std::uint32_t bar_x; // left edge of the moving bar
std::uint8_t code_r, code_g, code_b; // frame-counter block colour (frame_to_rgb)
};
inline FramePattern frame_pattern(std::uint32_t frame, std::uint32_t width)
{
FramePattern p{};
p.bg_r = static_cast<std::uint8_t>((frame * 2) % 256);
p.bg_g = static_cast<std::uint8_t>((frame * 3) % 256);
p.bg_b = static_cast<std::uint8_t>((frame * 5) % 256);
const std::uint32_t span = width > kBarWidth ? width - kBarWidth : 1;
p.bar_x = (frame * 4) % span;
frame_to_rgb(frame, p.code_r, p.code_g, p.code_b);
return p;
}
class RenderBackend
{
public: