Use openssl's sha1 and sha256, optionally (#15472)
[minetest.git] / irr / include / SMaterialLayer.h
blob419a8f1e96cb0035ccee8fba0f3e23bfdeb380a8
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
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 "matrix4.h"
9 namespace irr
11 namespace video
13 class ITexture;
15 //! Texture coord clamp mode outside [0.0, 1.0]
16 enum E_TEXTURE_CLAMP
18 //! Texture repeats
19 ETC_REPEAT = 0,
20 //! Texture is clamped to the last pixel
21 ETC_CLAMP,
22 //! Texture is clamped to the edge pixel
23 ETC_CLAMP_TO_EDGE,
24 //! Texture is clamped to the border pixel (if exists)
25 ETC_CLAMP_TO_BORDER,
26 //! Texture is alternatingly mirrored (0..1..0..1..0..)
27 ETC_MIRROR,
28 //! Texture is mirrored once and then clamped (0..1..0)
29 ETC_MIRROR_CLAMP,
30 //! Texture is mirrored once and then clamped to edge
31 ETC_MIRROR_CLAMP_TO_EDGE,
32 //! Texture is mirrored once and then clamped to border
33 ETC_MIRROR_CLAMP_TO_BORDER
35 static const char *const aTextureClampNames[] = {
36 "texture_clamp_repeat",
37 "texture_clamp_clamp",
38 "texture_clamp_clamp_to_edge",
39 "texture_clamp_clamp_to_border",
40 "texture_clamp_mirror",
41 "texture_clamp_mirror_clamp",
42 "texture_clamp_mirror_clamp_to_edge",
43 "texture_clamp_mirror_clamp_to_border", 0};
45 //! Texture minification filter.
46 /** Used when scaling textures down. See the documentation on OpenGL's
47 `GL_TEXTURE_MIN_FILTER` for more information. */
48 enum E_TEXTURE_MIN_FILTER
50 //! Aka nearest-neighbor.
51 ETMINF_NEAREST_MIPMAP_NEAREST = 0,
52 //! Aka bilinear.
53 ETMINF_LINEAR_MIPMAP_NEAREST,
54 //! Isn't known by any other name.
55 ETMINF_NEAREST_MIPMAP_LINEAR,
56 //! Aka trilinear.
57 ETMINF_LINEAR_MIPMAP_LINEAR,
60 //! Texture magnification filter.
61 /** Used when scaling textures up. See the documentation on OpenGL's
62 `GL_TEXTURE_MAG_FILTER` for more information.
63 Note that mipmaps are only used for minification, not for magnification. */
64 enum E_TEXTURE_MAG_FILTER
66 //! Aka nearest-neighbor.
67 ETMAGF_NEAREST = 0,
68 //! Aka bilinear.
69 ETMAGF_LINEAR,
72 //! Struct for holding material parameters which exist per texture layer
73 // Note for implementors: Serialization is in CNullDriver
74 class SMaterialLayer
76 public:
77 //! Default constructor
78 SMaterialLayer() :
79 Texture(0), TextureWrapU(ETC_REPEAT), TextureWrapV(ETC_REPEAT), TextureWrapW(ETC_REPEAT),
80 MinFilter(ETMINF_LINEAR_MIPMAP_NEAREST), MagFilter(ETMAGF_LINEAR), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
84 //! Copy constructor
85 /** \param other Material layer to copy from. */
86 SMaterialLayer(const SMaterialLayer &other)
88 // This pointer is checked during assignment
89 TextureMatrix = 0;
90 *this = other;
93 //! Destructor
94 ~SMaterialLayer()
96 if (TextureMatrix) {
97 delete TextureMatrix;
101 //! Assignment operator
102 /** \param other Material layer to copy from.
103 \return This material layer, updated. */
104 SMaterialLayer &operator=(const SMaterialLayer &other)
106 // Check for self-assignment!
107 if (this == &other)
108 return *this;
110 Texture = other.Texture;
111 if (TextureMatrix) {
112 if (other.TextureMatrix)
113 *TextureMatrix = *other.TextureMatrix;
114 else {
115 delete TextureMatrix;
116 TextureMatrix = 0;
118 } else {
119 if (other.TextureMatrix) {
120 TextureMatrix = new core::matrix4(*other.TextureMatrix);
121 } else
122 TextureMatrix = 0;
124 TextureWrapU = other.TextureWrapU;
125 TextureWrapV = other.TextureWrapV;
126 TextureWrapW = other.TextureWrapW;
127 MinFilter = other.MinFilter;
128 MagFilter = other.MagFilter;
129 AnisotropicFilter = other.AnisotropicFilter;
130 LODBias = other.LODBias;
132 return *this;
135 //! Gets the texture transformation matrix
136 /** \return Texture matrix of this layer. */
137 core::matrix4 &getTextureMatrix()
139 if (!TextureMatrix) {
140 TextureMatrix = new core::matrix4();
142 return *TextureMatrix;
145 //! Gets the immutable texture transformation matrix
146 /** \return Texture matrix of this layer. */
147 const core::matrix4 &getTextureMatrix() const
149 if (TextureMatrix)
150 return *TextureMatrix;
151 else
152 return core::IdentityMatrix;
155 //! Sets the texture transformation matrix to mat
156 /** NOTE: Pipelines can ignore this matrix when the
157 texture is 0.
158 \param mat New texture matrix for this layer. */
159 void setTextureMatrix(const core::matrix4 &mat)
161 if (!TextureMatrix) {
162 TextureMatrix = new core::matrix4(mat);
163 } else
164 *TextureMatrix = mat;
167 //! Inequality operator
168 /** \param b Layer to compare to.
169 \return True if layers are different, else false. */
170 inline bool operator!=(const SMaterialLayer &b) const
172 bool different =
173 Texture != b.Texture ||
174 TextureWrapU != b.TextureWrapU ||
175 TextureWrapV != b.TextureWrapV ||
176 TextureWrapW != b.TextureWrapW ||
177 MinFilter != b.MinFilter ||
178 MagFilter != b.MagFilter ||
179 AnisotropicFilter != b.AnisotropicFilter ||
180 LODBias != b.LODBias;
181 if (different)
182 return true;
183 else
184 different |= (TextureMatrix != b.TextureMatrix) &&
185 (!TextureMatrix || !b.TextureMatrix || (*TextureMatrix != *(b.TextureMatrix)));
186 return different;
189 //! Equality operator
190 /** \param b Layer to compare to.
191 \return True if layers are equal, else false. */
192 inline bool operator==(const SMaterialLayer &b) const
194 return !(b != *this);
197 //! Texture
198 ITexture *Texture;
200 //! Texture Clamp Mode
201 /** Values are taken from E_TEXTURE_CLAMP. */
202 u8 TextureWrapU : 4;
203 u8 TextureWrapV : 4;
204 u8 TextureWrapW : 4;
206 //! Minification (downscaling) filter
207 E_TEXTURE_MIN_FILTER MinFilter;
209 //! Magnification (upscaling) filter
210 E_TEXTURE_MAG_FILTER MagFilter;
212 //! Is anisotropic filtering enabled? Default: 0, disabled
213 /** In Irrlicht you can use anisotropic texture filtering
214 in conjunction with bilinear or trilinear texture
215 filtering to improve rendering results. Primitives
216 will look less blurry with this flag switched on. The number gives
217 the maximal anisotropy degree, and is often in the range 2-16.
218 Value 1 is equivalent to 0, but should be avoided. */
219 u8 AnisotropicFilter;
221 //! Bias for the mipmap choosing decision.
222 /** This value can make the textures more or less blurry than with the
223 default value of 0. The value (divided by 8.f) is added to the mipmap level
224 chosen initially, and thus takes a smaller mipmap for a region
225 if the value is positive. */
226 s8 LODBias;
228 private:
229 friend class SMaterial;
231 //! Texture Matrix
232 /** Do not access this element directly as the internal
233 resource management has to cope with Null pointers etc. */
234 core::matrix4 *TextureMatrix;
237 } // end namespace video
238 } // end namespace irr