1 #ifndef DALI_INTERNAL_MATERIAL_H
2 #define DALI_INTERNAL_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 <dali/public-api/common/vector-wrapper.h> // std::vector
25 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
27 #include <dali/devel-api/rendering/material.h> // Dali::Material
28 #include <dali/internal/common/blending-options.h>
29 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
30 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
31 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
32 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
33 #include <dali/internal/event/rendering/sampler-impl.h> // Dali::Internal::Sampler
34 #include <dali/internal/event/rendering/shader-impl.h> // Dali::Internal::Shader
47 typedef IntrusivePtr<Material> MaterialPtr;
50 * Material is an object that connects a Shader with Samplers and can be used
51 * to shade a Geometry.
53 class Material : public Object, public Connectable
58 * @copydoc Dali::Material::New()
60 static MaterialPtr New();
63 * @copydoc Dali::Material::SetShader()
65 void SetShader( Shader& shader );
68 * @copydoc Dali::Material::GetShader()
70 Shader* GetShader() const;
73 * @copydoc Dali::Material::AddTexture()
75 size_t AddTexture( ImagePtr image, const std::string& uniformName, SamplerPtr sampler );
78 * @copydoc Dali::Material::RemoveTexture()
80 void RemoveTexture( size_t index );
83 * @copydoc Dali::Material::SetTextureImage()
85 void SetTextureImage( size_t index, Image* image );
88 * @copydoc Dali::Material::SetTextureSampler()
90 void SetTextureSampler( size_t index, Sampler* sampler );
93 * @copydoc Dali::Material::SetTextureUniformName()
95 void SetTextureUniformName( size_t index, const std::string& uniformName );
98 * @copydoc Dali::Material::GetTextureIndex()
100 int GetTextureIndex( const std::string& uniformName );
103 * @copydoc Dali::Material::GetTextureIndex()
105 Image* GetTexture( const std::string& uniformName );
108 * @copydoc Dali::Material::GetNumberOfTextures()
110 size_t GetNumberOfTextures() const;
113 * @copydoc Dali::Material::SetFaceCullingMode()
115 void SetFaceCullingMode( Dali::Material::FaceCullingMode cullingMode );
118 * @copydoc Dali::Material::GetFaceCullingMode()
120 Dali::Material::FaceCullingMode GetFaceCullingMode();
123 * @copydoc Dali::Material::SetBlendMode()
125 void SetBlendMode( BlendingMode::Type mode );
128 * @copydoc Dali::Material::GetBlendMode()
130 BlendingMode::Type GetBlendMode() const;
133 * @copydoc Dali::Material::SetBlendFunc()
135 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
138 * @copydoc Dali::Material::SetBlendFunc()
140 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
141 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
144 * @copydoc Dali::Material::GetBlendFunc()
146 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
147 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
150 * @copydoc Dali::Material::SetBlendEquation()
152 void SetBlendEquation( BlendingEquation::Type equationRgba );
155 * @copydoc Dali::Material::SetBlendEquation()
157 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
160 * @copydoc Dali::Material::GetBlendEquation()
162 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
165 * @copydoc Dali::Material::SetBlendColor()
167 void SetBlendColor( const Vector4& color );
170 * @copydoc Dali::Material::GetBlendColor()
172 Vector4 GetBlendColor() const;
175 * @brief Get the material scene object
177 * @return the material scene object
179 const SceneGraph::Material* GetMaterialSceneObject() const;
181 public: // Default property extensions from Object
184 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
186 virtual unsigned int GetDefaultPropertyCount() const;
189 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
191 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
194 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
196 virtual const char* GetDefaultPropertyName(Property::Index index) const;
199 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
201 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
204 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
206 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
209 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
211 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
214 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
216 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
219 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
221 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
224 * @copydoc Dali::Internal::Object::SetDefaultProperty()
226 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
229 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
231 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
234 * @copydoc Dali::Internal::Object::GetDefaultProperty()
236 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
239 * @copydoc Dali::Internal::Object::GetPropertyOwner()
241 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
244 * @copydoc Dali::Internal::Object::GetSceneObject()
246 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
249 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
251 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
254 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
256 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
259 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
261 virtual int GetPropertyComponentIndex( Property::Index index ) const;
263 public: // Functions from Connectable
265 * @copydoc Dali::Internal::Connectable::OnStage()
267 virtual bool OnStage() const;
270 * @copydoc Dali::Internal::Connectable::Connect()
272 virtual void Connect();
275 * @copydoc Dali::Internal::Connectable::Disconnect()
277 virtual void Disconnect();
279 private: // implementation
289 Texture( const std::string& name, ImagePtr image, SamplerPtr sampler )
295 std::string mUniformName;
303 * Second stage initialization
309 * A reference counted object may only be deleted by calling Unreference()
313 private: // unimplemented methods
314 Material( const Material& );
315 Material& operator=( const Material& );
319 SceneGraph::Material* mSceneObject;
320 IntrusivePtr<Shader> mShader; ///< Connector that holds the shader used by this material
321 std::vector<Material::Texture> mTextures; ///<Vector of textures used by this material
323 Dali::Material::FaceCullingMode mFaceCullingMode; ///< Local copy of face culling mode
324 BlendingMode::Type mBlendingMode; ///< Local copy of blending mode
325 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
326 Vector4* mBlendColor; ///< Local copy of blend color, pointer only as its rarely used
331 } // namespace Internal
333 // Helpers for public-api forwarding methods
334 inline Internal::Material& GetImplementation( Dali::Material& handle )
336 DALI_ASSERT_ALWAYS(handle && "Material handle is empty");
338 BaseObject& object = handle.GetBaseObject();
340 return static_cast<Internal::Material&>(object);
343 inline const Internal::Material& GetImplementation( const Dali::Material& handle )
345 DALI_ASSERT_ALWAYS(handle && "Material handle is empty");
347 const BaseObject& object = handle.GetBaseObject();
349 return static_cast<const Internal::Material&>(object);
354 #endif // DALI_INTERNAL_MATERIAL_H