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
9 #include "irrAllocator.h"
\r
17 //! Texture coord clamp mode outside [0.0, 1.0]
\r
18 enum E_TEXTURE_CLAMP
\r
22 //! Texture is clamped to the last pixel
\r
24 //! Texture is clamped to the edge pixel
\r
26 //! Texture is clamped to the border pixel (if exists)
\r
27 ETC_CLAMP_TO_BORDER,
\r
28 //! Texture is alternatingly mirrored (0..1..0..1..0..)
\r
30 //! Texture is mirrored once and then clamped (0..1..0)
\r
32 //! Texture is mirrored once and then clamped to edge
\r
33 ETC_MIRROR_CLAMP_TO_EDGE,
\r
34 //! Texture is mirrored once and then clamped to border
\r
35 ETC_MIRROR_CLAMP_TO_BORDER
\r
37 static const char* const aTextureClampNames[] = {
\r
38 "texture_clamp_repeat",
\r
39 "texture_clamp_clamp",
\r
40 "texture_clamp_clamp_to_edge",
\r
41 "texture_clamp_clamp_to_border",
\r
42 "texture_clamp_mirror",
\r
43 "texture_clamp_mirror_clamp",
\r
44 "texture_clamp_mirror_clamp_to_edge",
\r
45 "texture_clamp_mirror_clamp_to_border", 0};
\r
47 //! Struct for holding material parameters which exist per texture layer
\r
48 // Note for implementors: Serialization is in CNullDriver
\r
49 class SMaterialLayer
\r
52 //! Default constructor
\r
53 SMaterialLayer() : Texture(0), TextureWrapU(ETC_REPEAT), TextureWrapV(ETC_REPEAT), TextureWrapW(ETC_REPEAT),
\r
54 BilinearFilter(true), TrilinearFilter(false), AnisotropicFilter(0), LODBias(0), TextureMatrix(0)
\r
58 //! Copy constructor
\r
59 /** \param other Material layer to copy from. */
\r
60 SMaterialLayer(const SMaterialLayer& other)
\r
62 // This pointer is checked during assignment
\r
70 if ( TextureMatrix )
\r
72 MatrixAllocator.destruct(TextureMatrix);
\r
73 MatrixAllocator.deallocate(TextureMatrix);
\r
77 //! Assignment operator
\r
78 /** \param other Material layer to copy from.
\r
79 \return This material layer, updated. */
\r
80 SMaterialLayer& operator=(const SMaterialLayer& other)
\r
82 // Check for self-assignment!
\r
86 Texture = other.Texture;
\r
89 if (other.TextureMatrix)
\r
90 *TextureMatrix = *other.TextureMatrix;
\r
93 MatrixAllocator.destruct(TextureMatrix);
\r
94 MatrixAllocator.deallocate(TextureMatrix);
\r
100 if (other.TextureMatrix)
\r
102 TextureMatrix = MatrixAllocator.allocate(1);
\r
103 MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
\r
108 TextureWrapU = other.TextureWrapU;
\r
109 TextureWrapV = other.TextureWrapV;
\r
110 TextureWrapW = other.TextureWrapW;
\r
111 BilinearFilter = other.BilinearFilter;
\r
112 TrilinearFilter = other.TrilinearFilter;
\r
113 AnisotropicFilter = other.AnisotropicFilter;
\r
114 LODBias = other.LODBias;
\r
119 //! Gets the texture transformation matrix
\r
120 /** \return Texture matrix of this layer. */
\r
121 core::matrix4& getTextureMatrix()
\r
123 if (!TextureMatrix)
\r
125 TextureMatrix = MatrixAllocator.allocate(1);
\r
126 MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
\r
128 return *TextureMatrix;
\r
131 //! Gets the immutable texture transformation matrix
\r
132 /** \return Texture matrix of this layer. */
\r
133 const core::matrix4& getTextureMatrix() const
\r
136 return *TextureMatrix;
\r
138 return core::IdentityMatrix;
\r
141 //! Sets the texture transformation matrix to mat
\r
142 /** NOTE: Pipelines can ignore this matrix when the
\r
144 \param mat New texture matrix for this layer. */
\r
145 void setTextureMatrix(const core::matrix4& mat)
\r
147 if (!TextureMatrix)
\r
149 TextureMatrix = MatrixAllocator.allocate(1);
\r
150 MatrixAllocator.construct(TextureMatrix,mat);
\r
153 *TextureMatrix = mat;
\r
156 //! Inequality operator
\r
157 /** \param b Layer to compare to.
\r
158 \return True if layers are different, else false. */
\r
159 inline bool operator!=(const SMaterialLayer& b) const
\r
162 Texture != b.Texture ||
\r
163 TextureWrapU != b.TextureWrapU ||
\r
164 TextureWrapV != b.TextureWrapV ||
\r
165 TextureWrapW != b.TextureWrapW ||
\r
166 BilinearFilter != b.BilinearFilter ||
\r
167 TrilinearFilter != b.TrilinearFilter ||
\r
168 AnisotropicFilter != b.AnisotropicFilter ||
\r
169 LODBias != b.LODBias;
\r
173 different |= (TextureMatrix != b.TextureMatrix) &&
\r
174 (!TextureMatrix || !b.TextureMatrix || (*TextureMatrix != *(b.TextureMatrix)));
\r
178 //! Equality operator
\r
179 /** \param b Layer to compare to.
\r
180 \return True if layers are equal, else false. */
\r
181 inline bool operator==(const SMaterialLayer& b) const
\r
182 { return !(b!=*this); }
\r
187 //! Texture Clamp Mode
\r
188 /** Values are taken from E_TEXTURE_CLAMP. */
\r
193 //! Is bilinear filtering enabled? Default: true
\r
194 bool BilinearFilter:1;
\r
196 //! Is trilinear filtering enabled? Default: false
\r
197 /** If the trilinear filter flag is enabled,
\r
198 the bilinear filtering flag is ignored. */
\r
199 bool TrilinearFilter:1;
\r
201 //! Is anisotropic filtering enabled? Default: 0, disabled
\r
202 /** In Irrlicht you can use anisotropic texture filtering
\r
203 in conjunction with bilinear or trilinear texture
\r
204 filtering to improve rendering results. Primitives
\r
205 will look less blurry with this flag switched on. The number gives
\r
206 the maximal anisotropy degree, and is often in the range 2-16.
\r
207 Value 1 is equivalent to 0, but should be avoided. */
\r
208 u8 AnisotropicFilter;
\r
210 //! Bias for the mipmap choosing decision.
\r
211 /** This value can make the textures more or less blurry than with the
\r
212 default value of 0. The value (divided by 8.f) is added to the mipmap level
\r
213 chosen initially, and thus takes a smaller mipmap for a region
\r
214 if the value is positive. */
\r
218 friend class SMaterial;
\r
219 irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;
\r
222 /** Do not access this element directly as the internal
\r
223 resource management has to cope with Null pointers etc. */
\r
224 core::matrix4* TextureMatrix;
\r
227 } // end namespace video
\r
228 } // end namespace irr
\r
230 #endif // __S_MATERIAL_LAYER_H_INCLUDED__
\r