Expose all OpenGL filtering modes, use OpenGL names for them

Because of a review comment by numberZero.
This commit is contained in:
Gregor Parzefall 2023-06-24 23:36:20 +02:00 committed by sfan5
parent c40045a40a
commit a994c31ccf
7 changed files with 58 additions and 40 deletions

View File

@ -45,26 +45,28 @@ namespace video
//! Texture minification filter.
/** Used when scaling textures down. */
/** Used when scaling textures down. See the documentation on OpenGL's
`GL_TEXTURE_MIN_FILTER` for more information. */
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,
//! Aka nearest-neighbor.
ETMINF_NEAREST_MIPMAP_NEAREST = 0,
//! Aka bilinear.
ETMINF_LINEAR_MIPMAP_NEAREST,
//! Isn't known by any other name.
ETMINF_NEAREST_MIPMAP_LINEAR,
//! Aka trilinear.
ETMINF_LINEAR_MIPMAP_LINEAR,
};
//! Texture magnification filter.
/** Used when scaling textures up. */
/** Used when scaling textures up. See the documentation on OpenGL's
`GL_TEXTURE_MAG_FILTER` for more information.
Note that mipmaps are only used for minification, not for magnification. */
enum E_TEXTURE_MAG_FILTER {
//! Nearest-neighbor interpolation.
//! Aka nearest-neighbor.
ETMAGF_NEAREST = 0,
//! Linear interpolation.
ETMAGF_BILINEAR,
//! Aka bilinear.
ETMAGF_LINEAR,
};
//! Struct for holding material parameters which exist per texture layer
@ -74,7 +76,7 @@ namespace video
public:
//! Default constructor
SMaterialLayer() : Texture(0), TextureWrapU(ETC_REPEAT), TextureWrapV(ETC_REPEAT), TextureWrapW(ETC_REPEAT),
MinFilter(ETMINF_BILINEAR), MagFilter(ETMAGF_BILINEAR), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
MinFilter(ETMINF_LINEAR_MIPMAP_NEAREST), MagFilter(ETMAGF_LINEAR), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
{
}
@ -234,9 +236,9 @@ namespace video
//! 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;
MinFilter = trilinear ? ETMINF_LINEAR_MIPMAP_LINEAR :
(bilinear ? ETMINF_LINEAR_MIPMAP_NEAREST : ETMINF_NEAREST_MIPMAP_NEAREST);
MagFilter = (trilinear || bilinear) ? ETMAGF_LINEAR : ETMAGF_NEAREST;
AnisotropicFilter = anisotropic ? 0xFF : 0;
}

View File

@ -103,7 +103,7 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
InitMaterial2D.ZBuffer = video::ECFN_DISABLED;
InitMaterial2D.UseMipMaps = false;
InitMaterial2D.forEachTexture([] (auto &tex) {
tex.MinFilter = video::ETMINF_NEAREST;
tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
tex.TextureWrapU = video::ETC_REPEAT;
tex.TextureWrapV = video::ETC_REPEAT;

View File

@ -4,6 +4,7 @@
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "COGLES2Driver.h"
#include <cassert>
#include "CNullDriver.h"
#include "IContextManager.h"
@ -1700,7 +1701,8 @@ COGLES2Driver::~COGLES2Driver()
{
E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER,
magFilter == ETMAGF_BILINEAR ? GL_LINEAR : GL_NEAREST);
magFilter == ETMAGF_NEAREST ? GL_NEAREST :
(assert(magFilter == ETMAGF_LINEAR), GL_LINEAR));
tmpTexture->getStatesCache().MagFilter = magFilter;
}
@ -1712,9 +1714,10 @@ COGLES2Driver::~COGLES2Driver()
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
minFilter == ETMINF_TRILINEAR ? GL_LINEAR_MIPMAP_LINEAR :
minFilter == ETMINF_BILINEAR ? GL_LINEAR_MIPMAP_NEAREST :
GL_NEAREST_MIPMAP_NEAREST);
minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST :
minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST :
minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR));
tmpTexture->getStatesCache().MinFilter = minFilter;
tmpTexture->getStatesCache().MipMapStatus = true;
@ -1727,7 +1730,8 @@ COGLES2Driver::~COGLES2Driver()
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
(minFilter == ETMINF_TRILINEAR || minFilter == ETMINF_BILINEAR) ? GL_LINEAR : GL_NEAREST);
(minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR));
tmpTexture->getStatesCache().MinFilter = minFilter;
tmpTexture->getStatesCache().MipMapStatus = false;

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "COGLESDriver.h"
#include <cassert>
#include "CNullDriver.h"
#include "IContextManager.h"
@ -1918,7 +1919,8 @@ void COGLES1Driver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER,
magFilter == ETMAGF_BILINEAR ? GL_LINEAR : GL_NEAREST);
magFilter == ETMAGF_NEAREST ? GL_NEAREST :
(assert(magFilter == ETMAGF_LINEAR), GL_LINEAR));
statesCache.MagFilter = magFilter;
}
@ -1930,9 +1932,10 @@ void COGLES1Driver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
minFilter == ETMINF_TRILINEAR ? GL_LINEAR_MIPMAP_LINEAR :
minFilter == ETMINF_BILINEAR ? GL_LINEAR_MIPMAP_NEAREST :
GL_NEAREST_MIPMAP_NEAREST);
minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST :
minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST :
minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR));
statesCache.MinFilter = minFilter;
statesCache.MipMapStatus = true;
@ -1945,7 +1948,9 @@ void COGLES1Driver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
(minFilter == ETMINF_TRILINEAR || minFilter == ETMINF_BILINEAR) ? GL_LINEAR : GL_NEAREST);
(minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR));
statesCache.MinFilter = minFilter;
statesCache.MipMapStatus = false;

