Jazz2::UI::PerformanceOverlay class

Table of the detailed performance metrics.

The overlay PerformanceMetricsLevel::Detailed shows. Its numbers change only when nCine::FrameStatistics publishes a new snapshot, twice a second, so that is the only time the table is built: Update() notices the snapshot and fills in the rows every screen has - the frame time, its phases, what the graphics backend reports and the memory - the caller adds rows of its own through AddRow(), and Build() measures them and has them rendered into a texture of their own, in an off-screen pass that runs in that one frame only. Every frame Draw() then costs a single textured quad, where drawing the text itself was a render command per character - some 150 of them, which on the weakest consoles made the overlay one of the more expensive things on the screen.

The texture is sized for the table, rounded up, and only ever grows, so the table changing by a digit does not reallocate it. A column is as wide as the widest text it held over the last few seconds rather than as its text is now: sized to the current text, the whole table would jump sideways every time a value gains or loses a digit, while a column that never narrowed would stay as wide as the frame time of the hitch that loaded the level. The table has no background of its own, only the text over the scene, so where a render target has no alpha channel to leave the rest of the texture see-through, it is drawn directly instead - and so it is wherever the off-screen pass cannot be set up.

Public static variables

static std::int32_t MaxRows constexpr
Maximum number of rows, further ones are dropped.

Constructors, destructors, conversion operators

PerformanceOverlay()
~PerformanceOverlay()
PerformanceOverlay(const PerformanceOverlay&) deleted

Public functions

auto operator=(const PerformanceOverlay&) -> PerformanceOverlay& deleted
auto Update() -> bool
Prepares the table for the frame, to be called every frame before the scene is visited.
void AddRow(StringView label, StringView value)
Adds a row, between Update() and Build().
void Build(Font* font, float maxHeight)
Lays the rows out and schedules rendering them.
void Draw(Canvas* canvas, float right, float top, std::uint16_t z)
Draws the table with its top right corner at the given point.
void Release()
Frees the texture and everything else the table holds.

Function documentation

bool Jazz2::UI::PerformanceOverlay::Update()

Prepares the table for the frame, to be called every frame before the scene is visited.

Returns true when a new snapshot has been published since the table was built. The rows then hold the ones describing the frame (see nCine::FrameStatistics), the caller adds its own and finishes with Build(). The table is not shown until the first snapshot is.

void Jazz2::UI::PerformanceOverlay::Build(Font* font, float maxHeight)

Lays the rows out and schedules rendering them.

Parameters
font Font to draw with
maxHeight Height the table may take; the rows that do not fit continue in another block beside the first, and the blocks read from left to right

void Jazz2::UI::PerformanceOverlay::Draw(Canvas* canvas, float right, float top, std::uint16_t z)

Draws the table with its top right corner at the given point.

Draws nothing until the table has been rendered for the first time.

void Jazz2::UI::PerformanceOverlay::Release()

Frees the texture and everything else the table holds.

For when the table is not going to be shown for a while; the next Update() builds it again. Costs nothing if there is nothing to free.