MCPcopy Create free account
hub / github.com/Illation/ETEngine / UpdateBuffer

Method UpdateBuffer

Engine/source/EtRendering/SceneRendering/TextRenderer.cpp:260–342  ·  view source on GitHub ↗

--------------------------------- TextRenderer::UpdateBuffer Updates the vertex buffer containing font vertices

Source from the content-addressed store, hash-verified

258// Updates the vertex buffer containing font vertices
259//
260void TextRenderer::UpdateBuffer()
261{
262 std::vector<TextVertex> tVerts;
263
264 for (QueuedFont& queued : m_QueuedFonts)
265 {
266 if (queued.m_IsAddedToRenderer)
267 {
268 queued.m_BufferStart = static_cast<int32>(tVerts.size() * (sizeof(TextVertex) / sizeof(float)));
269 queued.m_BufferSize = 0;
270
271 for (TextCache const& cache : queued.m_TextCache)
272 {
273 float const sizeMult = static_cast<float>(cache.Size) / static_cast<float>(queued.m_Font->GetFontSize());
274
275 float totalAdvanceX = 0.f;
276 char previous = 0;
277 for (char const charId : cache.Text)
278 {
279 if (!SpriteFont::IsCharValid(charId))
280 {
281 LOG(FS("TextRenderer::UpdateBuffer > char '%c' not supported for current font", charId), core::LogLevel::Warning);
282 continue;
283 }
284
285 FontMetric const& metric = queued.m_Font->GetMetric(charId);
286 if (!metric.IsValid)
287 {
288 LOG(FS("TextRenderer::UpdateBuffer > char '%c' doesn't have a valid metric", charId), core::LogLevel::Warning);
289 continue;
290 }
291
292 vec2 kerningVec = 0;
293 if (queued.m_Font->m_UseKerning && m_bUseKerning)
294 {
295 kerningVec = metric.GetKerningVec(static_cast<wchar_t>(previous)) * sizeMult;
296 }
297 previous = charId;
298
299 totalAdvanceX += kerningVec.x;
300
301 if (charId == ' ')
302 {
303 totalAdvanceX += metric.AdvanceX;
304 continue;
305 }
306
307 tVerts.push_back(TextVertex());
308 TextVertex& vText = tVerts[tVerts.size()-1];
309
310 vText.Position.x = cache.Position.x + (totalAdvanceX + metric.OffsetX)*sizeMult;
311 vText.Position.y = cache.Position.y + (kerningVec.y + metric.OffsetY)*sizeMult;
312 vText.Position.z = 0;
313 vText.Color = cache.Color;
314 vText.TexCoord = metric.TexCoord;
315 vText.CharacterDimension = vec2(metric.Width, metric.Height);
316 vText.SizeMult = sizeMult;
317 vText.ChannelId = metric.Channel;

Callers

nothing calls this directly

Calls 6

TextVertexClass · 0.85
GetFontSizeMethod · 0.80
GetKerningVecMethod · 0.80
BindVertexArrayMethod · 0.80
BindBufferMethod · 0.80
SetBufferDataMethod · 0.80

Tested by

no test coverage detected