Bunch of optimizations
This commit is contained in:
parent
acb862a115
commit
37278ff7f9
@ -753,10 +753,16 @@ void drawItemStack(
|
||||
return;
|
||||
}
|
||||
|
||||
const ItemDefinition &def = item.getDefinition(client->idef());
|
||||
ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
|
||||
const static thread_local bool enable_animations =
|
||||
g_settings->getBool("inventory_items_animations");
|
||||
|
||||
if (imesh && imesh->mesh) {
|
||||
const ItemDefinition &def = item.getDefinition(client->idef());
|
||||
|
||||
// Render as mesh if animated or no inventory image
|
||||
if ((enable_animations && rotation_kind < IT_ROT_NONE) || def.inventory_image.empty()) {
|
||||
ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
|
||||
if (!imesh || !imesh->mesh)
|
||||
return;
|
||||
scene::IMesh *mesh = imesh->mesh;
|
||||
driver->clearZBuffer();
|
||||
s32 delta = 0;
|
||||
@ -800,9 +806,6 @@ void drawItemStack(
|
||||
core::matrix4 matrix;
|
||||
matrix.makeIdentity();
|
||||
|
||||
static thread_local bool enable_animations =
|
||||
g_settings->getBool("inventory_items_animations");
|
||||
|
||||
if (enable_animations) {
|
||||
float timer_f = (float) delta / 5000.f;
|
||||
matrix.setRotationDegrees(v3f(
|
||||
@ -847,16 +850,27 @@ void drawItemStack(
|
||||
driver->setTransform(video::ETS_VIEW, oldViewMat);
|
||||
driver->setTransform(video::ETS_PROJECTION, oldProjMat);
|
||||
driver->setViewPort(oldViewPort);
|
||||
} else { // Otherwise just draw as 2D
|
||||
video::ITexture *texture = client->idef()->getInventoryTexture(def.name, client);
|
||||
if (!texture)
|
||||
return;
|
||||
video::SColor color =
|
||||
client->idef()->getItemstackColor(item, client);
|
||||
const video::SColor colors[] = { color, color, color, color };
|
||||
|
||||
// draw the inventory_overlay
|
||||
if (def.type == ITEM_NODE && def.inventory_image.empty() &&
|
||||
!def.inventory_overlay.empty()) {
|
||||
ITextureSource *tsrc = client->getTextureSource();
|
||||
video::ITexture *overlay_texture = tsrc->getTexture(def.inventory_overlay);
|
||||
core::dimension2d<u32> dimens = overlay_texture->getOriginalSize();
|
||||
core::rect<s32> srcrect(0, 0, dimens.Width, dimens.Height);
|
||||
draw2DImageFilterScaled(driver, overlay_texture, rect, srcrect, clip, 0, true);
|
||||
}
|
||||
draw2DImageFilterScaled(driver, texture, rect,
|
||||
core::rect<s32>({0, 0}, core::dimension2di(texture->getOriginalSize())),
|
||||
clip, colors, true);
|
||||
}
|
||||
|
||||
// draw the inventory_overlay
|
||||
if (def.type == ITEM_NODE && def.inventory_image.empty() &&
|
||||
!def.inventory_overlay.empty()) {
|
||||
ITextureSource *tsrc = client->getTextureSource();
|
||||
video::ITexture *overlay_texture = tsrc->getTexture(def.inventory_overlay);
|
||||
core::dimension2d<u32> dimens = overlay_texture->getOriginalSize();
|
||||
core::rect<s32> srcrect(0, 0, dimens.Width, dimens.Height);
|
||||
draw2DImageFilterScaled(driver, overlay_texture, rect, srcrect, clip, 0, true);
|
||||
}
|
||||
|
||||
if (def.type == ITEM_TOOL && item.wear != 0) {
|
||||
|
@ -336,7 +336,6 @@ void GUIChatConsole::drawText()
|
||||
tmp->draw(
|
||||
fragment.text,
|
||||
destrect,
|
||||
video::SColor(255, 255, 255, 255),
|
||||
false,
|
||||
false,
|
||||
&AbsoluteClippingRect);
|
||||
|
@ -548,12 +548,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)
|
||||
{
|
||||
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)
|
||||
return;
|
||||
@ -563,6 +563,7 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
||||
{
|
||||
Glyph_Pages[i]->render_positions.clear();
|
||||
Glyph_Pages[i]->render_source_rects.clear();
|
||||
Glyph_Pages[i]->render_colors.clear();
|
||||
}
|
||||
|
||||
// Set up some variables.
|
||||
@ -591,7 +592,6 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
||||
u32 n;
|
||||
uchar32_t previousChar = 0;
|
||||
core::ustring::const_iterator iter(utext);
|
||||
std::vector<video::SColor> applied_colors;
|
||||
while (!iter.atEnd())
|
||||
{
|
||||
uchar32_t currentChar = *iter;
|
||||
@ -637,10 +637,11 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
||||
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page];
|
||||
page->render_positions.push_back(core::position2di(offset.X + offx, offset.Y + offy));
|
||||
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);
|
||||
u32 current_color = iter.getPos();
|
||||
if (current_color < colors.size())
|
||||
applied_colors.push_back(colors[current_color]);
|
||||
}
|
||||
offset.X += getWidthFromCharacter(currentChar);
|
||||
|
||||
@ -666,16 +667,23 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
|
||||
for (size_t i = 0; i < page->render_positions.size(); ++i)
|
||||
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) {
|
||||
irr::video::SColor col;
|
||||
if (!applied_colors.empty()) {
|
||||
col = applied_colors[i < applied_colors.size() ? i : 0];
|
||||
} else {
|
||||
col = irr::video::SColor(255, 255, 255, 255);
|
||||
}
|
||||
ibegin = i;
|
||||
colprev = page->render_colors[i];
|
||||
do
|
||||
++i;
|
||||
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)
|
||||
col.color |= 0xff000000;
|
||||
Driver->draw2DImage(page->texture, page->render_positions[i], page->render_source_rects[i], clip, col, true);
|
||||
colprev.color |= 0xff000000;
|
||||
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::recti> render_source_rects;
|
||||
core::array<video::SColor> render_colors;
|
||||
|
||||
private:
|
||||
core::array<const SGUITTGlyph*> glyph_to_be_paged;
|
||||
@ -270,7 +271,7 @@ namespace gui
|
||||
const core::rect<s32>* clip=0);
|
||||
|
||||
virtual 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);
|
||||
|
||||
//! Returns the dimension of a character produced by this font.
|
||||
|
@ -107,16 +107,11 @@ void StaticText::draw()
|
||||
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 (font->getType() == irr::gui::EGFT_CUSTOM) {
|
||||
irr::gui::CGUITTFont *tmp = static_cast<irr::gui::CGUITTFont*>(font);
|
||||
tmp->draw(str,
|
||||
r, previous_color, // FIXME
|
||||
HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
||||
r, HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER,
|
||||
(RestrainTextInside ? &AbsoluteClippingRect : NULL));
|
||||
} else
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user