fix incorrect geometry buffer size

This commit is contained in:
ohyzha
2024-08-08 21:35:16 +03:00
parent ae39847d95
commit 6a85f25b87

View File

@@ -127,8 +127,23 @@ namespace OpenVulkano::Scene
return;
}
auto GetActualLength = [&]()
{
auto begin = text.begin();
auto end = text.end();
size_t len = 0;
while (begin != end)
{
uint32_t c = utf8::next(begin, end);
if (c == '\n') continue;
++len;
}
return len;
};
size_t len = GetActualLength();
m_geometry.Close();
m_geometry.Init(text.size() * 4, text.size() * 6);
m_geometry.Init(len * 4, len * 6);
// TODO: better implementation to decide what to use: data from atlas generator or data read from file
// we have msdf but loaded glyphs metadata from file before
@@ -161,7 +176,8 @@ namespace OpenVulkano::Scene
auto end = text.end();
const double lineHeight = meta->lineHeight;
double posY = pos.y;
for (size_t i = 0; begin != end; i++)
int i = 0;
while (begin != end)
{
uint32_t c = utf8::next(begin, end);
if (c == '\n')
@@ -216,6 +232,7 @@ namespace OpenVulkano::Scene
// TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols
// when setting for depth comparison operator will be available( <= )
cursorX += info.advance + 0.08;
++i;
}
SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer);
}