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);