Split up texture filtering properties of SMaterialLayer into MinFilter and MagFilter

You can now set the filter used when scaling textures down and the filter used when scaling textures up separately.
This commit is contained in:
Gregor Parzefall
2023-06-23 13:58:50 +02:00
committed by sfan5
parent 9e0189019e
commit 5ececc7d29
10 changed files with 128 additions and 101 deletions

View File

@ -43,6 +43,30 @@ namespace video
"texture_clamp_mirror_clamp_to_edge",
"texture_clamp_mirror_clamp_to_border", 0};
//! Texture minification filter.
/** Used when scaling textures down. */
enum E_TEXTURE_MIN_FILTER {
//! Nearest-neighbor interpolation.
ETMINF_NEAREST = 0,
//! Linear interpolation.
ETMINF_BILINEAR,
//! Linear interpolation across mipmaps.
/** Is equivalent to ETMINF_BILINEAR if mipmaps are disabled.
Only available as a minification filter since mipmaps are only used
when scaling down. */
ETMINF_TRILINEAR,
};
//! Texture magnification filter.
/** Used when scaling textures up. */
enum E_TEXTURE_MAG_FILTER {
//! Nearest-neighbor interpolation.
ETMAGF_NEAREST = 0,
//! Linear interpolation.
ETMAGF_BILINEAR,
};
//! Struct for holding material parameters which exist per texture layer
// Note for implementors: Serialization is in CNullDriver
class SMaterialLayer
@ -50,7 +74,7 @@ namespace video
public:
//! Default constructor
SMaterialLayer() : Texture(0), TextureWrapU(ETC_REPEAT), TextureWrapV(ETC_REPEAT), TextureWrapW(ETC_REPEAT),
BilinearFilter(true), TrilinearFilter(false), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
MinFilter(ETMINF_BILINEAR), MagFilter(ETMAGF_BILINEAR), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
{
}
@ -104,8 +128,8 @@ namespace video
TextureWrapU = other.TextureWrapU;
TextureWrapV = other.TextureWrapV;
TextureWrapW = other.TextureWrapW;
BilinearFilter = other.BilinearFilter;
TrilinearFilter = other.TrilinearFilter;
MinFilter = other.MinFilter;
MagFilter = other.MagFilter;
AnisotropicFilter = other.AnisotropicFilter;
LODBias = other.LODBias;
@ -157,8 +181,8 @@ namespace video
TextureWrapU != b.TextureWrapU ||
TextureWrapV != b.TextureWrapV ||
TextureWrapW != b.TextureWrapW ||
BilinearFilter != b.BilinearFilter ||
TrilinearFilter != b.TrilinearFilter ||
MinFilter != b.MinFilter ||
MagFilter != b.MagFilter ||
AnisotropicFilter != b.AnisotropicFilter ||
LODBias != b.LODBias;
if (different)
@ -184,13 +208,11 @@ namespace video
u8 TextureWrapV:4;
u8 TextureWrapW:4;
//! Is bilinear filtering enabled? Default: true
bool BilinearFilter:1;
//! Minification (downscaling) filter
E_TEXTURE_MIN_FILTER MinFilter;
//! Is trilinear filtering enabled? Default: false
/** If the trilinear filter flag is enabled,
the bilinear filtering flag is ignored. */
bool TrilinearFilter:1;
//! Magnification (upscaling) filter
E_TEXTURE_MAG_FILTER MagFilter;
//! Is anisotropic filtering enabled? Default: 0, disabled
/** In Irrlicht you can use anisotropic texture filtering
@ -208,6 +230,16 @@ namespace video
if the value is positive. */
s8 LODBias;
//! Sets the MinFilter, MagFilter and AnisotropicFilter properties according
//! to the three relevant boolean values found in the Minetest settings.
/** The value of `trilinear` takes precedence over the value of `bilinear`. */
void setFiltersMinetest(bool bilinear, bool trilinear, bool anisotropic) {
MinFilter = trilinear ? ETMINF_TRILINEAR :
(bilinear ? ETMINF_BILINEAR : ETMINF_NEAREST);
MagFilter = (trilinear || bilinear) ? ETMAGF_BILINEAR : ETMAGF_NEAREST;
AnisotropicFilter = anisotropic ? 0xFF : 0;
}
private:
friend class SMaterial;