]> git.lizzy.rs Git - irrlicht.git/blob - include/SMaterialLayer.h
Bump revision
[irrlicht.git] / include / SMaterialLayer.h
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
4 \r
5 #ifndef __S_MATERIAL_LAYER_H_INCLUDED__\r
6 #define __S_MATERIAL_LAYER_H_INCLUDED__\r
7 \r
8 #include "matrix4.h"\r
9 \r
10 namespace irr\r
11 {\r
12 namespace video\r
13 {\r
14         class ITexture;\r
15 \r
16         //! Texture coord clamp mode outside [0.0, 1.0]\r
17         enum E_TEXTURE_CLAMP\r
18         {\r
19                 //! Texture repeats\r
20                 ETC_REPEAT = 0,\r
21                 //! Texture is clamped to the last pixel\r
22                 ETC_CLAMP,\r
23                 //! Texture is clamped to the edge pixel\r
24                 ETC_CLAMP_TO_EDGE,\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
28                 ETC_MIRROR,\r
29                 //! Texture is mirrored once and then clamped (0..1..0)\r
30                 ETC_MIRROR_CLAMP,\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
35         };\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
45 \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
49         {\r
50         public:\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
54                 {\r
55                 }\r
56 \r
57                 //! Copy constructor\r
58                 /** \param other Material layer to copy from. */\r
59                 SMaterialLayer(const SMaterialLayer& other)\r
60                 {\r
61                         // This pointer is checked during assignment\r
62                         TextureMatrix = 0;\r
63                         *this = other;\r
64                 }\r
65 \r
66                 //! Destructor\r
67                 ~SMaterialLayer()\r
68                 {\r
69                         if ( TextureMatrix )\r
70                         {\r
71                                 delete TextureMatrix;\r
72                         }\r
73                 }\r
74 \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
79                 {\r
80                         // Check for self-assignment!\r
81                         if (this == &other)\r
82                                 return *this;\r
83 \r
84                         Texture = other.Texture;\r
85                         if (TextureMatrix)\r
86                         {\r
87                                 if (other.TextureMatrix)\r
88                                         *TextureMatrix = *other.TextureMatrix;\r
89                                 else\r
90                                 {\r
91                                         delete TextureMatrix;\r
92                                         TextureMatrix = 0;\r
93                                 }\r
94                         }\r
95                         else\r
96                         {\r
97                                 if (other.TextureMatrix)\r
98                                 {\r
99                                         TextureMatrix = new core::matrix4(*other.TextureMatrix);\r
100                                 }\r
101                                 else\r
102                                         TextureMatrix = 0;\r
103                         }\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
111 \r
112                         return *this;\r
113                 }\r
114 \r
115                 //! Gets the texture transformation matrix\r
116                 /** \return Texture matrix of this layer. */\r
117                 core::matrix4& getTextureMatrix()\r
118                 {\r
119                         if (!TextureMatrix)\r
120                         {\r
121                                 TextureMatrix = new core::matrix4();\r
122                         }\r
123                         return *TextureMatrix;\r
124                 }\r
125 \r
126                 //! Gets the immutable texture transformation matrix\r
127                 /** \return Texture matrix of this layer. */\r
128                 const core::matrix4& getTextureMatrix() const\r
129                 {\r
130                         if (TextureMatrix)\r
131                                 return *TextureMatrix;\r
132                         else\r
133                                 return core::IdentityMatrix;\r
134                 }\r
135 \r
136                 //! Sets the texture transformation matrix to mat\r
137                 /** NOTE: Pipelines can ignore this matrix when the \r
138                 texture is 0.\r
139                 \param mat New texture matrix for this layer. */\r
140                 void setTextureMatrix(const core::matrix4& mat)\r
141                 {\r
142                         if (!TextureMatrix)\r
143                         {\r
144                                 TextureMatrix = new core::matrix4(mat);\r
145                         }\r
146                         else\r
147                                 *TextureMatrix = mat;\r
148                 }\r
149 \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
154                 {\r
155                         bool different =\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
164                         if (different)\r
165                                 return true;\r
166                         else\r
167                                 different |= (TextureMatrix != b.TextureMatrix) &&\r
168                                         (!TextureMatrix || !b.TextureMatrix || (*TextureMatrix != *(b.TextureMatrix)));\r
169                         return different;\r
170                 }\r
171 \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
177 \r
178                 //! Texture\r
179                 ITexture* Texture;\r
180 \r
181                 //! Texture Clamp Mode\r
182                 /** Values are taken from E_TEXTURE_CLAMP. */\r
183                 u8 TextureWrapU:4;\r
184                 u8 TextureWrapV:4;\r
185                 u8 TextureWrapW:4;\r
186 \r
187                 //! Is bilinear filtering enabled? Default: true\r
188                 bool BilinearFilter:1;\r
189 \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
194 \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
203 \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
209                 s8 LODBias;\r
210 \r
211         private:\r
212                 friend class SMaterial;\r
213 \r
214                 //! Texture Matrix\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
218         };\r
219 \r
220 } // end namespace video\r
221 } // end namespace irr\r
222 \r
223 #endif // __S_MATERIAL_LAYER_H_INCLUDED__\r