Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop wasting memory on identical textures when texture filtering is d…
…isabled
  • Loading branch information
sfan5 committed May 20, 2020
1 parent 732c800 commit c47a680
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/client/tile.cpp
Expand Up @@ -668,7 +668,14 @@ video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id)

video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id)
{
return getTexture(name + "^[applyfiltersformesh", id);
static thread_local bool filter_needed =
g_settings->getBool("texture_clean_transparent") ||
((m_setting_trilinear_filter || m_setting_bilinear_filter) &&
g_settings->getS32("texture_min_size") > 1);
// Avoid duplicating texture if it won't actually change
if (filter_needed)
return getTexture(name + "^[applyfiltersformesh", id);
return getTexture(name, id);
}

Palette* TextureSource::getPalette(const std::string &name)
Expand Down Expand Up @@ -1623,6 +1630,9 @@ bool TextureSource::generateImagePart(std::string part_of_name,
*/
else if (str_starts_with(part_of_name, "[applyfiltersformesh"))
{
/* IMPORTANT: When changing this, getTextureForMesh() needs to be
* updated too. */

// Apply the "clean transparent" filter, if configured.
if (g_settings->getBool("texture_clean_transparent"))
imageCleanTransparent(baseimg, 127);
Expand Down

0 comments on commit c47a680

Please sign in to comment.