Subpixel rendering (#186)
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/186 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com> Co-authored-by: ohyzha <oleksii.hyzha.ext@madvoxel.com> Co-committed-by: ohyzha <oleksii.hyzha.ext@madvoxel.com>
This commit is contained in:
@@ -56,17 +56,18 @@ namespace OpenVulkano
|
||||
texts.push_back(std::make_pair("This is first line\nSecond gg line\nThird G line", TextConfig()));
|
||||
texts[1].second.backgroundColor.a = 255;
|
||||
|
||||
const int N = texts.size();
|
||||
constexpr int atlasesCount = 4;
|
||||
const int textsCount = texts.size();
|
||||
auto& resourceLoader = ResourceLoader::GetInstance();
|
||||
const std::string fontPath = resourceLoader.GetResourcePath("Roboto-Regular.ttf");
|
||||
m_nodesPool.resize(N * 3);
|
||||
m_drawablesPool.resize(N * 3);
|
||||
m_nodesPool.resize(textsCount * atlasesCount);
|
||||
m_drawablesPool.resize(textsCount * atlasesCount);
|
||||
|
||||
if constexpr (CREATE_BITMAP_ATLAS)
|
||||
{
|
||||
// ReSharper disable once CppDFAUnreachableCode
|
||||
std::set<uint32_t> s = BitmapFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||
BitmapFontAtlasGenerator generator;
|
||||
BitmapFontAtlasGenerator generator(FontPixelSizeConfig(), SubpixelLayout::RGB);
|
||||
generator.GenerateAtlas(fontPath, s);
|
||||
generator.GetAtlas()->Save("bitmap_atlas_packed.png");
|
||||
}
|
||||
@@ -81,63 +82,73 @@ namespace OpenVulkano
|
||||
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed.png");
|
||||
auto msdfMetadataInfo = resourceLoader.GetResource("msdf_atlas_packed.png");
|
||||
auto bitmapMetadataInfo = resourceLoader.GetResource("bitmap_atlas_packed.png");
|
||||
auto bitmapSubpixelRenderingMetadataInfo = resourceLoader.GetResource("bitmap_subpixel_atlas_packed.png");
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < texts.size() * 3; i++)
|
||||
for (int i = 0, xOffset = -5; i < atlasesCount; i++, xOffset += 20)
|
||||
{
|
||||
int textIdx = i % texts.size();
|
||||
TextDrawable* t = nullptr;
|
||||
for (int j = 0; j < texts.size(); j++)
|
||||
{
|
||||
TextDrawable* t = nullptr;
|
||||
#if defined(MSDFGEN_AVAILABLE) && CREATE_NEW_ATLAS
|
||||
if (i < texts.size())
|
||||
{
|
||||
t = new TextDrawable(m_atlasGenerator.GetAtlasData(), texts[textIdx].second);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(m_msdfAtlasGenerator.GetAtlasData(), texts[textIdx].second);
|
||||
}
|
||||
if (i < texts.size())
|
||||
{
|
||||
t = new TextDrawable(m_atlasGenerator.GetAtlasData(), texts[j].second);
|
||||
t->SetShader(&TextDrawable::GetSdfDefaultShader());
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(m_msdfAtlasGenerator.GetAtlasData(), texts[j].second);
|
||||
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
|
||||
}
|
||||
#else
|
||||
int xOffset = 0;
|
||||
if (i < N)
|
||||
{
|
||||
t = new TextDrawable(sdfMetadataInfo, texts[textIdx].second);
|
||||
xOffset = -5;
|
||||
if (i == 0)
|
||||
{
|
||||
t = new TextDrawable(sdfMetadataInfo, texts[j].second);
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
t = new TextDrawable(msdfMetadataInfo, texts[j].second);
|
||||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
// bitmap
|
||||
t = new TextDrawable(bitmapMetadataInfo, texts[j].second);
|
||||
}
|
||||
else if (i == 3)
|
||||
{
|
||||
// bitmap subpixel rendering
|
||||
t = new TextDrawable(bitmapSubpixelRenderingMetadataInfo, texts[j].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
|
||||
const int nodeIdx = i * texts.size() + j;
|
||||
t->GenerateText(texts[j].first);
|
||||
m_drawablesPool[nodeIdx].reset(t);
|
||||
m_nodesPool[nodeIdx].Init();
|
||||
m_nodesPool[nodeIdx].SetMatrix(
|
||||
Math::Utils::translate(glm::mat4x4(1.f), Vector3f(xOffset, 2 - j * 2, 0)));
|
||||
m_nodesPool[nodeIdx].AddDrawable(m_drawablesPool[nodeIdx].get());
|
||||
m_scene.GetRoot()->AddChild(&m_nodesPool[nodeIdx]);
|
||||
}
|
||||
else if (i >= N && i < N * 2)
|
||||
{
|
||||
t = new TextDrawable(msdfMetadataInfo, texts[textIdx].second);
|
||||
xOffset = 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(bitmapMetadataInfo, texts[textIdx].second);
|
||||
xOffset = 35;
|
||||
}
|
||||
// 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[textIdx].first);
|
||||
m_drawablesPool[i].reset(t);
|
||||
m_nodesPool[i].Init();
|
||||
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(xOffset, 2 - textIdx * 2, 0)));
|
||||
m_nodesPool[i].AddDrawable(m_drawablesPool[i].get());
|
||||
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);
|
||||
}
|
||||
|
||||
GetGraphicsAppManager()->GetRenderer()->SetScene(&m_scene);
|
||||
m_camController.Init(&m_cam);
|
||||
m_camController.SetDefaultKeybindings();
|
||||
m_camController.SetPosition({ 10, 0, 15 });
|
||||
m_camController.SetBoostFactor(5);
|
||||
|
||||
|
||||
std::shared_ptr<UI::PerformanceInfo> m_perfInfo =
|
||||
std::make_shared<UI::PerformanceInfo>();
|
||||
m_ui.AddElement(m_perfInfo);
|
||||
|
||||
BIN
examples/ExampleSources/bitmap_subpixel_atlas_packed.png
Normal file
BIN
examples/ExampleSources/bitmap_subpixel_atlas_packed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 KiB |
Reference in New Issue
Block a user