add opportunity to pack atlas and meta data in same file

This commit is contained in:
ohyzha
2024-08-06 17:02:24 +03:00
parent 9e9a76e459
commit c7c2a96b9c
8 changed files with 140 additions and 29 deletions

View File

@@ -67,13 +67,15 @@ namespace OpenVulkano
m_drawablesPool.resize(N);
#ifdef MSDFGEN_AVAILABLE
Charset charset = Charset::ASCII;
for (unicode_t c = 0x0410; c <= 0x041F; c++)
{
// some unicode values
charset.add(c);
}
m_atlasGenerator.GenerateAtlas(fontPath, charset, "roboto-regular-atlas.png");
Charset charset = FontAtlasGenerator::LoadAllGlyphs(fontPath);
//Charset charset = Charset::ASCII;
//for (unicode_t c = 0x0410; c <= 0x041F; c++)
//{
// // some unicode values
// charset.add(c);
//}
m_atlasGenerator.GenerateAtlas(fontPath, charset);
m_atlasGenerator.SaveAtlasMetadataInfo("atlas_metadata", true);
#endif
for (int i = 0; i < texts.size(); i++)
@@ -81,16 +83,19 @@ namespace OpenVulkano
#ifdef MSDFGEN_AVAILABLE
TextDrawable* t = new TextDrawable(&m_atlasGenerator, texts[i].second);
#else
auto metadataInfo = resourceLoader.GetResource("atlas_metadata");
auto data = resourceLoader.GetResource("roboto-regular-atlas.png");
Image::ImageLoaderPng loader;
static auto image = loader.loadData(reinterpret_cast<uint8_t*>(data.Data()), data.Size());
static Texture tex;
tex.resolution = image->resolution;
tex.textureBuffer = image->data.Data();
tex.format = image->dataFormat;
tex.size = image->data.Size(); // 1 channel
TextDrawable* t = new TextDrawable(metadataInfo, &tex, texts[i].second);
auto metadataInfo = resourceLoader.GetResource("full_atlas_metadata_packed");
TextDrawable* t = new TextDrawable(metadataInfo, texts[i].second);
// OR use separate texture + metadata file
//auto metadataInfo = resourceLoader.GetResource("atlas_metadata");
//auto data = resourceLoader.GetResource("roboto-regular-atlas.png");
//Image::ImageLoaderPng loader;
//static auto image = loader.loadData(reinterpret_cast<uint8_t*>(data.Data()), data.Size());
//static Texture tex;
//tex.resolution = image->resolution;
//tex.textureBuffer = image->data.Data();
//tex.format = image->dataFormat;
//tex.size = image->data.Size(); // 1 channel
//TextDrawable* t = new TextDrawable(metadataInfo, &tex, texts[i].second);
#endif // MSDFGEN_AVAILABLE
t->GenerateText(texts[i].first);
m_drawablesPool[i] = t;