fix(render): give degenerate segments area, pin font bit order, clarify vertex_count

This commit is contained in:
Martino Ferrari committed 2026-09-27 22:10:53 +02:00
1 parent 7cbc1c9955
commit b4e88fe0c1
5 files changed
+76 -15

No files matched your search

+21 -8
View File
@@ -269,13 +269,15 @@ PLOT_TEST(line_pipeline_draws_an_aa_strip) {
plot::render::LineVertexArray lines;
PLOT_CHECK(lines.create(&st));
// Two instances, so a wrong attribute divisor cannot pass: with a divisor of
// zero the second quad would be assembled from the first instance's leftover
// attribute values instead of its own segment. Data space is pixels here, and
// u_offset lands the two axes at Rect y = 100 and Rect y = 120.
const f32 segments[8] = {0.0f, 0.0f, 40.0f, 0.0f, 0.0f, 20.0f, 40.0f, 20.0f};
lines.upload(segments, 2);
PLOT_CHECK(lines.instance_count() == 2);
// Three instances: two segments at different y, so a wrong attribute divisor
// cannot pass (with a divisor of zero the second quad would be assembled from
// the first instance's leftover attribute values), plus a degenerate one at
// Rect (64, 140) — the shape a dense trace's min == max bucket stages, which
// must still leave a mark instead of collapsing to zero area.
const f32 segments[12] = {0.0f, 0.0f, 40.0f, 0.0f, 0.0f, 20.0f,
40.0f, 20.0f, 0.0f, 40.0f, 0.0f, 40.0f};
lines.upload(segments, 3);
PLOT_CHECK(lines.instance_count() == 3);
plot::gl::glViewport(0, 0, static_cast<plot::gl::GLsizei>(ctx.width),
static_cast<plot::gl::GLsizei>(ctx.height));
@@ -291,7 +293,7 @@ PLOT_TEST(line_pipeline_draws_an_aa_strip) {
program.set_width(3.0f);
program.set_color(plot::Color::hex(0xFF00FF));
lines.bind();
plot::gl::glDrawArraysInstanced(plot::gl::GL_TRIANGLE_STRIP, 0, 4, 2);
plot::gl::glDrawArraysInstanced(plot::gl::GL_TRIANGLE_STRIP, 0, 4, 3);
plot::u8 px[4] = {};
// Rect y = 100 is GL row 155.5, so rows 155 and 156 straddle the axis
@@ -318,6 +320,17 @@ PLOT_TEST(line_pipeline_draws_an_aa_strip) {
// Past the end of the segment (flat cap) and far from both strips.
PLOT_CHECK(ctx.read_pixel(110, 155, px));
PLOT_CHECK(px[0] + px[2] < 40);
// The degenerate instance: Rect y = 140 is rows 115/116 at x = 64, and the
// mark must be visible rather than a zero-area quad, while staying inside its
// own stroke width + fringe (columns 62..66).
PLOT_CHECK(ctx.read_pixel(64, 115, px));
PLOT_CHECK(px[0] > 200 && px[2] > 200);
PLOT_CHECK(ctx.read_pixel(64, 116, px));
PLOT_CHECK(px[0] > 200 && px[2] > 200);
PLOT_CHECK(ctx.read_pixel(64, 121, px));
PLOT_CHECK(px[0] + px[2] < 40);
PLOT_CHECK(ctx.read_pixel(70, 115, px));
PLOT_CHECK(px[0] + px[2] < 40);
PLOT_CHECK(ctx.read_pixel(128, 0, px));
PLOT_CHECK(px[0] + px[2] < 40);
PLOT_CHECK(plot::gl::glGetError() == plot::gl::GL_NO_ERROR);
+34
View File
@@ -151,6 +151,40 @@ PLOT_TEST(bitmap_font_decodes_si_units_and_falls_back_visibly) {
PLOT_CHECK(any_ink);
}
// The packed atlas must be left-to-right in absolute terms: `(row >> x) & 1` is
// also how every other expectation here is derived, so a table transcribed with
// the opposite in-row bit order would keep those tests green while drawing
// mirrored text. 'A' cannot catch that (it is
// symmetric about its vertical axis); 'L', 'b' and '/' can.
PLOT_TEST(bitmap_font_bit_order_runs_left_to_right) {
using plot::render::BitmapFont;
const plot::u8* atlas = BitmapFont::atlas_image();
auto ink = [atlas](char c, plot::u32 col, plot::u32 row) {
const plot::u32 slot = static_cast<plot::u32>(c) - BitmapFont::kFirstChar;
const plot::Vec2 origin = BitmapFont::atlas_origin(slot);
const auto x = static_cast<std::size_t>(origin.x) + col;
const auto y = static_cast<std::size_t>(origin.y) + row;
return atlas[y * BitmapFont::kAtlasWidth + x] != 0u;
};
// 'L': stem and top serif on the left, the foot running right along the
// bottom row and stopping one texel short of the right edge.
PLOT_CHECK(ink('L', 0u, 0u));
PLOT_CHECK(!ink('L', 7u, 0u));
PLOT_CHECK(ink('L', 1u, 3u));
PLOT_CHECK(!ink('L', 6u, 3u));
PLOT_CHECK(ink('L', 6u, 6u));
PLOT_CHECK(!ink('L', 7u, 6u));
// 'b': the stem is the leftmost column of the upper rows.
PLOT_CHECK(ink('b', 0u, 0u));
PLOT_CHECK(!ink('b', 7u, 0u));
// '/': starts at the right of the top row and ends at the left of the last
// one — the opposite of '\'.
PLOT_CHECK(ink('/', 6u, 0u));
PLOT_CHECK(!ink('/', 0u, 0u));
PLOT_CHECK(ink('/', 0u, 6u));
PLOT_CHECK(!ink('/', 6u, 6u));
}
PLOT_TEST(bitmap_font_atlas_is_uploadable) {
using plot::render::BitmapFont;
PLOT_CHECK(BitmapFont::kAtlasWidth == BitmapFont::kAtlasCols * BitmapFont::kGlyphPx);