Move SMaterial std::hash impl to its header
[minetest.git] / irr / include / SOverrideMaterial.h
blob1ae324211f359b17d2e01d93f654bbc170142a96
1 // Copyright (C) 2017 Michael Zeilfelder
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
5 #pragma once
7 #include <vector>
8 #include "SMaterial.h"
10 namespace irr
12 namespace video
15 struct SOverrideMaterial
17 //! The Material values
18 SMaterial Material;
20 //! Which values are overridden
21 /** OR'ed values from E_MATERIAL_PROPS. */
22 u32 EnableProps;
24 //! For those properties in EnableProps which affect layers, set which of the layers are affected
25 bool EnableLayerProps[MATERIAL_MAX_TEXTURES];
27 //! Which textures are overridden
28 bool EnableTextures[MATERIAL_MAX_TEXTURES];
30 //! Overwrite complete layers (settings of EnableLayerProps and EnableTextures don't matter then for layer data)
31 bool EnableLayers[MATERIAL_MAX_TEXTURES];
33 //! Set in which render passes the material override is active.
34 /** OR'ed values from E_SCENE_NODE_RENDER_PASS. */
35 u16 EnablePasses;
37 //! Global enable flag, overwritten by the SceneManager in each pass
38 /** NOTE: This is generally _not_ set by users of the engine, but the
39 Scenemanager uses the EnablePass array and sets Enabled to true if the
40 Override material is enabled in the current pass.
41 As user you generally _only_ set EnablePasses.
42 The exception is when rendering without SceneManager but using draw calls in the VideoDriver. */
43 bool Enabled;
45 struct SMaterialTypeReplacement
47 SMaterialTypeReplacement(s32 original, u32 replacement) :
48 Original(original), Replacement(replacement) {}
49 SMaterialTypeReplacement(u32 replacement) :
50 Original(-1), Replacement(replacement) {}
52 //! SMaterial.MaterialType to replace.
53 //! -1 for all types or a specific value to only replace that one (which is either one of E_MATERIAL_TYPE or a shader material id)
54 s32 Original;
56 //! MaterialType to used to override Original (either one of E_MATERIAL_TYPE or a shader material id)
57 u32 Replacement;
60 //! To overwrite SMaterial::MaterialType
61 std::vector<SMaterialTypeReplacement> MaterialTypes;
63 //! Default constructor
64 SOverrideMaterial() :
65 EnableProps(0), EnablePasses(0), Enabled(false)
69 //! disable overrides and reset all properties
70 void reset()
72 EnableProps = 0;
73 EnablePasses = 0;
74 Enabled = false;
75 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
76 EnableLayerProps[i] = true; // doesn't do anything unless EnableProps is set, just saying by default all texture layers are affected by properties
77 EnableTextures[i] = false;
78 EnableLayers[i] = false;
80 MaterialTypes.clear();
83 //! Apply the enabled overrides
84 void apply(SMaterial &material)
86 if (Enabled) {
87 for (const auto &mtr : MaterialTypes) {
88 if (mtr.Original < 0 || mtr.Original == (s32)material.MaterialType)
89 material.MaterialType = (E_MATERIAL_TYPE)mtr.Replacement;
91 for (u32 f = 0; f < 32; ++f) {
92 const u32 num = (1 << f);
93 if (EnableProps & num) {
94 switch (num) {
95 case EMP_WIREFRAME:
96 material.Wireframe = Material.Wireframe;
97 break;
98 case EMP_POINTCLOUD:
99 material.PointCloud = Material.PointCloud;
100 break;
101 case EMP_ZBUFFER:
102 material.ZBuffer = Material.ZBuffer;
103 break;
104 case EMP_ZWRITE_ENABLE:
105 material.ZWriteEnable = Material.ZWriteEnable;
106 break;
107 case EMP_BACK_FACE_CULLING:
108 material.BackfaceCulling = Material.BackfaceCulling;
109 break;
110 case EMP_FRONT_FACE_CULLING:
111 material.FrontfaceCulling = Material.FrontfaceCulling;
112 break;
113 case EMP_MIN_FILTER:
114 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
115 if (EnableLayerProps[i]) {
116 material.TextureLayers[i].MinFilter = Material.TextureLayers[i].MinFilter;
119 break;
120 case EMP_MAG_FILTER:
121 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
122 if (EnableLayerProps[i]) {
123 material.TextureLayers[i].MagFilter = Material.TextureLayers[i].MagFilter;
126 break;
127 case EMP_ANISOTROPIC_FILTER:
128 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
129 if (EnableLayerProps[i]) {
130 material.TextureLayers[i].AnisotropicFilter = Material.TextureLayers[i].AnisotropicFilter;
133 break;
134 case EMP_FOG_ENABLE:
135 material.FogEnable = Material.FogEnable;
136 break;
137 case EMP_TEXTURE_WRAP:
138 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
139 if (EnableLayerProps[i]) {
140 material.TextureLayers[i].TextureWrapU = Material.TextureLayers[i].TextureWrapU;
141 material.TextureLayers[i].TextureWrapV = Material.TextureLayers[i].TextureWrapV;
142 material.TextureLayers[i].TextureWrapW = Material.TextureLayers[i].TextureWrapW;
145 break;
146 case EMP_ANTI_ALIASING:
147 material.AntiAliasing = Material.AntiAliasing;
148 break;
149 case EMP_COLOR_MASK:
150 material.ColorMask = Material.ColorMask;
151 break;
152 case EMP_USE_MIP_MAPS:
153 material.UseMipMaps = Material.UseMipMaps;
154 break;
155 case EMP_BLEND_OPERATION:
156 material.BlendOperation = Material.BlendOperation;
157 break;
158 case EMP_BLEND_FACTOR:
159 material.BlendFactor = Material.BlendFactor;
160 break;
161 case EMP_POLYGON_OFFSET:
162 material.PolygonOffsetDepthBias = Material.PolygonOffsetDepthBias;
163 material.PolygonOffsetSlopeScale = Material.PolygonOffsetSlopeScale;
164 break;
168 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
169 if (EnableLayers[i]) {
170 material.TextureLayers[i] = Material.TextureLayers[i];
171 } else if (EnableTextures[i]) {
172 material.TextureLayers[i].Texture = Material.TextureLayers[i].Texture;
179 } // end namespace video
180 } // end namespace irr