1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Reduce size of SMaterial struct

This commit is contained in:
sfan5 2025-01-08 18:29:40 +01:00
parent be75e42d77
commit 2cdf3af1b8
8 changed files with 39 additions and 42 deletions

View file

@ -20,7 +20,7 @@ class ITexture;
//! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor //! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor
//! BlendFunc = source * sourceFactor + dest * destFactor //! BlendFunc = source * sourceFactor + dest * destFactor
enum E_BLEND_FACTOR enum E_BLEND_FACTOR : u8
{ {
EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0) EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0)
EBF_ONE, //!< src & dest (1, 1, 1, 1) EBF_ONE, //!< src & dest (1, 1, 1, 1)
@ -36,7 +36,7 @@ enum E_BLEND_FACTOR
}; };
//! Values defining the blend operation //! Values defining the blend operation
enum E_BLEND_OPERATION enum E_BLEND_OPERATION : u8
{ {
EBO_NONE = 0, //!< No blending happens EBO_NONE = 0, //!< No blending happens
EBO_ADD, //!< Default blending adds the color values EBO_ADD, //!< Default blending adds the color values
@ -51,7 +51,7 @@ enum E_BLEND_OPERATION
}; };
//! MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X //! MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X
enum E_MODULATE_FUNC enum E_MODULATE_FUNC : u8
{ {
EMFN_MODULATE_1X = 1, EMFN_MODULATE_1X = 1,
EMFN_MODULATE_2X = 2, EMFN_MODULATE_2X = 2,
@ -59,7 +59,7 @@ enum E_MODULATE_FUNC
}; };
//! Comparison function, e.g. for depth buffer test //! Comparison function, e.g. for depth buffer test
enum E_COMPARISON_FUNC enum E_COMPARISON_FUNC : u8
{ {
//! Depth test disabled (disable also write to depth buffer) //! Depth test disabled (disable also write to depth buffer)
ECFN_DISABLED = 0, ECFN_DISABLED = 0,
@ -82,7 +82,7 @@ enum E_COMPARISON_FUNC
}; };
//! Enum values for enabling/disabling color planes for rendering //! Enum values for enabling/disabling color planes for rendering
enum E_COLOR_PLANE enum E_COLOR_PLANE : u8
{ {
//! No color enabled //! No color enabled
ECP_NONE = 0, ECP_NONE = 0,
@ -103,7 +103,7 @@ enum E_COLOR_PLANE
//! Source of the alpha value to take //! Source of the alpha value to take
/** This is currently only supported in EMT_ONETEXTURE_BLEND. You can use an /** This is currently only supported in EMT_ONETEXTURE_BLEND. You can use an
or'ed combination of values. Alpha values are modulated (multiplied). */ or'ed combination of values. Alpha values are modulated (multiplied). */
enum E_ALPHA_SOURCE enum E_ALPHA_SOURCE : u8
{ {
//! Use no alpha, somewhat redundant with other settings //! Use no alpha, somewhat redundant with other settings
EAS_NONE = 0, EAS_NONE = 0,
@ -181,7 +181,7 @@ Some drivers don't support a per-material setting of the anti-aliasing
modes. In those cases, FSAA/multisampling is defined by the device mode modes. In those cases, FSAA/multisampling is defined by the device mode
chosen upon creation via irr::SIrrCreationParameters. chosen upon creation via irr::SIrrCreationParameters.
*/ */
enum E_ANTI_ALIASING_MODE enum E_ANTI_ALIASING_MODE : u8
{ {
//! Use to turn off anti-aliasing for this material //! Use to turn off anti-aliasing for this material
EAAM_OFF = 0, EAAM_OFF = 0,
@ -202,7 +202,7 @@ const c8 *const PolygonOffsetDirectionNames[] = {
}; };
//! For SMaterial.ZWriteEnable //! For SMaterial.ZWriteEnable
enum E_ZWRITE enum E_ZWRITE : u8
{ {
//! zwrite always disabled for this material //! zwrite always disabled for this material
EZW_OFF = 0, EZW_OFF = 0,
@ -240,10 +240,10 @@ public:
//! Default constructor. Creates a solid material //! Default constructor. Creates a solid material
SMaterial() : SMaterial() :
MaterialType(EMT_SOLID), ColorParam(0, 0, 0, 0), MaterialType(EMT_SOLID), ColorParam(0, 0, 0, 0),
MaterialTypeParam(0.0f), Thickness(1.0f), ZBuffer(ECFN_LESSEQUAL), MaterialTypeParam(0.0f), Thickness(1.0f), BlendFactor(0.0f),
AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL), PolygonOffsetDepthBias(0.f), PolygonOffsetSlopeScale(0.f),
BlendOperation(EBO_NONE), BlendFactor(0.0f), PolygonOffsetDepthBias(0.f), ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL),
PolygonOffsetSlopeScale(0.f), Wireframe(false), PointCloud(false), BlendOperation(EBO_NONE), Wireframe(false), PointCloud(false),
ZWriteEnable(EZW_AUTO), ZWriteEnable(EZW_AUTO),
BackfaceCulling(true), FrontfaceCulling(false), FogEnable(false), BackfaceCulling(true), FrontfaceCulling(false), FogEnable(false),
UseMipMaps(true) UseMipMaps(true)
@ -268,28 +268,6 @@ public:
//! Thickness of non-3dimensional elements such as lines and points. //! Thickness of non-3dimensional elements such as lines and points.
f32 Thickness; f32 Thickness;
//! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
/** If you want to disable depth test for this material
just set this parameter to ECFN_DISABLED.
Values are from E_COMPARISON_FUNC. */
u8 ZBuffer;
//! Sets the antialiasing mode
/** Values are chosen from E_ANTI_ALIASING_MODE. Default is
EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
u8 AntiAliasing;
//! Defines the enabled color planes
/** Values are defined as or'ed values of the E_COLOR_PLANE enum.
Only enabled color planes will be rendered to the current render
target. Typical use is to disable all colors when rendering only to
depth or stencil buffer, or using Red and Green for Stereo rendering. */
u8 ColorMask : 4;
//! Store the blend operation of choice
/** Values to be chosen from E_BLEND_OPERATION. */
E_BLEND_OPERATION BlendOperation : 4;
//! Store the blend factors //! Store the blend factors
/** textureBlendFunc/textureBlendFuncSeparate functions should be used to write /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
properly blending factors to this parameter. properly blending factors to this parameter.
@ -316,6 +294,25 @@ public:
and -1.f to pull them towards the camera. */ and -1.f to pull them towards the camera. */
f32 PolygonOffsetSlopeScale; f32 PolygonOffsetSlopeScale;
//! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
/** If you want to disable depth test for this material
just set this parameter to ECFN_DISABLED. */
E_COMPARISON_FUNC ZBuffer : 4;
//! Sets the antialiasing mode
/** Default is EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
E_ANTI_ALIASING_MODE AntiAliasing : 4;
//! Defines the enabled color planes
/** Values are defined as or'ed values of the E_COLOR_PLANE enum.
Only enabled color planes will be rendered to the current render
target. Typical use is to disable all colors when rendering only to
depth or stencil buffer, or using Red and Green for Stereo rendering. */
E_COLOR_PLANE ColorMask : 4;
//! Store the blend operation of choice
E_BLEND_OPERATION BlendOperation : 4;
//! Draw as wireframe or filled triangles? Default: false //! Draw as wireframe or filled triangles? Default: false
bool Wireframe : 1; bool Wireframe : 1;

View file

@ -45,7 +45,7 @@ static const char *const aTextureClampNames[] = {
//! Texture minification filter. //! Texture minification filter.
/** Used when scaling textures down. See the documentation on OpenGL's /** Used when scaling textures down. See the documentation on OpenGL's
`GL_TEXTURE_MIN_FILTER` for more information. */ `GL_TEXTURE_MIN_FILTER` for more information. */
enum E_TEXTURE_MIN_FILTER enum E_TEXTURE_MIN_FILTER : u8
{ {
//! Aka nearest-neighbor. //! Aka nearest-neighbor.
ETMINF_NEAREST_MIPMAP_NEAREST = 0, ETMINF_NEAREST_MIPMAP_NEAREST = 0,
@ -61,7 +61,7 @@ enum E_TEXTURE_MIN_FILTER
/** Used when scaling textures up. See the documentation on OpenGL's /** Used when scaling textures up. See the documentation on OpenGL's
`GL_TEXTURE_MAG_FILTER` for more information. `GL_TEXTURE_MAG_FILTER` for more information.
Note that mipmaps are only used for minification, not for magnification. */ Note that mipmaps are only used for minification, not for magnification. */
enum E_TEXTURE_MAG_FILTER enum E_TEXTURE_MAG_FILTER : u8
{ {
//! Aka nearest-neighbor. //! Aka nearest-neighbor.
ETMAGF_NEAREST = 0, ETMAGF_NEAREST = 0,

View file

@ -253,7 +253,7 @@ void CAnimatedMeshSceneNode::render()
// for debug purposes only: // for debug purposes only:
if (DebugDataVisible && PassCount == 1) { if (DebugDataVisible && PassCount == 1) {
video::SMaterial debug_mat; video::SMaterial debug_mat;
debug_mat.AntiAliasing = 0; debug_mat.AntiAliasing = video::EAAM_OFF;
driver->setMaterial(debug_mat); driver->setMaterial(debug_mat);
// show normals // show normals
if (DebugDataVisible & scene::EDS_NORMALS) { if (DebugDataVisible & scene::EDS_NORMALS) {

View file

@ -109,7 +109,7 @@ void CMeshSceneNode::render()
// for debug purposes only: // for debug purposes only:
if (DebugDataVisible && PassCount == 1) { if (DebugDataVisible && PassCount == 1) {
video::SMaterial m; video::SMaterial m;
m.AntiAliasing = 0; m.AntiAliasing = video::EAAM_OFF;
m.ZBuffer = video::ECFN_DISABLED; m.ZBuffer = video::ECFN_DISABLED;
driver->setMaterial(m); driver->setMaterial(m);

View file

@ -1311,7 +1311,7 @@ void CNullDriver::runOcclusionQuery(scene::ISceneNode *node, bool visible)
OcclusionQueries[index].Run = 0; OcclusionQueries[index].Run = 0;
if (!visible) { if (!visible) {
SMaterial mat; SMaterial mat;
mat.AntiAliasing = 0; mat.AntiAliasing = video::EAAM_OFF;
mat.ColorMask = ECP_NONE; mat.ColorMask = ECP_NONE;
mat.ZWriteEnable = EZW_OFF; mat.ZWriteEnable = EZW_OFF;
setMaterial(mat); setMaterial(mat);

View file

@ -18,7 +18,7 @@ void SetColorMaskStep::run(PipelineContext &context)
{ {
video::SOverrideMaterial &mat = context.device->getVideoDriver()->getOverrideMaterial(); video::SOverrideMaterial &mat = context.device->getVideoDriver()->getOverrideMaterial();
mat.reset(); mat.reset();
mat.Material.ColorMask = color_mask; mat.Material.ColorMask = static_cast<video::E_COLOR_PLANE>(color_mask);
mat.EnableProps = video::EMP_COLOR_MASK; mat.EnableProps = video::EMP_COLOR_MASK;
mat.EnablePasses = scene::ESNRP_SKY_BOX | scene::ESNRP_SOLID | mat.EnablePasses = scene::ESNRP_SKY_BOX | scene::ESNRP_SOLID |
scene::ESNRP_TRANSPARENT | scene::ESNRP_TRANSPARENT_EFFECT; scene::ESNRP_TRANSPARENT | scene::ESNRP_TRANSPARENT_EFFECT;

View file

@ -21,7 +21,7 @@ PostProcessingStep::PostProcessingStep(u32 _shader_id, const std::vector<u8> &_t
void PostProcessingStep::configureMaterial() void PostProcessingStep::configureMaterial()
{ {
material.UseMipMaps = false; material.UseMipMaps = false;
material.ZBuffer = true; material.ZBuffer = video::ECFN_LESSEQUAL;
material.ZWriteEnable = video::EZW_ON; material.ZWriteEnable = video::EZW_ON;
for (u32 k = 0; k < texture_map.size(); ++k) { for (u32 k = 0; k < texture_map.size(); ++k) {
material.TextureLayers[k].AnisotropicFilter = 0; material.TextureLayers[k].AnisotropicFilter = 0;

View file

@ -27,7 +27,7 @@ static video::SMaterial baseMaterial()
video::SMaterial mat; video::SMaterial mat;
mat.ZBuffer = video::ECFN_DISABLED; mat.ZBuffer = video::ECFN_DISABLED;
mat.ZWriteEnable = video::EZW_OFF; mat.ZWriteEnable = video::EZW_OFF;
mat.AntiAliasing = 0; mat.AntiAliasing = video::EAAM_OFF;
mat.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; mat.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
mat.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; mat.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
mat.BackfaceCulling = false; mat.BackfaceCulling = false;