From d323797d98b2929e1626803f010bbdca772e656a Mon Sep 17 00:00:00 2001 From: trompetin17 Date: Wed, 28 May 2025 14:02:23 -0500 Subject: [PATCH] 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. --- binaries/data/config/default.cfg | 5 +++++ source/graphics/TextRenderer.cpp | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 7d6d587d36..f24fa9215c 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -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" ;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/source/graphics/TextRenderer.cpp b/source/graphics/TextRenderer.cpp index d7cbe879f2..f496619d2b 100644 --- a/source/graphics/TextRenderer.cpp +++ b/source/graphics/TextRenderer.cpp @@ -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 @@ -202,6 +203,11 @@ void CTextRenderer::Render( std::vector positions; std::vector 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);