Commit 0d8210fa authored by hybrid's avatar hybrid

Add Mipmap LOD Bias to texture layers.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2133 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 1864555d
...@@ -45,7 +45,9 @@ namespace video ...@@ -45,7 +45,9 @@ namespace video
TextureWrap(ETC_REPEAT), TextureWrap(ETC_REPEAT),
BilinearFilter(true), BilinearFilter(true),
TrilinearFilter(false), TrilinearFilter(false),
AnisotropicFilter(0), TextureMatrix(0) AnisotropicFilter(0),
LODBias(0),
TextureMatrix(0)
{} {}
//! Copy constructor //! Copy constructor
...@@ -99,6 +101,7 @@ namespace video ...@@ -99,6 +101,7 @@ namespace video
BilinearFilter = other.BilinearFilter; BilinearFilter = other.BilinearFilter;
TrilinearFilter = other.TrilinearFilter; TrilinearFilter = other.TrilinearFilter;
AnisotropicFilter = other.AnisotropicFilter; AnisotropicFilter = other.AnisotropicFilter;
LODBias = other.LODBias;
return *this; return *this;
} }
...@@ -107,15 +110,15 @@ namespace video ...@@ -107,15 +110,15 @@ namespace video
ITexture* Texture; ITexture* Texture;
//! Texture Clamp Mode //! Texture Clamp Mode
E_TEXTURE_CLAMP TextureWrap; u8 TextureWrap;
//! Is bilinear filtering enabled? Default: true //! Is bilinear filtering enabled? Default: true
bool BilinearFilter; bool BilinearFilter:1;
//! Is trilinear filtering enabled? Default: false //! Is trilinear filtering enabled? Default: false
/** If the trilinear filter flag is enabled, /** If the trilinear filter flag is enabled,
the bilinear filtering flag is ignored. */ the bilinear filtering flag is ignored. */
bool TrilinearFilter; bool TrilinearFilter:1;
//! Is anisotropic filtering enabled? Default: 0, disabled //! Is anisotropic filtering enabled? Default: 0, disabled
/** In Irrlicht you can use anisotropic texture filtering /** In Irrlicht you can use anisotropic texture filtering
...@@ -126,6 +129,13 @@ namespace video ...@@ -126,6 +129,13 @@ namespace video
Value 1 is equivalent to 0, but should be avoided. */ Value 1 is equivalent to 0, but should be avoided. */
u8 AnisotropicFilter; u8 AnisotropicFilter;
//! Bias for the mipmap choosing decision.
/** This value can make the textures more or less blurry than with the
default value of 0. The value (divided by 8.f) is added to the mipmap level
chosen initially, and thus takes a smaller mipmap for a region
if the value is positive. */
s8 LODBias;
//! Gets the texture transformation matrix //! Gets the texture transformation matrix
/** \return Texture matrix of this layer. */ /** \return Texture matrix of this layer. */
core::matrix4& getTextureMatrix() core::matrix4& getTextureMatrix()
...@@ -171,7 +181,8 @@ namespace video ...@@ -171,7 +181,8 @@ namespace video
TextureWrap != b.TextureWrap || TextureWrap != b.TextureWrap ||
BilinearFilter != b.BilinearFilter || BilinearFilter != b.BilinearFilter ||
TrilinearFilter != b.TrilinearFilter || TrilinearFilter != b.TrilinearFilter ||
AnisotropicFilter != b.AnisotropicFilter; AnisotropicFilter != b.AnisotropicFilter ||
LODBias != b.LODBias;
if (different) if (different)
return true; return true;
else else
......
...@@ -1469,6 +1469,12 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -1469,6 +1469,12 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria
// texture address mode // texture address mode
for (u32 st=0; st<MaxTextureUnits; ++st) for (u32 st=0; st<MaxTextureUnits; ++st)
{ {
if (resetAllRenderstates || lastmaterial.TextureLayer[st].LODBias != material.TextureLayer[st].LODBias)
{
const float tmp = material.TextureLayer[st].LODBias * 0.125f;
pID3DDevice->SetTextureStageState(st, D3DSAMP_MIPMAPLODBIAS, *(DWORD*)(&tmp));
}
if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrap != material.TextureLayer[st].TextureWrap) if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrap != material.TextureLayer[st].TextureWrap)
{ {
u32 mode = D3DTADDRESS_WRAP; u32 mode = D3DTADDRESS_WRAP;
......
...@@ -1828,6 +1828,12 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -1828,6 +1828,12 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
// texture address mode // texture address mode
for (u32 st=0; st<MaxTextureUnits; ++st) for (u32 st=0; st<MaxTextureUnits; ++st)
{ {
if (resetAllRenderstates || lastmaterial.TextureLayer[st].LODBias != material.TextureLayer[st].LODBias)
{
const float tmp = material.TextureLayer[st].LODBias * 0.125f;
pID3DDevice->SetSamplerState(st, D3DSAMP_MIPMAPLODBIAS, *(DWORD*)(&tmp));
}
if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrap != material.TextureLayer[st].TextureWrap) if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrap != material.TextureLayer[st].TextureWrap)
{ {
u32 mode = D3DTADDRESS_WRAP; u32 mode = D3DTADDRESS_WRAP;
......
...@@ -2013,6 +2013,19 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -2013,6 +2013,19 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
else if (i>0) else if (i>0)
break; break;
#ifdef EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
{
if (material.TextureLayer[i].LODBias)
{
const float tmp = core::clamp(material.TextureLayer[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias);
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp);
}
else
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f);
}
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
(material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST);
......
...@@ -21,7 +21,7 @@ COpenGLExtensionHandler::COpenGLExtensionHandler() : ...@@ -21,7 +21,7 @@ COpenGLExtensionHandler::COpenGLExtensionHandler() :
TextureCompressionExtension(false), TextureCompressionExtension(false),
MaxTextureUnits(1), MaxLights(1), MaxAnisotropy(1), MaxUserClipPlanes(0), MaxTextureUnits(1), MaxLights(1), MaxAnisotropy(1), MaxUserClipPlanes(0),
MaxAuxBuffers(0), MaxIndices(65535), MaxTextureSize(1), MaxAuxBuffers(0), MaxIndices(65535), MaxTextureSize(1),
Version(0), ShaderLanguageVersion(0) MaxTextureLODBias(0.f), Version(0), ShaderLanguageVersion(0)
#ifdef _IRR_OPENGL_USE_EXTPOINTER_ #ifdef _IRR_OPENGL_USE_EXTPOINTER_
,pGlActiveTextureARB(0), pGlClientActiveTextureARB(0), ,pGlActiveTextureARB(0), pGlClientActiveTextureARB(0),
pGlGenProgramsARB(0), pGlBindProgramARB(0), pGlProgramStringARB(0), pGlGenProgramsARB(0), pGlBindProgramARB(0), pGlProgramStringARB(0),
...@@ -411,6 +411,10 @@ void COpenGLExtensionHandler::initExtensions(bool stencilBuffer) ...@@ -411,6 +411,10 @@ void COpenGLExtensionHandler::initExtensions(bool stencilBuffer)
#endif #endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &num); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &num);
MaxTextureSize=static_cast<u32>(num); MaxTextureSize=static_cast<u32>(num);
#ifdef EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif
glGetIntegerv(GL_MAX_CLIP_PLANES, &num); glGetIntegerv(GL_MAX_CLIP_PLANES, &num);
MaxUserClipPlanes=static_cast<u8>(num); MaxUserClipPlanes=static_cast<u8>(num);
glGetIntegerv(GL_AUX_BUFFERS, &num); glGetIntegerv(GL_AUX_BUFFERS, &num);
......
...@@ -725,6 +725,8 @@ class COpenGLExtensionHandler ...@@ -725,6 +725,8 @@ class COpenGLExtensionHandler
u32 MaxIndices; u32 MaxIndices;
//! Maximal texture dimension //! Maximal texture dimension
u32 MaxTextureSize; u32 MaxTextureSize;
//! Maximal LOD Bias
f32 MaxTextureLODBias;
//! OpenGL version as Integer: 100*Major+Minor, i.e. 2.1 becomes 201 //! OpenGL version as Integer: 100*Major+Minor, i.e. 2.1 becomes 201
u16 Version; u16 Version;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment