1 #ifndef DALI_MATERIAL_H
2 #define DALI_MATERIAL_H
5 * Copyright (c) 2015 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 <cstddef> // std::size_t
23 #include <string> // std::string
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
34 namespace Internal DALI_INTERNAL
40 * @brief Material is a handle to an object that specifies the visual properties of the renderer.
42 class DALI_IMPORT_API Material : public Handle
47 * @brief Creates a new Material object
49 * @return A handle to a newly allocated Material
51 static Material New( Shader shader );
54 * @brief Default constructor, creates an empty handle
64 * @brief Copy constructor, creates a new handle to the same object
66 * @param[in] handle Handle to an object
68 Material( const Material& handle );
71 * @brief Downcast to a material handle.
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
77 static Material DownCast( BaseHandle handle );
80 * @brief Assignment operator, changes this handle to point at the same object
82 * @param[in] handle Handle to an object
84 Material& operator=( const Material& handle );
87 * @brief Sets the Shader used by this material
89 * @param[in] shader Handle to a shader
91 void SetShader( Shader& shader );
94 * @brief Gets the shader used by this material
96 * @return The shader used by the material
98 Shader GetShader() const;
101 * @brief Add a new texture to be used by the material
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
108 int AddTexture( Image image, const std::string& uniformName, Sampler sampler = Sampler() );
111 * @brief Removes a texture from the material
113 * @param[in] index The index of the texture in the array of textures
115 void RemoveTexture( size_t index );
118 * @brief Sets the image to be used by a given texture
120 * @param[in] index The index of the texture in the array of textures
121 * @param[in] image The new image
123 void SetTextureImage( size_t index, Image image );
126 * @brief Set the sampler used by a given texture
128 * @param[in] index The index of the texture in the array of textures
129 * @param[in] sampler The new sampler
131 void SetTextureSampler( size_t index, Sampler sampler );
134 * @brief Retrieve the sampler of a texture given its texture index
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
139 Sampler GetTextureSampler( size_t index ) const;
142 * @brief Set the uniform name of a given texture
144 * @param[in] index The index of the texture in the array of textures
145 * @param[in] uniformName The new uniform name
147 void SetTextureUniformName( size_t index, const std::string& uniformName );
150 * @brief Retrive the index of a texture given its uniform name
152 * @param[in] uniformName the uniform name
153 * @returns The index in the array of textures or -1 if the texture is not found
155 int GetTextureIndex( const std::string& uniformName ) const;
158 * @brief Retrive the texture given its uniform name
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
163 Image GetTexture( const std::string& uniformName ) const;
166 * @brief Retrive the texture given its index
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
171 Image GetTexture( size_t index ) const;
174 * @brief Retrieve the number of textures used by the material
176 std::size_t GetNumberOfTextures() const;
180 * @brief The constructor
182 * @param [in] pointer A pointer to a newly allocated Material
184 explicit DALI_INTERNAL Material( Internal::Material* pointer );
191 #endif // DALI_MATERIAL_H