rework label drawable and text drawable's API

This commit is contained in:
ohyzha
2024-08-26 17:42:43 +03:00
parent a2923966fa
commit e2ae1687ac
13 changed files with 160 additions and 217 deletions

View File

@@ -61,11 +61,7 @@ namespace OpenVulkano
m_nodesPool.resize(N);
m_drawablesPool.reserve(N);
static TextDrawable textDrawable(sdfMetadataInfo);
auto& sh = TextDrawable::GetSdfDefaultShader();
sh.depthWrite = false;
sh.depthCompareOp = CompareOp::LESS_OR_EQUAL;
textDrawable.SetShader(&sh);
TextDrawable textDrawable(sdfMetadataInfo);
const std::vector<std::string> texts = { "Hello", "1", "XYZ" };
BillboardControlBlock billboardSettings;
LabelDrawableSettings labelSettings;
@@ -75,14 +71,14 @@ namespace OpenVulkano
//labelSettings.hasRoundedCorners = (i % 2 == 0 ? 1 : 0);
labelSettings.hasArrow = (i % 2 == 0 ? 1 : 0);
bool isBillboard = (i % 2 == 0 ? 1 : 0);
LabelDrawable& label = m_drawablesPool.emplace_back(labelSettings, isBillboard);
LabelDrawable& label = m_drawablesPool.emplace_back(textDrawable.GetAtlasData(), labelSettings, isBillboard);
label.SetBillboardSettings(billboardSettings);
label.AddText(&textDrawable, texts[i]);
label.AddText(texts[i]);
if (i == 2)
{
for (int j = 0; j < 3; j++)
{
label.AddText(&textDrawable, "Additional text" + std::to_string(j));
label.AddText("Additional text" + std::to_string(j));
}
}
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);

View File

@@ -74,6 +74,8 @@ namespace OpenVulkano
msdf_atlas::Charset charset = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
m_atlasGenerator.GenerateAtlas(fontPath, charset);
m_msdfAtlasGenerator.GenerateAtlas(fontPath, charset);
m_atlasGenerator.SaveAtlasMetadataInfo("sdf_atlas.png");
m_msdfAtlasGenerator.SaveAtlasMetadataInfo("msdf_atlas");
#else
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed.png");
auto msdfMetadataInfo = resourceLoader.GetResource("msdf_atlas_packed.png");
@@ -86,12 +88,12 @@ namespace OpenVulkano
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
if (i < texts.size())
{
t = new TextDrawable(&m_atlasGenerator, texts[textIdx].second);
t = new TextDrawable(m_atlasGenerator.GetAtlasData(), texts[textIdx].second);
t->SetShader(&TextDrawable::GetSdfDefaultShader());
}
else
{
t = new TextDrawable(&m_msdfAtlasGenerator, texts[textIdx].second);
t = new TextDrawable(m_msdfAtlasGenerator.GetAtlasData(), texts[textIdx].second);
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
}
#else

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1012 KiB

After

Width:  |  Height:  |  Size: 1012 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 KiB

After

Width:  |  Height:  |  Size: 631 KiB