1 #ifndef __DALI_MATERIAL_H__
2 #define __DALI_MATERIAL_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/common/constants.h>
30 namespace Internal DALI_INTERNAL
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
42 * @brief Encapsulates the data describing a material.
44 * Color, opacity, shininess, shading mode, texture/normal/height mapping...
46 class DALI_IMPORT_API Material : public BaseHandle
50 * @brief How the material's texture is sampled outside the range 0..1
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
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
73 * @brief Create an initialized Material.
75 * @param[in] name The material's name
76 * @return A handle to a newly allocated Dali resource.
78 static Material New(const std::string& name);
81 * @brief Downcast an Object handle to Material handle.
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
88 static Material DownCast( BaseHandle handle );
91 * @brief Create an uninitialized material; this can be initialized with Material::New().
93 * Calling member functions with an uninitialized Dali::Object is not allowed.
100 * This is non-virtual since derived Handle types must not contain data or virtual methods.
105 * @brief This copy constructor is required for (smart) pointer semantics.
107 * @param [in] handle A reference to the copied handle
109 Material(const Material& handle);
112 * @brief This assignment operator is required for (smart) pointer semantics.
114 * @param [in] rhs A reference to the copied handle
115 * @return A reference to this
117 Material& operator=(const Material& rhs);
120 * @brief Set the material's name.
122 * @param[in] name The material's name
124 void SetName(const std::string& name);
127 * @brief Get the material's name.
129 const std::string& GetName() const;
132 * @brief Set the material's opacity.
134 * @param[in] opacity The new opacity value
136 void SetOpacity(const float opacity);
139 * @brief Get the material's opacity.
141 * @return The opacity.
143 float GetOpacity() const;
146 * @brief Set the material's shininess (used for specular highlighting).
148 * @param[in] shininess The new shininess value
150 void SetShininess(const float shininess);
153 * @brief Get the material's shininess.
155 * @return The shininess.
157 float GetShininess() const;
160 * @brief Set the material's ambient color.
162 * @param[in] color The new color value
164 void SetAmbientColor(const Vector4& color);
167 * @brief Get the material's ambient color.
169 * @return The color value
171 const Vector4& GetAmbientColor() const;
174 * @brief Set the material's diffuse color.
176 * @param[in] color The new color value
178 void SetDiffuseColor(const Vector4& color);
181 * @brief Get the material's diffuse color.
183 * @return The color value
185 const Vector4& GetDiffuseColor() const;
188 * @brief Set the material's specular color.
190 * @param[in] color The new color value
192 void SetSpecularColor(const Vector4& color);
195 * @brief Get the material's specular color.
197 * @return The color value
199 const Vector4& GetSpecularColor() const;
202 * @brief Set the material's emissive color.
204 * @param[in] color The new color value
206 void SetEmissiveColor(const Vector4& color);
209 * @brief Get the material's emissive color.
211 * @return The color value
213 const Vector4& GetEmissiveColor() const;
216 * @brief Set the diffuse texture image.
218 * @param[in] image The new texture image
220 void SetDiffuseTexture(Image image);
223 * @brief Set the diffuse texture image.
225 * @param[in] filename The name of the image file
227 void SetDiffuseTextureFileName(const std::string filename);
230 * @brief Get the diffuse texture image.
232 * @return The texture image
234 Image GetDiffuseTexture() const;
237 * @brief Get the diffuse texture image filename.
239 * @return the filename
241 const std::string& GetDiffuseFileName() const;
244 * @brief Set the opacity texture image.
246 * @param[in] image The new texture image
248 void SetOpacityTexture(Image image);
251 * @brief Set the opacity texture image.
253 * @param[in] filename The opacity texture image filename
255 void SetOpacityTextureFileName(const std::string filename);
258 * @brief Get the opacity texture image.
260 * @return The texture image
262 Image GetOpacityTexture() const;
265 * @brief Get the opacity texture image filename.
267 * @return The texture image's filename
269 const std::string& GetOpacityTextureFileName() const;
273 * @brief Set the normal/height map texture image.
275 * @param[in] image The new texture image
277 void SetNormalMap(Image image);
280 * @brief Set the normal/height map texture image filename.
282 * @param[in] filename The new texture image filename
284 void SetNormalMapFileName(const std::string filename);
287 * @brief Get the normal/height map texture image.
289 * @return The texture image
291 Image GetNormalMap() const;
294 * @brief Get the normal/height map texture image filename.
296 * @return The texture image filename
298 const std::string& GetNormalMapFileName() const;
301 * @brief Set the U mapping mode.
303 * @param[in] map The mapping mode
305 void SetMapU(const unsigned int map);
308 * @brief Get the U mapping mode.
310 * @return The mapping mode
312 unsigned int GetMapU() const;
315 * @brief Set the V mapping mode.
317 * @param[in] map The mapping mode
319 void SetMapV(const unsigned int map);
322 * @brief Get the U mapping mode.
324 * @return The mapping mode
326 unsigned int GetMapV() const;
329 * @brief Set the index into the bound mesh's array of UV's for the diffuse texture coordinates.
331 * @param[in] index The diffuse uv index
333 void SetDiffuseUVIndex(const int index);
336 * @brief Get the index into the bound mesh's array of UV's for the diffuse texture coordinates.
338 * @return The uv index
340 unsigned int GetDiffuseUVIndex() const;
343 * @brief Set the index into the bound mesh's array of UV's for the opacity texture coordinates.
345 * @param[in] index The opacity uv index
347 void SetOpacityUVIndex(const int index);
350 * @brief Get the index into the bound mesh's array of UV's for the opacity texture coordinates.
352 * @return The uv index
354 unsigned int GetOpacityUVIndex() const;
357 * @brief Set the index into the bound mesh's array of UV's for the normal/height map texture coordinates.
359 * @param[in] index The normal/height map uv index
361 void SetNormalUVIndex(const int index);
364 * @brief Get the index into the bound mesh's array of UV's for the normal/height map texture coordinates.
366 * @return The uv index
368 unsigned int GetNormalUVIndex() const;
371 * @brief Set whether the normal texture contains a normal or height map.
373 * @param[in] flag true if the normal map contains a height map
375 void SetHasHeightMap(const bool flag);
378 * @brief Get whether the normal texture contains a normal or height map.
380 * @return true if the normal map contains a height map, false otherwise
382 bool GetHasHeightMap() const;
384 public: // Not intended for application developers
387 * @brief This constructor is used by Dali New() methods.
389 * @param [in] material A pointer to an internal material resource
391 explicit DALI_INTERNAL Material(Internal::Material* material);
396 #endif // __DALI_MATERIAL_H__