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
15 //! Texture coord clamp mode outside [0.0, 1.0]
20 //! Texture is clamped to the last pixel
22 //! Texture is clamped to the edge pixel
24 //! Texture is clamped to the border pixel (if exists)
26 //! Texture is alternatingly mirrored (0..1..0..1..0..)
28 //! Texture is mirrored once and then clamped (0..1..0)
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,
53 ETMINF_LINEAR_MIPMAP_NEAREST
,
54 //! Isn't known by any other name.
55 ETMINF_NEAREST_MIPMAP_LINEAR
,
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.
72 //! Struct for holding material parameters which exist per texture layer
73 // Note for implementors: Serialization is in CNullDriver
77 //! Default constructor
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)
85 /** \param other Material layer to copy from. */
86 SMaterialLayer(const SMaterialLayer
&other
)
88 // This pointer is checked during assignment
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!
110 Texture
= other
.Texture
;
112 if (other
.TextureMatrix
)
113 *TextureMatrix
= *other
.TextureMatrix
;
115 delete TextureMatrix
;
119 if (other
.TextureMatrix
) {
120 TextureMatrix
= new core::matrix4(*other
.TextureMatrix
);
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
;
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
150 return *TextureMatrix
;
152 return core::IdentityMatrix
;
155 //! Sets the texture transformation matrix to mat
156 /** NOTE: Pipelines can ignore this matrix when the
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
);
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
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
;
184 different
|= (TextureMatrix
!= b
.TextureMatrix
) &&
185 (!TextureMatrix
|| !b
.TextureMatrix
|| (*TextureMatrix
!= *(b
.TextureMatrix
)));
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);
200 //! Texture Clamp Mode
201 /** Values are taken from E_TEXTURE_CLAMP. */
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. */
229 friend class SMaterial
;
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