#include "../Common/TestsShell.h" #include #include #include #include #include #include #include #include using namespace ankerl; using namespace Rml; // Start of the "CJK unified ideographs" Unicode block. static constexpr int rml_font_texture_atlas_start_codepoint = 0x4E00; static const String rml_font_texture_atlas_document = R"( Font texture atlas benchmark )"; TEST_CASE("font_texture_atlas") { Context* context = TestsShell::GetContext(); REQUIRE(context); LoadFontFace("assets/NotoSansJP-Regular.ttf"); nanobench::Bench bench; bool incremental = false; // SUBCASE("all at once") //{ // incremental = false; // bench.title("Font texture atlas (all at once)"); // } // SUBCASE("incremental") //{ incremental = true; bench.title("Font texture atlas (incremental)"); //} bench.relative(true); bench.epochIterations(50); for (const int font_size : {12}) { const String rml_document = CreateString(rml_font_texture_atlas_document.c_str(), font_size); ElementDocument* const document = context->LoadDocumentFromMemory(rml_document); REQUIRE(document); Element* const body = document->GetElementById("body"); REQUIRE(body); document->Show(); context->Update(); context->Render(); for (const int glyph_count : {10}) { const String benchmark_name = CreateString("Size %d with %d glyphs", font_size, glyph_count); if (incremental) { bench.run(benchmark_name, [&]() { RMLUI_ZoneScopedN("Font texture atlas incremental"); { RMLUI_ZoneScopedN("ReleaseFontResources"); ReleaseFontResources(); } { RMLUI_ZoneScopedN("Change RML"); std::string inner_rml; for (int i = 0; i < glyph_count; ++i) { inner_rml += StringUtilities::ToUTF8(static_cast(rml_font_texture_atlas_start_codepoint + i)); body->SetInnerRML(inner_rml); } context->Update(); context->Render(); } }); } else { bench.run(benchmark_name, [&]() { ReleaseFontResources(); for (int i = 0; i < glyph_count; ++i) { body->SetInnerRML(StringUtilities::ToUTF8(static_cast(rml_font_texture_atlas_start_codepoint + i))); context->Update(); context->Render(); } }); } } document->Close(); } TestsShell::ShutdownShell(); }