Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / devel-api / rendering / material.h
1 #ifndef DALI_MATERIAL_H
2 #define DALI_MATERIAL_H
3
4 /*
5  * Copyright (c) 2015 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 // EXTERNAL INCLUDES
22 #include <cstddef> // std::size_t
23 #include <string> // std::string
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/images/image.h> // Dali::Image
27 #include <dali/public-api/object/handle.h> // Dali::Handle
28 #include <dali/devel-api/rendering/sampler.h> // Dali::Sampler
29 #include <dali/devel-api/rendering/shader.h> // Dali::Shader
30
31 namespace Dali
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class Material;
37 }
38
39 /**
40  * @brief Material is a handle to an object that specifies the visual properties of the renderer.
41  */
42 class DALI_IMPORT_API Material : public Handle
43 {
44 public:
45
46   /**
47    * @brief Creates a new Material object
48    *
49    * @return A handle to a newly allocated Material
50    */
51   static Material New( Shader shader );
52
53   /**
54    * @brief Default constructor, creates an empty handle
55    */
56   Material();
57
58   /**
59    * @brief Destructor
60    */
61   ~Material();
62
63   /**
64    * @brief Copy constructor, creates a new handle to the same object
65    *
66    * @param[in] handle Handle to an object
67    */
68   Material( const Material& handle );
69
70   /**
71    * @brief Downcast to a material handle.
72    *
73    * If handle is not a material, the returned handle is left uninitialized.
74    * @param[in] handle to an object
75    * @return material handle or an uninitialized handle
76    */
77   static Material DownCast( BaseHandle handle );
78
79   /**
80    * @brief Assignment operator, changes this handle to point at the same object
81    *
82    * @param[in] handle Handle to an object
83    */
84   Material& operator=( const Material& handle );
85
86   /**
87    * @brief Sets the Shader used by this material
88    *
89    * @param[in] shader Handle to a shader
90    */
91   void SetShader( Shader& shader );
92
93   /**
94    * @brief Gets the shader used by this material
95    *
96    * @return The shader used by the material
97    */
98   Shader GetShader() const;
99
100   /**
101    * @brief Add a new texture to be used by the material
102    *
103    * @param[in] image The image used by the texture
104    * @param[in] uniformName The uniform name of the texture
105    * @param[in] sampler Sampling parameters. If not provided the default sampling parameters will be used
106    * @return The index of the texture in the array of textures or -1 if texture can not be added
107    */
108   int AddTexture( Image image, const std::string& uniformName, Sampler sampler = Sampler() );
109
110   /**
111    * @brief Removes a texture from the material
112    *
113    * @param[in] index The index of the texture in the array of textures
114    */
115   void RemoveTexture( size_t  index );
116
117   /**
118    * @brief Sets the image to be used by a given texture
119    *
120    * @param[in] index The index of the texture in the array of textures
121    * @param[in] image The new image
122    */
123   void SetTextureImage( size_t index, Image image );
124
125   /**
126    * @brief Set the sampler used by a given texture
127    *
128    * @param[in] index The index of the texture in the array of textures
129    * @param[in] sampler The new sampler
130    */
131   void SetTextureSampler( size_t index, Sampler sampler );
132
133   /**
134    * @brief Retrieve the sampler of a texture given its texture index
135    *
136    * @param[in] index The index of the texture in the array of textures
137    * @return Returns the sampler of a texture given its texture index
138    */
139   Sampler GetTextureSampler( size_t index ) const;
140
141   /**
142    * @brief Set the uniform name of a given texture
143    *
144    * @param[in] index The index of the texture in the array of textures
145    * @param[in] uniformName The new uniform name
146    */
147   void SetTextureUniformName( size_t index, const std::string& uniformName );
148
149   /**
150    * @brief Retrive the index of a texture given its uniform name
151    *
152    * @param[in] uniformName the uniform name
153    * @returns The index in the array of textures or -1 if the texture is not found
154    */
155   int GetTextureIndex( const std::string& uniformName ) const;
156
157   /**
158    * @brief Retrive the texture given its uniform name
159    *
160    * @param[in] uniformName the uniform name
161    * @returns The image in the array of textures corresponding to the uniformName or an empty handle if the texture is not found
162    */
163   Image GetTexture( const std::string& uniformName ) const;
164
165   /**
166    * @brief Retrive the texture given its index
167    *
168    * @param[in] index The index in the array of textures
169    * @returns The image in the array of textures corresponding to the index or an empty handle if the texture is not found
170    */
171   Image GetTexture( size_t index ) const;
172
173   /**
174    * @brief Retrieve the number of textures used by the material
175    */
176   std::size_t GetNumberOfTextures() const;
177
178 public:
179   /**
180    * @brief The constructor
181    *
182    * @param [in] pointer A pointer to a newly allocated Material
183    */
184   explicit DALI_INTERNAL Material( Internal::Material* pointer );
185 };
186
187 } //namespace Dali
188
189
190
191 #endif // DALI_MATERIAL_H