forked from Mirrorlandia_minetest/minetest
CGUITTFont optimizations (#11136)
This commit is contained in:
parent
34888a914e
commit
024d47e0d3
@ -326,7 +326,6 @@ void GUIChatConsole::drawText()
|
|||||||
tmp->draw(
|
tmp->draw(
|
||||||
fragment.text,
|
fragment.text,
|
||||||
destrect,
|
destrect,
|
||||||
video::SColor(255, 255, 255, 255),
|
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
&AbsoluteClippingRect);
|
&AbsoluteClippingRect);
|
||||||
|
@ -547,12 +547,12 @@ void CGUITTFont::setFontHinting(const bool enable, const bool enable_auto_hintin
|
|||||||
|
|
||||||
void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
|
void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
|
||||||
{
|
{
|
||||||
draw(EnrichedString(std::wstring(text.c_str()), color), position, color, hcenter, vcenter, clip);
|
draw(EnrichedString(std::wstring(text.c_str()), color), position, hcenter, vcenter, clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
|
void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& position, bool hcenter, bool vcenter, const core::rect<s32>* clip)
|
||||||
{
|
{
|
||||||
std::vector<video::SColor> colors = text.getColors();
|
const std::vector<video::SColor> &colors = text.getColors();
|
||||||
|
|
||||||
if (!Driver)
|
if (!Driver)
|
||||||
return;
|
return;
|
||||||
@ -562,6 +562,7 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
|||||||
{
|
{
|
||||||
Glyph_Pages[i]->render_positions.clear();
|
Glyph_Pages[i]->render_positions.clear();
|
||||||
Glyph_Pages[i]->render_source_rects.clear();
|
Glyph_Pages[i]->render_source_rects.clear();
|
||||||
|
Glyph_Pages[i]->render_colors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up some variables.
|
// Set up some variables.
|
||||||
@ -590,7 +591,6 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
|||||||
u32 n;
|
u32 n;
|
||||||
uchar32_t previousChar = 0;
|
uchar32_t previousChar = 0;
|
||||||
core::ustring::const_iterator iter(utext);
|
core::ustring::const_iterator iter(utext);
|
||||||
std::vector<video::SColor> applied_colors;
|
|
||||||
while (!iter.atEnd())
|
while (!iter.atEnd())
|
||||||
{
|
{
|
||||||
uchar32_t currentChar = *iter;
|
uchar32_t currentChar = *iter;
|
||||||
@ -636,10 +636,11 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
|||||||
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page];
|
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page];
|
||||||
page->render_positions.push_back(core::position2di(offset.X + offx, offset.Y + offy));
|
page->render_positions.push_back(core::position2di(offset.X + offx, offset.Y + offy));
|
||||||
page->render_source_rects.push_back(glyph.source_rect);
|
page->render_source_rects.push_back(glyph.source_rect);
|
||||||
|
if (iter.getPos() < colors.size())
|
||||||
|
page->render_colors.push_back(colors[iter.getPos()]);
|
||||||
|
else
|
||||||
|
page->render_colors.push_back(video::SColor(255,255,255,255));
|
||||||
Render_Map.set(glyph.glyph_page, page);
|
Render_Map.set(glyph.glyph_page, page);
|
||||||
u32 current_color = iter.getPos();
|
|
||||||
if (current_color < colors.size())
|
|
||||||
applied_colors.push_back(colors[current_color]);
|
|
||||||
}
|
}
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
{
|
{
|
||||||
@ -688,16 +689,24 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
|||||||
for (size_t i = 0; i < page->render_positions.size(); ++i)
|
for (size_t i = 0; i < page->render_positions.size(); ++i)
|
||||||
page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset);
|
page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset);
|
||||||
}
|
}
|
||||||
|
// render runs of matching color in batch
|
||||||
|
size_t ibegin;
|
||||||
|
video::SColor colprev;
|
||||||
for (size_t i = 0; i < page->render_positions.size(); ++i) {
|
for (size_t i = 0; i < page->render_positions.size(); ++i) {
|
||||||
irr::video::SColor col;
|
ibegin = i;
|
||||||
if (!applied_colors.empty()) {
|
colprev = page->render_colors[i];
|
||||||
col = applied_colors[i < applied_colors.size() ? i : 0];
|
do
|
||||||
} else {
|
++i;
|
||||||
col = irr::video::SColor(255, 255, 255, 255);
|
while (i < page->render_positions.size() && page->render_colors[i] == colprev);
|
||||||
}
|
core::array<core::vector2di> tmp_positions;
|
||||||
|
core::array<core::recti> tmp_source_rects;
|
||||||
|
tmp_positions.set_pointer(&page->render_positions[ibegin], i - ibegin, false, false); // no copy
|
||||||
|
tmp_source_rects.set_pointer(&page->render_source_rects[ibegin], i - ibegin, false, false);
|
||||||
|
--i;
|
||||||
|
|
||||||
if (!use_transparency)
|
if (!use_transparency)
|
||||||
col.color |= 0xff000000;
|
colprev.color |= 0xff000000;
|
||||||
Driver->draw2DImage(page->texture, page->render_positions[i], page->render_source_rects[i], clip, col, true);
|
Driver->draw2DImageBatch(page->texture, tmp_positions, tmp_source_rects, clip, colprev, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,6 +199,7 @@ namespace gui
|
|||||||
|
|
||||||
core::array<core::vector2di> render_positions;
|
core::array<core::vector2di> render_positions;
|
||||||
core::array<core::recti> render_source_rects;
|
core::array<core::recti> render_source_rects;
|
||||||
|
core::array<video::SColor> render_colors;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::array<const SGUITTGlyph*> glyph_to_be_paged;
|
core::array<const SGUITTGlyph*> glyph_to_be_paged;
|
||||||
@ -270,7 +271,7 @@ namespace gui
|
|||||||
const core::rect<s32>* clip=0);
|
const core::rect<s32>* clip=0);
|
||||||
|
|
||||||
void draw(const EnrichedString& text, const core::rect<s32>& position,
|
void draw(const EnrichedString& text, const core::rect<s32>& position,
|
||||||
video::SColor color, bool hcenter=false, bool vcenter=false,
|
bool hcenter=false, bool vcenter=false,
|
||||||
const core::rect<s32>* clip=0);
|
const core::rect<s32>* clip=0);
|
||||||
|
|
||||||
//! Returns the dimension of a character produced by this font.
|
//! Returns the dimension of a character produced by this font.
|
||||||
|
@ -108,16 +108,11 @@ void StaticText::draw()
|
|||||||
font->getDimension(str.c_str()).Width;
|
font->getDimension(str.c_str()).Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
//str = colorizeText(BrokenText[i].c_str(), colors, previous_color);
|
|
||||||
//if (!colors.empty())
|
|
||||||
// previous_color = colors[colors.size() - 1];
|
|
||||||
|
|
||||||
#if USE_FREETYPE
|
#if USE_FREETYPE
|
||||||
if (font->getType() == irr::gui::EGFT_CUSTOM) {
|
if (font->getType() == irr::gui::EGFT_CUSTOM) {
|
||||||
irr::gui::CGUITTFont *tmp = static_cast<irr::gui::CGUITTFont*>(font);
|
irr::gui::CGUITTFont *tmp = static_cast<irr::gui::CGUITTFont*>(font);
|
||||||
tmp->draw(str,
|
tmp->draw(str,
|
||||||
r, previous_color, // FIXME
|
r, HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
||||||
HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
|
||||||
(RestrainTextInside ? &AbsoluteClippingRect : NULL));
|
(RestrainTextInside ? &AbsoluteClippingRect : NULL));
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user