From 9e0189019e363a82393e76435897d26984b5037d Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Fri, 23 Jun 2023 11:33:29 +0200 Subject: [PATCH] Refactor the way you set material properties Instead of using SMaterial::setFlag, you now set them directly on SMaterial or SMaterialLayer. --- examples/AutomatedTest/main.cpp | 6 +- include/EMaterialFlags.h | 62 +++++-------- include/IMesh.h | 5 - include/ISceneNode.h | 40 ++------ include/SAnimatedMesh.h | 7 -- include/SMaterial.h | 153 +++---------------------------- include/SMesh.h | 7 -- source/Irrlicht/CSkinnedMesh.cpp | 8 -- source/Irrlicht/CSkinnedMesh.h | 3 - 9 files changed, 48 insertions(+), 243 deletions(-) diff --git a/examples/AutomatedTest/main.cpp b/examples/AutomatedTest/main.cpp index 96cbc738..99fa5a96 100644 --- a/examples/AutomatedTest/main.cpp +++ b/examples/AutomatedTest/main.cpp @@ -100,10 +100,12 @@ int main(int argc, char *argv[]) scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh); if (node) { - node->setMaterialFlag(video::EMF_LIGHTING, false); + node->forEachMaterial([tex] (video::SMaterial &mat) { + mat.Lighting = false; + mat.setTexture(0, tex); + }); node->setFrameLoop(0, 29); node->setAnimationSpeed(30); - node->setMaterialTexture(0, tex); } } diff --git a/include/EMaterialFlags.h b/include/EMaterialFlags.h index 04ef13ea..c2ebdee3 100644 --- a/include/EMaterialFlags.h +++ b/include/EMaterialFlags.h @@ -13,84 +13,70 @@ namespace video //! Material flags enum E_MATERIAL_FLAG { - //! Draw as wireframe or filled triangles? Default: false + //! Corresponds to SMaterial::Wireframe. EMF_WIREFRAME = 0x1, - //! Draw as point cloud or filled triangles? Default: false + //! Corresponds to SMaterial::PointCloud. EMF_POINTCLOUD = 0x2, - //! Flat or Gouraud shading? Default: true + //! Corresponds to SMaterial::GouraudShading. EMF_GOURAUD_SHADING = 0x4, - //! Will this material be lighted? Default: true + //! Corresponds to SMaterial::Lighting. EMF_LIGHTING = 0x8, - //! Is the ZBuffer enabled? Default: true + //! Corresponds to SMaterial::ZBuffer. EMF_ZBUFFER = 0x10, - //! May be written to the zbuffer or is it readonly. Default: true - /** This flag is ignored, if the material type is a transparent type. */ + //! Corresponds to SMaterial::ZWriteEnable. EMF_ZWRITE_ENABLE = 0x20, - //! Is backface culling enabled? Default: true + //! Corresponds to SMaterial::BackfaceCulling. EMF_BACK_FACE_CULLING = 0x40, - //! Is frontface culling enabled? Default: false - /** Overrides EMF_BACK_FACE_CULLING if both are enabled. */ + //! Corresponds to SMaterial::FrontfaceCulling. EMF_FRONT_FACE_CULLING = 0x80, - //! Is bilinear filtering enabled? Default: true + //! Corresponds to SMaterialLayer::BilinearFilter. EMF_BILINEAR_FILTER = 0x100, - //! Is trilinear filtering enabled? Default: false - /** If the trilinear filter flag is enabled, - the bilinear filtering flag is ignored. */ + //! Corresponds to SMaterialLayer::TrilinearFilter. EMF_TRILINEAR_FILTER = 0x200, - //! Is anisotropic filtering? Default: false - /** In Irrlicht you can use anisotropic texture filtering in - conjunction with bilinear or trilinear texture filtering - to improve rendering results. Primitives will look less - blurry with this flag switched on. */ + //! Corresponds to SMaterialLayer::AnisotropicFilter. EMF_ANISOTROPIC_FILTER = 0x400, - //! Is fog enabled? Default: false + //! Corresponds to SMaterial::FogEnable. EMF_FOG_ENABLE = 0x800, - //! Normalizes normals. Default: false - /** You can enable this if you need to scale a dynamic lighted - model. Usually, its normals will get scaled too then and it - will get darker. If you enable the EMF_NORMALIZE_NORMALS flag, - the normals will be normalized again, and the model will look - as bright as it should. */ + //! Corresponds to SMaterial::NormalizeNormals. EMF_NORMALIZE_NORMALS = 0x1000, - //! Access to all layers texture wrap settings. Overwrites separate layer settings. - /** Note that if you want to change TextureWrapU, TextureWrapV, TextureWrapW - independently, then you can't work with this flag, but will have to set the variables - directly. */ + //! Corresponds to SMaterialLayer::TextureWrapU, TextureWrapV and + //! TextureWrapW. EMF_TEXTURE_WRAP = 0x2000, - //! AntiAliasing mode + //! Corresponds to SMaterial::AntiAliasing. EMF_ANTI_ALIASING = 0x4000, - //! ColorMask bits, for enabling the color planes + //! Corresponds to SMaterial::ColorMask. EMF_COLOR_MASK = 0x8000, - //! ColorMaterial enum for vertex color interpretation + //! Corresponds to SMaterial::ColorMaterial. EMF_COLOR_MATERIAL = 0x10000, - //! Flag for enabling/disabling mipmap usage + //! Corresponds to SMaterial::UseMipMaps. EMF_USE_MIP_MAPS = 0x20000, - //! Flag for blend operation + //! Corresponds to SMaterial::BlendOperation. EMF_BLEND_OPERATION = 0x40000, - //! Flag for polygon offset + //! Corresponds to SMaterial::PolygonOffsetFactor, PolygonOffsetDirection, + //! PolygonOffsetDepthBias and PolygonOffsetSlopeScale. EMF_POLYGON_OFFSET = 0x80000, - //! Flag for blend factor - EMF_BLEND_FACTOR = 0x160000 + //! Corresponds to SMaterial::BlendFactor. + EMF_BLEND_FACTOR = 0x100000, }; } // end namespace video diff --git a/include/IMesh.h b/include/IMesh.h index 227ef509..215aebde 100644 --- a/include/IMesh.h +++ b/include/IMesh.h @@ -97,11 +97,6 @@ namespace scene /** \param box New bounding box to use for the mesh. */ virtual void setBoundingBox( const core::aabbox3df& box) = 0; - //! Sets a flag of all contained materials to a new value. - /** \param flag: Flag to set in all materials. - \param newvalue: New value to set in all materials. */ - virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) = 0; - //! Set the hardware mapping hint /** This methods allows to define optimization hints for the hardware. This enables, e.g., the use of hardware buffers on diff --git a/include/ISceneNode.h b/include/ISceneNode.h index 1f8c2c6b..fe8400ad 100644 --- a/include/ISceneNode.h +++ b/include/ISceneNode.h @@ -352,38 +352,14 @@ namespace scene } - //! Sets all material flags at once to a new value. - /** Useful, for example, if you want the whole mesh to be - affected by light. - \param flag Which flag of all materials to be set. - \param newvalue New value of that flag. */ - void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) - { - for (u32 i=0; i= video::MATERIAL_MAX_TEXTURES) - return; - - for (u32 i=0; i + void forEachMaterial(F &&fn) { + for (u32 i = 0; i < getMaterialCount(); i++) { + fn(getMaterial(i)); + } } diff --git a/include/SAnimatedMesh.h b/include/SAnimatedMesh.h index 7ab45ef2..eb67e5e6 100644 --- a/include/SAnimatedMesh.h +++ b/include/SAnimatedMesh.h @@ -147,13 +147,6 @@ namespace scene return Meshes[0]->getMeshBuffer(material); } - //! Set a material flag for all meshbuffers of this mesh. - void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override - { - for (u32 i=0; isetMaterialFlag(flag, newvalue); - } - //! set the hardware mapping hint, for driver void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) override { diff --git a/include/SMaterial.h b/include/SMaterial.h index 154bf296..3caf2b48 100644 --- a/include/SMaterial.h +++ b/include/SMaterial.h @@ -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 + 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; igetMaterial().setFlag(flag, newvalue); - } - //! set the hardware mapping hint, for driver void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) override { diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index 75e2ca64..22fc3738 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -690,14 +690,6 @@ void CSkinnedMesh::setBoundingBox( const core::aabbox3df& box) } -//! sets a flag of all contained materials to a new value -void CSkinnedMesh::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) -{ - for (u32 i=0; iMaterial.setFlag(flag,newvalue); -} - - //! set the hardware mapping hint, for driver void CSkinnedMesh::setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer) diff --git a/source/Irrlicht/CSkinnedMesh.h b/source/Irrlicht/CSkinnedMesh.h index 4c919ccf..c1777769 100644 --- a/source/Irrlicht/CSkinnedMesh.h +++ b/source/Irrlicht/CSkinnedMesh.h @@ -72,9 +72,6 @@ namespace scene //! set user axis aligned bounding box void setBoundingBox( const core::aabbox3df& box) override; - //! sets a flag of all contained materials to a new value - void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override; - //! set the hardware mapping hint, for driver void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override;