Refactor text renderer

Replace unifont with CFont and CFontManager, since the h_mgr interface
was
needlessly inconvenient.

Load the font textures through CTextureManager, to support dynamic
reloading (e.g. when resetting GL state - see #741).

Add CFontMetrics as a convenient wrapper for code that just wants to
measure text.

Fixes #1117.

This was SVN commit r14016.
This commit is contained in:
Ykkrosh
2013-10-18 15:53:07 +00:00
parent 8799bd98b0
commit 5778484a77
25 changed files with 406 additions and 541 deletions
+10 -9
View File
@@ -19,10 +19,11 @@
#include "TextRenderer.h"
#include "graphics/Font.h"
#include "graphics/FontManager.h"
#include "lib/ogl.h"
#include "lib/res/graphics/unifont.h"
#include "ps/CStrIntern.h"
#include "ps/Font.h"
#include "renderer/Renderer.h"
extern int g_xres, g_yres;
@@ -74,10 +75,7 @@ void CTextRenderer::Color(float r, float g, float b, float a)
void CTextRenderer::Font(const CStrW& font)
{
if (!m_Fonts[font])
m_Fonts[font] = shared_ptr<CFont>(new CFont(font));
m_Font = m_Fonts[font];
m_Font = g_Renderer.GetFontManager().LoadFont(font);
}
void CTextRenderer::PrintfAdvance(const wchar_t* fmt, ...)
@@ -125,6 +123,9 @@ void CTextRenderer::Put(float x, float y, const wchar_t* buf)
if (buf[0] == 0)
return; // empty string; don't bother storing
if (!m_Font)
return; // invalid font; can't render
CMatrix3D translate;
translate.SetTranslation(x, y, 0.0f);
@@ -155,7 +156,7 @@ void CTextRenderer::Render()
if (batch.text.empty()) // avoid zero-length arrays
continue;
const std::map<u16, UnifontGlyphData>& glyphs = batch.font->GetGlyphs();
const CFont::GlyphMap& glyphs = batch.font->GetGlyphs();
m_Shader->BindTexture(str_tex, batch.font->GetTexture());
@@ -179,7 +180,7 @@ void CTextRenderer::Render()
i16 x = 0;
for (size_t i = 0; i < batch.text.size(); ++i)
{
std::map<u16, UnifontGlyphData>::const_iterator it = glyphs.find(batch.text[i]);
CFont::GlyphMap::const_iterator it = glyphs.find(batch.text[i]);
if (it == glyphs.end())
it = glyphs.find(0xFFFD); // Use the missing glyph symbol
@@ -187,7 +188,7 @@ void CTextRenderer::Render()
if (it == glyphs.end()) // Missing the missing glyph symbol - give up
continue;
const UnifontGlyphData& g = it->second;
const CFont::GlyphData& g = it->second;
vertexes[i*4].u = g.u1;
vertexes[i*4].v = g.v0;