mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up texture filtering settings (#13683)
This commit is contained in:
parent
d0ee63c766
commit
72ef90885d
8 changed files with 52 additions and 94 deletions
|
@ -433,10 +433,8 @@ private:
|
|||
// Maps image file names to loaded palettes.
|
||||
std::unordered_map<std::string, Palette> m_palettes;
|
||||
|
||||
// Cached settings needed for making textures from meshes
|
||||
bool m_setting_mipmap;
|
||||
bool m_setting_trilinear_filter;
|
||||
bool m_setting_bilinear_filter;
|
||||
// Cached settings needed for making textures for meshes
|
||||
bool m_mesh_texture_prefilter;
|
||||
};
|
||||
|
||||
IWritableTextureSource *createTextureSource()
|
||||
|
@ -455,9 +453,9 @@ TextureSource::TextureSource()
|
|||
// Cache some settings
|
||||
// Note: Since this is only done once, the game must be restarted
|
||||
// for these settings to take effect
|
||||
m_setting_mipmap = g_settings->getBool("mip_map");
|
||||
m_setting_trilinear_filter = g_settings->getBool("trilinear_filter");
|
||||
m_setting_bilinear_filter = g_settings->getBool("bilinear_filter");
|
||||
m_mesh_texture_prefilter =
|
||||
g_settings->getBool("mip_map") || g_settings->getBool("bilinear_filter") ||
|
||||
g_settings->getBool("trilinear_filter") || g_settings->getBool("anisotropic_filter");
|
||||
}
|
||||
|
||||
TextureSource::~TextureSource()
|
||||
|
@ -701,12 +699,8 @@ video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id)
|
|||
|
||||
video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id)
|
||||
{
|
||||
static thread_local bool filter_needed =
|
||||
g_settings->getBool("texture_clean_transparent") || m_setting_mipmap ||
|
||||
((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)
|
||||
if (m_mesh_texture_prefilter)
|
||||
return getTexture(name + "^[applyfiltersformesh", id);
|
||||
return getTexture(name, id);
|
||||
}
|
||||
|
@ -1741,46 +1735,8 @@ bool TextureSource::generateImagePart(std::string part_of_name,
|
|||
}
|
||||
|
||||
// Apply the "clean transparent" filter, if needed
|
||||
if (m_setting_mipmap || g_settings->getBool("texture_clean_transparent"))
|
||||
if (m_mesh_texture_prefilter)
|
||||
imageCleanTransparent(baseimg, 127);
|
||||
|
||||
/* Upscale textures to user's requested minimum size. This is a trick to make
|
||||
* filters look as good on low-res textures as on high-res ones, by making
|
||||
* low-res textures BECOME high-res ones. This is helpful for worlds that
|
||||
* mix high- and low-res textures, or for mods with least-common-denominator
|
||||
* textures that don't have the resources to offer high-res alternatives.
|
||||
*/
|
||||
const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter;
|
||||
const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1;
|
||||
if (scaleto > 1) {
|
||||
const core::dimension2d<u32> dim = baseimg->getDimension();
|
||||
|
||||
/* Calculate scaling needed to make the shortest texture dimension
|
||||
* equal to the target minimum. If e.g. this is a vertical frames
|
||||
* animation, the short dimension will be the real size.
|
||||
*/
|
||||
if ((dim.Width == 0) || (dim.Height == 0)) {
|
||||
errorstream << "generateImagePart(): Illegal 0 dimension "
|
||||
<< "for part_of_name=\""<< part_of_name
|
||||
<< "\", cancelling." << std::endl;
|
||||
return false;
|
||||
}
|
||||
u32 xscale = scaleto / dim.Width;
|
||||
u32 yscale = scaleto / dim.Height;
|
||||
u32 scale = (xscale > yscale) ? xscale : yscale;
|
||||
|
||||
// Never downscale; only scale up by 2x or more.
|
||||
if (scale > 1) {
|
||||
u32 w = scale * dim.Width;
|
||||
u32 h = scale * dim.Height;
|
||||
const core::dimension2d<u32> newdim = core::dimension2d<u32>(w, h);
|
||||
video::IImage *newimg = driver->createImage(
|
||||
baseimg->getColorFormat(), newdim);
|
||||
baseimg->copyToScaling(newimg);
|
||||
baseimg->drop();
|
||||
baseimg = newimg;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
[resize:WxH
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue