]> git.lizzy.rs Git - irrlicht.git/blob - include/SMaterialLayer.h
Replace HWBufferMap with a list and back pointers (#99)
[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 #include "irrAllocator.h"\r
10 \r
11 namespace irr\r
12 {\r
13 namespace video\r
14 {\r
15         class ITexture;\r
16 \r
17         //! Texture coord clamp mode outside [0.0, 1.0]\r
18         enum E_TEXTURE_CLAMP\r
19         {\r
20                 //! Texture repeats\r
21                 ETC_REPEAT = 0,\r
22                 //! Texture is clamped to the last pixel\r
23                 ETC_CLAMP,\r
24                 //! Texture is clamped to the edge pixel\r
25                 ETC_CLAMP_TO_EDGE,\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
29                 ETC_MIRROR,\r
30                 //! Texture is mirrored once and then clamped (0..1..0)\r
31                 ETC_MIRROR_CLAMP,\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
36         };\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
46 \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
50         {\r
51         public:\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
55                 {\r
56                 }\r
57 \r
58                 //! Copy constructor\r
59                 /** \param other Material layer to copy from. */\r
60                 SMaterialLayer(const SMaterialLayer& other)\r
61                 {\r
62                         // This pointer is checked during assignment\r
63                         TextureMatrix = 0;\r
64                         *this = other;\r
65                 }\r
66 \r
67                 //! Destructor\r
68                 ~SMaterialLayer()\r
69                 {\r
70                         if ( TextureMatrix )\r
71                         {\r
72                                 MatrixAllocator.destruct(TextureMatrix);\r
73                                 MatrixAllocator.deallocate(TextureMatrix);\r
74                         }\r
75                 }\r
76 \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
81                 {\r
82                         // Check for self-assignment!\r
83                         if (this == &other)\r
84                                 return *this;\r
85 \r
86                         Texture = other.Texture;\r
87                         if (TextureMatrix)\r
88                         {\r
89                                 if (other.TextureMatrix)\r
90                                         *TextureMatrix = *other.TextureMatrix;\r
91                                 else\r
92                                 {\r
93                                         MatrixAllocator.destruct(TextureMatrix);\r
94                                         MatrixAllocator.deallocate(TextureMatrix);\r
95                                         TextureMatrix = 0;\r
96                                 }\r
97                         }\r
98                         else\r
99                         {\r
100                                 if (other.TextureMatrix)\r
101                                 {\r
102                                         TextureMatrix = MatrixAllocator.allocate(1);\r
103                                         MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);\r
104                                 }\r
105                                 else\r
106                                         TextureMatrix = 0;\r
107                         }\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
115 \r
116                         return *this;\r
117                 }\r
118 \r
119                 //! Gets the texture transformation matrix\r
120                 /** \return Texture matrix of this layer. */\r
121                 core::matrix4& getTextureMatrix()\r
122                 {\r
123                         if (!TextureMatrix)\r
124                         {\r
125                                 TextureMatrix = MatrixAllocator.allocate(1);\r
126                                 MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);\r
127                         }\r
128                         return *TextureMatrix;\r
129                 }\r
130 \r
131                 //! Gets the immutable texture transformation matrix\r
132                 /** \return Texture matrix of this layer. */\r
133                 const core::matrix4& getTextureMatrix() const\r
134                 {\r
135                         if (TextureMatrix)\r
136                                 return *TextureMatrix;\r
137                         else\r
138                                 return core::IdentityMatrix;\r
139                 }\r
140 \r
141                 //! Sets the texture transformation matrix to mat\r
142                 /** NOTE: Pipelines can ignore this matrix when the \r
143                 texture is 0.\r
144                 \param mat New texture matrix for this layer. */\r
145                 void setTextureMatrix(const core::matrix4& mat)\r
146                 {\r
147                         if (!TextureMatrix)\r
148                         {\r
149                                 TextureMatrix = MatrixAllocator.allocate(1);\r
150                                 MatrixAllocator.construct(TextureMatrix,mat);\r
151                         }\r
152                         else\r
153                                 *TextureMatrix = mat;\r
154                 }\r
155 \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
160                 {\r
161                         bool different =\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
170                         if (different)\r
171                                 return true;\r
172                         else\r
173                                 different |= (TextureMatrix != b.TextureMatrix) &&\r
174                                         (!TextureMatrix || !b.TextureMatrix || (*TextureMatrix != *(b.TextureMatrix)));\r
175                         return different;\r
176                 }\r
177 \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
183 \r
184                 //! Texture\r
185                 ITexture* Texture;\r
186 \r
187                 //! Texture Clamp Mode\r
188                 /** Values are taken from E_TEXTURE_CLAMP. */\r
189                 u8 TextureWrapU:4;\r
190                 u8 TextureWrapV:4;\r
191                 u8 TextureWrapW:4;\r
192 \r
193                 //! Is bilinear filtering enabled? Default: true\r
194                 bool BilinearFilter:1;\r
195 \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
200 \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
209 \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
215                 s8 LODBias;\r
216 \r
217         private:\r
218                 friend class SMaterial;\r
219                 irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;\r
220 \r
221                 //! Texture Matrix\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
225         };\r
226 \r
227 } // end namespace video\r
228 } // end namespace irr\r
229 \r
230 #endif // __S_MATERIAL_LAYER_H_INCLUDED__\r