Refactor the way you set material properties

Instead	of using SMaterial::setFlag, you now set them directly on SMaterial or SMaterialLayer.
This commit is contained in:
Gregor Parzefall
2023-06-23 11:33:29 +02:00
committed by sfan5
parent b249e4523d
commit 9e0189019e
9 changed files with 48 additions and 243 deletions

View File

@ -256,7 +256,7 @@ namespace video
EZW_OFF = 0,
//! This is the default setting for SMaterial and tries to handle things automatically.
//! This is also the value which is set when SMaterial::setFlag(EMF_ZWRITE_ENABLE) is enabled.
//! This is what you want to set to enable zwriting.
//! Usually zwriting is enabled non-transparent materials - as far as Irrlicht can recognize those.
//! Basically Irrlicht tries to handle the zwriting for you and assumes transparent materials don't need it.
//! This is addionally affected by IVideoDriver::setAllowZWriteOnTransparent
@ -426,9 +426,7 @@ namespace video
f32 PolygonOffsetSlopeScale;
//! Draw as wireframe or filled triangles? Default: false
/** The user can access a material flag using
\code material.Wireframe=true \endcode
or \code material.setFlag(EMF_WIREFRAME, true); \endcode */
/** The user can access a material flag using \code material.Wireframe = true; \endcode */
bool Wireframe:1;
//! Draw as point cloud or filled triangles? Default: false
@ -462,6 +460,16 @@ namespace video
/** Sometimes, disabling mipmap usage can be useful. Default: true */
bool UseMipMaps:1;
//! Execute a function on all texture layers.
/** Useful for setting properties which are not per material, but per
texture layer, e.g. bilinear filtering. */
template <typename F>
void forEachTexture(F &&fn) {
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; i++) {
fn(TextureLayer[i]);
}
}
//! Gets the texture transformation matrix for level i
/** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
\return Texture matrix for texture level i. */
@ -510,143 +518,6 @@ namespace video
TextureLayer[i].Texture = tex;
}
//! Sets the Material flag to the given value
/** \param flag The flag to be set.
\param value The new value for the flag. */
void setFlag(E_MATERIAL_FLAG flag, bool value)
{
switch (flag)
{
case EMF_WIREFRAME:
Wireframe = value; break;
case EMF_POINTCLOUD:
PointCloud = value; break;
case EMF_GOURAUD_SHADING:
GouraudShading = value; break;
case EMF_LIGHTING:
Lighting = value; break;
case EMF_ZBUFFER:
ZBuffer = value; break;
case EMF_ZWRITE_ENABLE:
ZWriteEnable = value ? EZW_AUTO : EZW_OFF; break;
case EMF_BACK_FACE_CULLING:
BackfaceCulling = value; break;
case EMF_FRONT_FACE_CULLING:
FrontfaceCulling = value; break;
case EMF_BILINEAR_FILTER:
{
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
TextureLayer[i].BilinearFilter = value;
}
break;
case EMF_TRILINEAR_FILTER:
{
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
TextureLayer[i].TrilinearFilter = value;
}
break;
case EMF_ANISOTROPIC_FILTER:
{
if (value)
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
TextureLayer[i].AnisotropicFilter = 0xFF;
else
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
TextureLayer[i].AnisotropicFilter = 0;
}
break;
case EMF_FOG_ENABLE:
FogEnable = value; break;
case EMF_NORMALIZE_NORMALS:
NormalizeNormals = value; break;
case EMF_TEXTURE_WRAP:
{
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value;
TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value;
TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)value;
}
}
break;
case EMF_ANTI_ALIASING:
AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
case EMF_COLOR_MASK:
ColorMask = value?ECP_ALL:ECP_NONE; break;
case EMF_COLOR_MATERIAL:
ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
case EMF_USE_MIP_MAPS:
UseMipMaps = value; break;
case EMF_BLEND_OPERATION:
BlendOperation = value?EBO_ADD:EBO_NONE; break;
case EMF_BLEND_FACTOR:
break;
case EMF_POLYGON_OFFSET:
PolygonOffsetFactor = value?1:0;
PolygonOffsetDirection = EPO_BACK;
PolygonOffsetSlopeScale = value?1.f:0.f;
PolygonOffsetDepthBias = value?1.f:0.f;
default:
break;
}
}
//! Gets the Material flag
/** \param flag The flag to query.
\return The current value of the flag. */
bool getFlag(E_MATERIAL_FLAG flag) const
{
switch (flag)
{
case EMF_WIREFRAME:
return Wireframe;
case EMF_POINTCLOUD:
return PointCloud;
case EMF_GOURAUD_SHADING:
return GouraudShading;
case EMF_LIGHTING:
return Lighting;
case EMF_ZBUFFER:
return ZBuffer!=ECFN_DISABLED;
case EMF_ZWRITE_ENABLE:
return ZWriteEnable != EZW_OFF;
case EMF_BACK_FACE_CULLING:
return BackfaceCulling;
case EMF_FRONT_FACE_CULLING:
return FrontfaceCulling;
case EMF_BILINEAR_FILTER:
return TextureLayer[0].BilinearFilter;
case EMF_TRILINEAR_FILTER:
return TextureLayer[0].TrilinearFilter;
case EMF_ANISOTROPIC_FILTER:
return TextureLayer[0].AnisotropicFilter!=0;
case EMF_FOG_ENABLE:
return FogEnable;
case EMF_NORMALIZE_NORMALS:
return NormalizeNormals;
case EMF_TEXTURE_WRAP:
return !(TextureLayer[0].TextureWrapU ||
TextureLayer[0].TextureWrapV ||
TextureLayer[0].TextureWrapW);
case EMF_ANTI_ALIASING:
return (AntiAliasing==1);
case EMF_COLOR_MASK:
return (ColorMask!=ECP_NONE);
case EMF_COLOR_MATERIAL:
return (ColorMaterial != ECM_NONE);
case EMF_USE_MIP_MAPS:
return UseMipMaps;
case EMF_BLEND_OPERATION:
return BlendOperation != EBO_NONE;
case EMF_BLEND_FACTOR:
return BlendFactor != 0.f;
case EMF_POLYGON_OFFSET:
return PolygonOffsetFactor != 0 || PolygonOffsetDepthBias != 0.f;
}
return false;
}
//! Inequality operator
/** \param b Material to compare to.
\return True if the materials differ, else false. */