DALi signals refactor to remove V2 naming
[platform/core/uifw/dali-core.git] / dali / public-api / modeling / material.h
1 #ifndef __DALI_MATERIAL_H__
2 #define __DALI_MATERIAL_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/common/constants.h>
24
25 namespace Dali
26 {
27
28 struct Vector4;
29
30 namespace Internal DALI_INTERNAL
31 {
32 class Material;
33 }
34
35
36 class Material;
37 typedef std::vector<Material>             MaterialContainer; ///< Container for Dali::Material
38 typedef MaterialContainer::iterator       MaterialIter;      ///< Iterator for Dali::MaterialContainer
39 typedef MaterialContainer::const_iterator MaterialConstIter; ///< Const iterator for Dali::MaterialContainer
40
41 /**
42  * @brief Encapsulates the data describing a material.
43  *
44  * Color, opacity, shininess, shading mode, texture/normal/height mapping...
45  */
46 class DALI_IMPORT_API Material : public BaseHandle
47 {
48 public:
49   /**
50    * @brief How the material's texture is sampled outside the range 0..1
51    */
52   enum MappingMode
53   {
54     MAPPING_MODE_WRAP   = 0x0,            ///< A texture coordinate u|v is translated to u%1|v%1
55     MAPPING_MODE_CLAMP  = 0x1,            ///< Texture coordinates outside [0...1] are clamped to the nearest valid value
56     MAPPING_MODE_MIRROR = 0x2,            ///< A texture coordinate u|v becomes u%1|v%1 if (u-(u%1))%2 is zero and 1-(u%1)|1-(v%1) otherwise
57     MAPPING_MODE_DECAL  = 0x3,            ///< If the texture coordinates for a pixel are outside [0...1] the texture is not applied to that pixel
58   };
59
60   static const float        DEFAULT_OPACITY;          ///< 1.0f
61   static const float        DEFAULT_SHININESS;        ///< 0.5f
62   static const Vector4      DEFAULT_AMBIENT_COLOR;    ///< (0.2f, 0.2f, 0.2f, 1.0f)
63   static const Vector4      DEFAULT_DIFFUSE_COLOR;    ///< (0.8f, 0.8f, 0.8f, 1.0f)
64   static const Vector4      DEFAULT_SPECULAR_COLOR;   ///< (0.0f, 0.0f, 0.0f, 1.0f)
65   static const Vector4      DEFAULT_EMISSIVE_COLOR;   ///< (0.0f, 0.0f, 0.0f, 1.0f)
66   static const MappingMode  DEFAULT_MAPPING_MODE;     ///< Material::MAPPING_MODE_WRAP
67   static const size_t       DEFAULT_DIFFUSE_UV_INDEX; ///< 0
68   static const size_t       DEFAULT_OPACITY_UV_INDEX; ///< 0
69   static const size_t       DEFAULT_NORMAL_UV_INDEX;  ///< 0
70   static const bool         DEFAULT_HAS_HEIGHT_MAP;   ///< false
71
72   /**
73    * @brief Create an initialized Material.
74    *
75    * @param[in] name The material's name
76    * @return A handle to a newly allocated Dali resource.
77    */
78   static Material New(const std::string& name);
79
80   /**
81    * @brief Downcast an Object handle to Material handle.
82    *
83    * If handle points to a Material object the
84    * downcast produces valid handle. If not the returned handle is left uninitialized.
85    * @param[in] handle to An object
86    * @return handle to a Material object or an uninitialized handle
87    */
88   static Material DownCast( BaseHandle handle );
89
90   /**
91    * @brief Create an uninitialized material; this can be initialized with Material::New().
92    *
93    * Calling member functions with an uninitialized Dali::Object is not allowed.
94    */
95   Material();
96
97   /**
98    * @brief Destructor
99    *
100    * This is non-virtual since derived Handle types must not contain data or virtual methods.
101    */
102   ~Material();
103
104   /**
105    * @brief This copy constructor is required for (smart) pointer semantics.
106    *
107    * @param [in] handle A reference to the copied handle
108    */
109   Material(const Material& handle);
110
111   /**
112    * @brief This assignment operator is required for (smart) pointer semantics.
113    *
114    * @param [in] rhs  A reference to the copied handle
115    * @return A reference to this
116    */
117   Material& operator=(const Material& rhs);
118
119   /**
120    * @brief Set the material's name.
121    *
122    * @param[in] name The material's name
123    */
124   void SetName(const std::string& name);
125
126   /**
127    * @brief Get the material's name.
128    */
129   const std::string& GetName() const;
130
131   /**
132    * @brief Set the material's opacity.
133    *
134    * @param[in] opacity The new opacity value
135    */
136   void SetOpacity(const float opacity);
137
138   /**
139    * @brief Get the material's opacity.
140    *
141    * @return The opacity.
142    */
143   float GetOpacity() const;
144
145   /**
146    * @brief Set the material's shininess (used for specular highlighting).
147    *
148    * @param[in] shininess The new shininess value
149    */
150   void SetShininess(const float shininess);
151
152   /**
153    * @brief Get the material's shininess.
154    *
155    * @return The shininess.
156    */
157   float GetShininess() const;
158
159   /**
160    * @brief Set the material's ambient color.
161    *
162    * @param[in] color The new color value
163    */
164   void SetAmbientColor(const Vector4& color);
165
166   /**
167    * @brief Get the material's ambient color.
168    *
169    * @return The color value
170    */
171   const Vector4& GetAmbientColor() const;
172
173   /**
174    * @brief Set the material's diffuse color.
175    *
176    * @param[in] color The new color value
177    */
178   void SetDiffuseColor(const Vector4& color);
179
180   /**
181    * @brief Get the material's diffuse color.
182    *
183    * @return The color value
184    */
185   const Vector4& GetDiffuseColor() const;
186
187   /**
188    * @brief Set the material's specular color.
189    *
190    * @param[in] color The new color value
191    */
192   void SetSpecularColor(const Vector4& color);
193
194   /**
195    * @brief Get the material's specular color.
196    *
197    * @return The color value
198    */
199   const Vector4& GetSpecularColor() const;
200
201   /**
202    * @brief Set the material's emissive color.
203    *
204    * @param[in] color The new color value
205    */
206   void SetEmissiveColor(const Vector4& color);
207
208   /**
209    * @brief Get the material's emissive color.
210    *
211    * @return The color value
212    */
213   const Vector4& GetEmissiveColor() const;
214
215   /**
216    * @brief Set the diffuse texture image.
217    *
218    * @param[in] image The new texture image
219    */
220   void SetDiffuseTexture(Image image);
221
222   /**
223    * @brief Set the diffuse texture image.
224    *
225    * @param[in] filename The name of the image file
226    */
227   void SetDiffuseTextureFileName(const std::string filename);
228
229   /**
230    * @brief Get the diffuse texture image.
231    *
232    * @return The texture image
233    */
234   Image GetDiffuseTexture() const;
235
236   /**
237    * @brief Get the diffuse texture image filename.
238    *
239    * @return the filename
240    */
241   const std::string& GetDiffuseFileName() const;
242
243   /**
244    * @brief Set the opacity texture image.
245    *
246    * @param[in] image The new texture image
247    */
248   void SetOpacityTexture(Image image);
249
250   /**
251    * @brief Set the opacity texture image.
252    *
253    * @param[in] filename The opacity texture image filename
254    */
255   void SetOpacityTextureFileName(const std::string filename);
256
257   /**
258    * @brief Get the opacity texture image.
259    *
260    * @return The texture image
261    */
262   Image GetOpacityTexture() const;
263
264   /**
265    * @brief Get the opacity texture image filename.
266    *
267    * @return The texture image's filename
268    */
269   const std::string& GetOpacityTextureFileName() const;
270
271
272   /**
273    * @brief Set the normal/height map texture image.
274    *
275    * @param[in] image The new texture image
276    */
277   void SetNormalMap(Image image);
278
279   /**
280    * @brief Set the normal/height map texture image filename.
281    *
282    * @param[in] filename The new texture image filename
283    */
284   void SetNormalMapFileName(const std::string filename);
285
286   /**
287    * @brief Get the normal/height map texture image.
288    *
289    * @return The texture image
290    */
291   Image GetNormalMap() const;
292
293   /**
294    * @brief Get the normal/height map texture image filename.
295    *
296    * @return The texture image filename
297    */
298   const std::string& GetNormalMapFileName() const;
299
300   /**
301    * @brief Set the U mapping mode.
302    *
303    * @param[in] map The mapping mode
304    */
305   void SetMapU(const unsigned int map);
306
307   /**
308    * @brief Get the U mapping mode.
309    *
310    * @return The mapping mode
311    */
312   unsigned int GetMapU() const;
313
314   /**
315    * @brief Set the V mapping mode.
316    *
317    * @param[in] map The mapping mode
318    */
319   void SetMapV(const unsigned int map);
320
321   /**
322    * @brief Get the U mapping mode.
323    *
324    * @return The mapping mode
325    */
326   unsigned int GetMapV() const;
327
328   /**
329    * @brief Set the index into the bound mesh's array of UV's for the diffuse texture coordinates.
330    *
331    * @param[in] index The diffuse uv index
332    */
333   void SetDiffuseUVIndex(const int index);
334
335   /**
336    * @brief Get the index into the bound mesh's array of UV's for the diffuse texture coordinates.
337    *
338    * @return The uv index
339    */
340   unsigned int GetDiffuseUVIndex() const;
341
342   /**
343    * @brief Set the index into the bound mesh's array of UV's for the opacity texture coordinates.
344    *
345    * @param[in] index The opacity uv index
346    */
347   void SetOpacityUVIndex(const int index);
348
349   /**
350    * @brief Get the index into the bound mesh's array of UV's for the opacity texture coordinates.
351    *
352    * @return The uv index
353    */
354   unsigned int GetOpacityUVIndex() const;
355
356   /**
357    * @brief Set the index into the bound mesh's array of UV's for the normal/height map texture coordinates.
358    *
359    * @param[in] index The normal/height map uv index
360    */
361   void SetNormalUVIndex(const int index);
362
363   /**
364    * @brief Get the index into the bound mesh's array of UV's for the normal/height map texture coordinates.
365    *
366    * @return The uv index
367    */
368   unsigned int GetNormalUVIndex() const;
369
370   /**
371    * @brief Set whether the normal texture contains a normal or height map.
372    *
373    * @param[in] flag true if the normal map contains a height map
374    */
375   void SetHasHeightMap(const bool flag);
376
377   /**
378    * @brief Get whether the normal texture contains a normal or height map.
379    *
380    * @return true if the normal map contains a height map, false otherwise
381    */
382   bool GetHasHeightMap() const;
383
384 public: // Not intended for application developers
385
386   /**
387    * @brief This constructor is used by Dali New() methods.
388    *
389    * @param [in] material A pointer to an internal material resource
390    */
391   explicit DALI_INTERNAL Material(Internal::Material* material);
392 }; // class Material
393
394 } // namespace Dali
395
396 #endif // __DALI_MATERIAL_H__