Font builder
This commit is contained in:
@@ -40,6 +40,7 @@ add_video_shader_test(RenderCadenceCompositorRuntimeShaderParamsTests
|
||||
)
|
||||
|
||||
add_video_shader_test(RenderCadenceCompositorRuntimeLayerModelTests
|
||||
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeLayerModel.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeJson.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
|
||||
@@ -48,7 +49,15 @@ add_video_shader_test(RenderCadenceCompositorRuntimeLayerModelTests
|
||||
"${TEST_DIR}/RenderCadenceCompositorRuntimeLayerModelTests.cpp"
|
||||
)
|
||||
|
||||
add_video_shader_test(FontAtlasBuilderTests
|
||||
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeJson.cpp"
|
||||
"${SRC_DIR}/shader/ShaderPackageRegistry.cpp"
|
||||
"${TEST_DIR}/FontAtlasBuilderTests.cpp"
|
||||
)
|
||||
|
||||
add_video_shader_test(RenderCadenceCompositorSupportedShaderCatalogTests
|
||||
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeJson.cpp"
|
||||
"${SRC_DIR}/runtime/SupportedShaderCatalog.cpp"
|
||||
"${SRC_DIR}/shader/ShaderPackageRegistry.cpp"
|
||||
@@ -59,6 +68,7 @@ add_video_shader_test(RenderCadenceCompositorRuntimeStateJsonTests
|
||||
"${SRC_DIR}/app/AppConfig.cpp"
|
||||
"${SRC_DIR}/app/AppConfigProvider.cpp"
|
||||
"${SRC_DIR}/json/JsonWriter.cpp"
|
||||
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeJson.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeLayerModel.cpp"
|
||||
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
|
||||
|
||||
83
tests/FontAtlasBuilderTests.cpp
Normal file
83
tests/FontAtlasBuilderTests.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "FontAtlasBuilder.h"
|
||||
#include "ShaderPackageRegistry.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
int gFailures = 0;
|
||||
|
||||
void Expect(bool condition, const char* message)
|
||||
{
|
||||
if (condition)
|
||||
return;
|
||||
|
||||
std::cerr << "FAIL: " << message << "\n";
|
||||
++gFailures;
|
||||
}
|
||||
|
||||
std::filesystem::path RepoRoot()
|
||||
{
|
||||
std::filesystem::path path = std::filesystem::current_path();
|
||||
while (!path.empty())
|
||||
{
|
||||
if (std::filesystem::exists(path / "3rdParty" / "msdf-atlas-gen" / "msdf-atlas-gen.exe"))
|
||||
return path;
|
||||
const std::filesystem::path parent = path.parent_path();
|
||||
if (parent.empty() || parent == path)
|
||||
break;
|
||||
path = parent;
|
||||
}
|
||||
return std::filesystem::current_path();
|
||||
}
|
||||
|
||||
void TestFindsBundledExecutable()
|
||||
{
|
||||
std::filesystem::path executablePath;
|
||||
Expect(
|
||||
RenderCadenceCompositor::FontAtlasBuilder::FindMsdfAtlasGenExecutable(RepoRoot(), executablePath),
|
||||
"bundled msdf-atlas-gen executable is found");
|
||||
Expect(std::filesystem::exists(executablePath), "bundled msdf-atlas-gen executable exists");
|
||||
}
|
||||
|
||||
void TestBuildsTextOverlayFontAtlas()
|
||||
{
|
||||
const std::filesystem::path repoRoot = RepoRoot();
|
||||
ShaderPackageRegistry registry(4);
|
||||
ShaderPackage shaderPackage;
|
||||
std::string error;
|
||||
Expect(registry.ParseManifest(repoRoot / "shaders" / "text-overlay" / "shader.json", shaderPackage, error), "text overlay manifest parses");
|
||||
Expect(!shaderPackage.fontAssets.empty(), "text overlay declares a font asset");
|
||||
|
||||
RenderCadenceCompositor::FontAtlasBuildConfig config;
|
||||
config.repoRoot = repoRoot;
|
||||
config.cacheRoot = repoRoot / "runtime" / "test_font_cache";
|
||||
RenderCadenceCompositor::FontAtlasBuilder builder(config);
|
||||
std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> outputs;
|
||||
Expect(builder.BuildPackageFontAtlases(shaderPackage, outputs, error), "text overlay font atlas builds");
|
||||
Expect(outputs.size() == 1, "one font atlas output is produced");
|
||||
if (!outputs.empty())
|
||||
{
|
||||
Expect(std::filesystem::exists(outputs[0].imagePath), "font atlas image exists");
|
||||
Expect(std::filesystem::exists(outputs[0].jsonPath), "font atlas json exists");
|
||||
Expect(std::filesystem::file_size(outputs[0].imagePath) > 0, "font atlas image is not empty");
|
||||
Expect(std::filesystem::file_size(outputs[0].jsonPath) > 0, "font atlas json is not empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
TestFindsBundledExecutable();
|
||||
TestBuildsTextOverlayFontAtlas();
|
||||
|
||||
if (gFailures != 0)
|
||||
{
|
||||
std::cerr << gFailures << " font atlas builder test failure(s).\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "FontAtlasBuilder tests passed.\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "SupportedShaderCatalog.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@@ -29,6 +30,21 @@ ShaderPackage MakeSinglePassPackage()
|
||||
return shaderPackage;
|
||||
}
|
||||
|
||||
std::filesystem::path RepoRoot()
|
||||
{
|
||||
std::filesystem::path path = std::filesystem::current_path();
|
||||
while (!path.empty())
|
||||
{
|
||||
if (std::filesystem::exists(path / "shaders" / "text-overlay" / "shader.json"))
|
||||
return path;
|
||||
const std::filesystem::path parent = path.parent_path();
|
||||
if (parent.empty() || parent == path)
|
||||
break;
|
||||
path = parent;
|
||||
}
|
||||
return std::filesystem::current_path();
|
||||
}
|
||||
|
||||
void SupportsSinglePassStatelessPackage()
|
||||
{
|
||||
const ShaderPackage shaderPackage = MakeSinglePassPackage();
|
||||
@@ -110,6 +126,24 @@ void RejectsTextParameters()
|
||||
Expect(!result.supported, "text-parameter packages should be rejected for now");
|
||||
Expect(result.reason.find("text") != std::string::npos, "text rejection should mention text parameters");
|
||||
}
|
||||
|
||||
void BuildsDeclaredFontAtlasesDuringCatalogLoad()
|
||||
{
|
||||
RenderCadenceCompositor::SupportedShaderCatalog catalog;
|
||||
std::string error;
|
||||
Expect(catalog.Load(RepoRoot() / "shaders", 12, error), "shader catalog loads");
|
||||
|
||||
const auto& fontAtlases = catalog.FontAtlases();
|
||||
const auto textOverlayIt = fontAtlases.find("text-overlay");
|
||||
Expect(textOverlayIt != fontAtlases.end(), "text overlay font atlas is prepared during catalog load");
|
||||
if (textOverlayIt != fontAtlases.end() && !textOverlayIt->second.empty())
|
||||
{
|
||||
Expect(std::filesystem::exists(textOverlayIt->second.front().imagePath), "catalog font atlas image exists");
|
||||
Expect(std::filesystem::exists(textOverlayIt->second.front().jsonPath), "catalog font atlas json exists");
|
||||
Expect(std::filesystem::file_size(textOverlayIt->second.front().imagePath) > 0, "catalog font atlas image is not empty");
|
||||
Expect(std::filesystem::file_size(textOverlayIt->second.front().jsonPath) > 0, "catalog font atlas json is not empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -120,6 +154,7 @@ int main()
|
||||
RejectsTemporalPackage();
|
||||
RejectsTextureAssets();
|
||||
RejectsTextParameters();
|
||||
BuildsDeclaredFontAtlasesDuringCatalogLoad();
|
||||
|
||||
if (gFailures != 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user