Add glyph debug box rendering for font system

This commit introduces optional debugging visuals for font glyph
rendering. When enabled, each glyph is drawn with a surrounding debug
box to aid in visual inspection of glyph layout, spacing, and atlas
behavior.

Usage examples (via console):

// Enable debug box rendering
Engine.ConfigDB_CreateValue("user","fonts.debugBox", true);

// Set debug box color (R G B)
Engine.ConfigDB_CreateValue("user","fonts.debugBoxColor", "35 0 35");

This feature is intended for developers working on font layout or atlas
generation logic, and has no effect on normal gameplay or UI rendering
when disabled.
This commit is contained in:
trompetin17
2025-05-28 14:02:23 -05:00
parent 8b1c6c76b6
commit d323797d98
2 changed files with 19 additions and 3 deletions
+5
View File
@@ -621,6 +621,11 @@ height.min = 16
[fonts]
default = "LinBiolinum_Rah.ttf", "FreeSans.ttf" ; Default font to use for all text
debugBox = false ; Whether to draw a debug box around text, useful for debugging text rendering issues
; Color of the debug box, if enabled.
; When A8 or R8 "R G B" only take R as alpha channel.
; When R8G8B8A: "R G B" where R, G, B are integers from 0 to 255.
debugBoxColor = "128 0 128"
;;;;;;;;;;;;;;;;;;;;;;;;
+14 -3
View File
@@ -26,6 +26,7 @@
#include "maths/Matrix3D.h"
#include "ps/CStrIntern.h"
#include "ps/CStrInternStatic.h"
#include "ps/ConfigDB.h"
#include "renderer/Renderer.h"
#include <errno.h>
@@ -202,6 +203,11 @@ void CTextRenderer::Render(
std::vector<CVector2D> positions;
std::vector<CVector2D> uvs;
const bool debugFontBox{g_ConfigDB.Get("fonts.debugBox", false)};
const std::string debugFontBoxColor{ g_ConfigDB.Get("fonts.debugBoxColor", std::string{"128 0 128"})};
CColor debugBoxColor;
debugBoxColor.ParseString(debugFontBoxColor.c_str());
// Try to merge non-consecutive batches that share the same font/color/translate:
// sort the batch list by font, then merge the runs of adjacent compatible batches
m_Batches.sort(SBatchCompare());
@@ -245,13 +251,18 @@ void CTextRenderer::Render(
translationChanged = true;
}
CColor boxColor;
// ALPHA-only textures will have .rgb sampled as 0, so we need to
// replace it with white (but not affect RGBA textures)
if (batch.font->HasRGB())
deviceCommandContext->SetUniform(colorAddBindingSlot, 0.0f, 0.0f, 0.0f, 0.0f);
if (!debugFontBox && batch.font->HasRGB())
boxColor = CColor(0.0f, 0.0f, 0.0f, 0.0f);
else if (debugFontBox && batch.font->HasRGB())
boxColor = debugBoxColor;
else
deviceCommandContext->SetUniform(colorAddBindingSlot, batch.color.r, batch.color.g, batch.color.b, 0.0f);
boxColor = CColor(batch.color.r, batch.color.g, batch.color.b, debugFontBox ? debugBoxColor.r : 0);
deviceCommandContext->SetUniform(colorAddBindingSlot, boxColor.AsFloatArray());
deviceCommandContext->SetUniform(colorMulBindingSlot, batch.color.AsFloatArray());
positions.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 4);