View File

@ -31,7 +31,7 @@ public:
struct SStatesCache
{
SStatesCache() : WrapU(ETC_REPEAT), WrapV(ETC_REPEAT), WrapW(ETC_REPEAT),
LODBias(0), AnisotropicFilter(0), MinFilter(video::ETMINF_NEAREST),
LODBias(0), AnisotropicFilter(0), MinFilter(video::ETMINF_NEAREST_MIPMAP_NEAREST),
MagFilter(video::ETMAGF_NEAREST), MipMapStatus(false), IsCached(false)
{
}

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "COpenGLDriver.h"
#include <cassert>
#include "CNullDriver.h"
#include "IContextManager.h"
@ -2713,7 +2714,8 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter;
glTexParameteri(tmpType, GL_TEXTURE_MAG_FILTER,
magFilter == ETMAGF_BILINEAR ? GL_LINEAR : GL_NEAREST);
magFilter == ETMAGF_NEAREST ? GL_NEAREST :
(assert(magFilter == ETMAGF_LINEAR), GL_LINEAR));
statesCache.MagFilter = magFilter;
}
@ -2725,9 +2727,10 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER,
minFilter == ETMINF_TRILINEAR ? GL_LINEAR_MIPMAP_LINEAR :
minFilter == ETMINF_BILINEAR ? GL_LINEAR_MIPMAP_NEAREST :
GL_NEAREST_MIPMAP_NEAREST);
minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST :
minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST :
minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR));
statesCache.MinFilter = minFilter;
statesCache.MipMapStatus = true;
@ -2740,7 +2743,8 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpType, GL_TEXTURE_MIN_FILTER,
(minFilter == ETMINF_TRILINEAR || minFilter == ETMINF_BILINEAR) ? GL_LINEAR : GL_NEAREST);
(minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR));
statesCache.MinFilter = minFilter;
statesCache.MipMapStatus = false;

View File

@ -1460,7 +1460,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase()
{
E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER,
magFilter == ETMAGF_BILINEAR ? GL_LINEAR : GL_NEAREST);
magFilter == ETMAGF_NEAREST ? GL_NEAREST :
(assert(magFilter == ETMAGF_LINEAR), GL_LINEAR));
tmpTexture->getStatesCache().MagFilter = magFilter;
}
@ -1472,9 +1473,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase()
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
minFilter == ETMINF_TRILINEAR ? GL_LINEAR_MIPMAP_LINEAR :
minFilter == ETMINF_BILINEAR ? GL_LINEAR_MIPMAP_NEAREST :
GL_NEAREST_MIPMAP_NEAREST);
minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST :
minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST :
minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR));
tmpTexture->getStatesCache().MinFilter = minFilter;
tmpTexture->getStatesCache().MipMapStatus = true;
@ -1487,7 +1489,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase()
{
E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter;
glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER,
(minFilter == ETMINF_TRILINEAR || minFilter == ETMINF_BILINEAR) ? GL_LINEAR : GL_NEAREST);
(minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST :
(assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR));
tmpTexture->getStatesCache().MinFilter = minFilter;
tmpTexture->getStatesCache().MipMapStatus = false;