1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_MATERIAL_LAYER_H_INCLUDED__
\r
6 #define __S_MATERIAL_LAYER_H_INCLUDED__
\r
16 //! Texture coord clamp mode outside [0.0, 1.0]
\r
17 enum E_TEXTURE_CLAMP
\r
21 //! Texture is clamped to the last pixel
\r
23 //! Texture is clamped to the edge pixel
\r
25 //! Texture is clamped to the border pixel (if exists)
\r
26 ETC_CLAMP_TO_BORDER,
\r
27 //! Texture is alternatingly mirrored (0..1..0..1..0..)
\r
29 //! Texture is mirrored once and then clamped (0..1..0)
\r
31 //! Texture is mirrored once and then clamped to edge
\r
32 ETC_MIRROR_CLAMP_TO_EDGE,
\r
33 //! Texture is mirrored once and then clamped to border
\r
34 ETC_MIRROR_CLAMP_TO_BORDER
\r
36 static const char* const aTextureClampNames[] = {
\r
37 "texture_clamp_repeat",
\r
38 "texture_clamp_clamp",
\r
39 "texture_clamp_clamp_to_edge",
\r
40 "texture_clamp_clamp_to_border",
\r
41 "texture_clamp_mirror",
\r
42 "texture_clamp_mirror_clamp",
\r
43 "texture_clamp_mirror_clamp_to_edge",
\r
44 "texture_clamp_mirror_clamp_to_border", 0};
\r
46 //! Struct for holding material parameters which exist per texture layer
\r
47 // Note for implementors: Serialization is in CNullDriver
\r
48 class SMaterialLayer
\r
51 //! Default constructor
\r
52 SMaterialLayer() : Texture(0), TextureWrapU(ETC_REPEAT), TextureWrapV(ETC_REPEAT), TextureWrapW(ETC_REPEAT),
\r
53 BilinearFilter(true), TrilinearFilter(false), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
\r
57 //! Copy constructor
\r
58 /** \param other Material layer to copy from. */
\r
59 SMaterialLayer(const SMaterialLayer& other)
\r
61 // This pointer is checked during assignment
\r
69 if ( TextureMatrix )
\r
71 delete TextureMatrix;
\r
75 //! Assignment operator
\r
76 /** \param other Material layer to copy from.
\r
77 \return This material layer, updated. */
\r
78 SMaterialLayer& operator=(const SMaterialLayer& other)
\r
80 // Check for self-assignment!
\r
84 Texture = other.Texture;
\r
87 if (other.TextureMatrix)
\r
88 *TextureMatrix = *other.TextureMatrix;
\r
91 delete TextureMatrix;
\r
97 if (other.TextureMatrix)
\r
99 TextureMatrix = new core::matrix4(*other.TextureMatrix);
\r
104 TextureWrapU = other.TextureWrapU;
\r
105 TextureWrapV = other.TextureWrapV;
\r
106 TextureWrapW = other.TextureWrapW;
\r
107 BilinearFilter = other.BilinearFilter;
\r
108 TrilinearFilter = other.TrilinearFilter;
\r
109 AnisotropicFilter = other.AnisotropicFilter;
\r
110 LODBias = other.LODBias;
\r
115 //! Gets the texture transformation matrix
\r
116 /** \return Texture matrix of this layer. */
\r
117 core::matrix4& getTextureMatrix()
\r
119 if (!TextureMatrix)
\r
121 TextureMatrix = new core::matrix4();
\r
123 return *TextureMatrix;
\r
126 //! Gets the immutable texture transformation matrix
\r
127 /** \return Texture matrix of this layer. */
\r
128 const core::matrix4& getTextureMatrix() const
\r
131 return *TextureMatrix;
\r
133 return core::IdentityMatrix;
\r
136 //! Sets the texture transformation matrix to mat
\r
137 /** NOTE: Pipelines can ignore this matrix when the
\r
139 \param mat New texture matrix for this layer. */
\r
140 void setTextureMatrix(const core::matrix4& mat)
\r
142 if (!TextureMatrix)
\r
144 TextureMatrix = new core::matrix4(mat);
\r
147 *TextureMatrix = mat;
\r
150 //! Inequality operator
\r
151 /** \param b Layer to compare to.
\r
152 \return True if layers are different, else false. */
\r
153 inline bool operator!=(const SMaterialLayer& b) const
\r
156 Texture != b.Texture ||
\r
157 TextureWrapU != b.TextureWrapU ||
\r
158 TextureWrapV != b.TextureWrapV ||
\r
159 TextureWrapW != b.TextureWrapW ||
\r
160 BilinearFilter != b.BilinearFilter ||
\r
161 TrilinearFilter != b.TrilinearFilter ||
\r
162 AnisotropicFilter != b.AnisotropicFilter ||
\r
163 LODBias != b.LODBias;
\r
167 different |= (TextureMatrix != b.TextureMatrix) &&
\r
168 (!TextureMatrix || !b.TextureMatrix || (*TextureMatrix != *(b.TextureMatrix)));
\r
172 //! Equality operator
\r
173 /** \param b Layer to compare to.
\r
174 \return True if layers are equal, else false. */
\r
175 inline bool operator==(const SMaterialLayer& b) const
\r
176 { return !(b!=*this); }
\r
181 //! Texture Clamp Mode
\r
182 /** Values are taken from E_TEXTURE_CLAMP. */
\r
187 //! Is bilinear filtering enabled? Default: true
\r
188 bool BilinearFilter:1;
\r
190 //! Is trilinear filtering enabled? Default: false
\r
191 /** If the trilinear filter flag is enabled,
\r
192 the bilinear filtering flag is ignored. */
\r
193 bool TrilinearFilter:1;
\r
195 //! Is anisotropic filtering enabled? Default: 0, disabled
\r
196 /** In Irrlicht you can use anisotropic texture filtering
\r
197 in conjunction with bilinear or trilinear texture
\r
198 filtering to improve rendering results. Primitives
\r
199 will look less blurry with this flag switched on. The number gives
\r
200 the maximal anisotropy degree, and is often in the range 2-16.
\r
201 Value 1 is equivalent to 0, but should be avoided. */
\r
202 u8 AnisotropicFilter;
\r
204 //! Bias for the mipmap choosing decision.
\r
205 /** This value can make the textures more or less blurry than with the
\r
206 default value of 0. The value (divided by 8.f) is added to the mipmap level
\r
207 chosen initially, and thus takes a smaller mipmap for a region
\r
208 if the value is positive. */
\r
212 friend class SMaterial;
\r
215 /** Do not access this element directly as the internal
\r
216 resource management has to cope with Null pointers etc. */
\r
217 core::matrix4* TextureMatrix;
\r
220 } // end namespace video
\r
221 } // end namespace irr
\r
223 #endif // __S_MATERIAL_LAYER_H_INCLUDED__
\r