Implement texture atlas for fonts
This commit is contained in:
1 parent
17dc1e4d88
commit
22a90fe07c
14 files changed
+388
-50
No files matched your search
@@ -19,11 +19,11 @@ struct UIRender {
|
||||
uint32 z;
|
||||
uint32 level;
|
||||
PElement element; // back-ref for input hit-testing
|
||||
// glyph-only (text): the glyph texture is backgroundTexture, this is the
|
||||
// per-glyph rect in *atlas* space (0..1) so the pass can emit a glyph quad
|
||||
bool isGlyph = false;
|
||||
// UV rect for textured quads; glyphs carry their rect in the font's per-size
|
||||
// atlas (backgroundTexture = the atlas), full-rect (0,0,1,1) for plain images.
|
||||
// A "glyph quad" is nothing special: a quad with a texture and a UV rect.
|
||||
Vector2 uvOffset = Vector2(0);
|
||||
Vector2 uvSize = Vector2(0);
|
||||
Vector2 uvSize = Vector2(1);
|
||||
};
|
||||
class Element {
|
||||
public:
|
||||
|
||||
@@ -79,7 +79,7 @@ class Text : public Element {
|
||||
.level = level,
|
||||
.element = this,
|
||||
});
|
||||
// text: one render quad per shaped glyph, carrying its atlas rect
|
||||
// text: one quad per shaped glyph, carrying its rect in the font's per-size atlas
|
||||
if (style.fontFamily != nullptr) {
|
||||
for (auto& g : glyphs) {
|
||||
result.add(UIRender{
|
||||
@@ -90,9 +90,8 @@ class Text : public Element {
|
||||
.z = style.z,
|
||||
.level = level,
|
||||
.element = this,
|
||||
.isGlyph = true,
|
||||
.uvOffset = Vector2(0),
|
||||
.uvSize = Vector2(1),
|
||||
.uvOffset = g.uvOffset,
|
||||
.uvSize = g.uvSize,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user