@@ -547,12 +547,12 @@ void CGUITTFont::setFontHinting(const bool enable, const bool enable_auto_hintin
547
547
548
548
void CGUITTFont::draw (const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
549
549
{
550
- draw (EnrichedString (std::wstring (text.c_str ()), color), position, color, hcenter, vcenter, clip);
550
+ draw (EnrichedString (std::wstring (text.c_str ()), color), position, hcenter, vcenter, clip);
551
551
}
552
552
553
- void CGUITTFont::draw (const EnrichedString &text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
553
+ void CGUITTFont::draw (const EnrichedString &text, const core::rect<s32>& position, bool hcenter, bool vcenter, const core::rect<s32>* clip)
554
554
{
555
- std::vector<video::SColor> colors = text.getColors ();
555
+ const std::vector<video::SColor> & colors = text.getColors ();
556
556
557
557
if (!Driver)
558
558
return ;
@@ -562,6 +562,7 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
562
562
{
563
563
Glyph_Pages[i]->render_positions .clear ();
564
564
Glyph_Pages[i]->render_source_rects .clear ();
565
+ Glyph_Pages[i]->render_colors .clear ();
565
566
}
566
567
567
568
// Set up some variables.
@@ -590,7 +591,6 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
590
591
u32 n;
591
592
uchar32_t previousChar = 0 ;
592
593
core::ustring::const_iterator iter (utext);
593
- std::vector<video::SColor> applied_colors;
594
594
while (!iter.atEnd ())
595
595
{
596
596
uchar32_t currentChar = *iter;
@@ -636,10 +636,11 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
636
636
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page ];
637
637
page->render_positions .push_back (core::position2di (offset.X + offx, offset.Y + offy));
638
638
page->render_source_rects .push_back (glyph.source_rect );
639
+ if (iter.getPos () < colors.size ())
640
+ page->render_colors .push_back (colors[iter.getPos ()]);
641
+ else
642
+ page->render_colors .push_back (video::SColor (255 ,255 ,255 ,255 ));
639
643
Render_Map.set (glyph.glyph_page , page);
640
- u32 current_color = iter.getPos ();
641
- if (current_color < colors.size ())
642
- applied_colors.push_back (colors[current_color]);
643
644
}
644
645
if (n > 0 )
645
646
{
@@ -688,16 +689,24 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
688
689
for (size_t i = 0 ; i < page->render_positions .size (); ++i)
689
690
page->render_positions [i] -= core::vector2di (shadow_offset, shadow_offset);
690
691
}
692
+ // render runs of matching color in batch
693
+ size_t ibegin;
694
+ video::SColor colprev;
691
695
for (size_t i = 0 ; i < page->render_positions .size (); ++i) {
692
- irr::video::SColor col;
693
- if (!applied_colors.empty ()) {
694
- col = applied_colors[i < applied_colors.size () ? i : 0 ];
695
- } else {
696
- col = irr::video::SColor (255 , 255 , 255 , 255 );
697
- }
696
+ ibegin = i;
697
+ colprev = page->render_colors [i];
698
+ do
699
+ ++i;
700
+ while (i < page->render_positions .size () && page->render_colors [i] == colprev);
701
+ core::array<core::vector2di> tmp_positions;
702
+ core::array<core::recti> tmp_source_rects;
703
+ tmp_positions.set_pointer (&page->render_positions [ibegin], i - ibegin, false , false ); // no copy
704
+ tmp_source_rects.set_pointer (&page->render_source_rects [ibegin], i - ibegin, false , false );
705
+ --i;
706
+
698
707
if (!use_transparency)
699
- col .color |= 0xff000000 ;
700
- Driver->draw2DImage (page->texture , page-> render_positions [i], page-> render_source_rects [i] , clip, col , true );
708
+ colprev .color |= 0xff000000 ;
709
+ Driver->draw2DImageBatch (page->texture , tmp_positions, tmp_source_rects , clip, colprev , true );
701
710
}
702
711
}
703
712
}
0 commit comments