Remove obsolete and unnecessary animated and double buffered values from material
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / material-impl.h
1 #ifndef DALI_INTERNAL_MATERIAL_H
2 #define DALI_INTERNAL_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 <dali/public-api/common/vector-wrapper.h> // std::vector
23
24 // INTERNAL INCLUDES
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
35
36 namespace Dali
37 {
38 namespace Internal
39 {
40 namespace SceneGraph
41 {
42 class Material;
43 }
44
45
46 class Material;
47 typedef IntrusivePtr<Material> MaterialPtr;
48
49 /**
50  * Material is an object that connects a Shader with Samplers and can be used
51  * to shade a Geometry.
52  */
53 class Material : public Object, public Connectable
54 {
55 public:
56
57   /**
58    * @copydoc Dali::Material::New()
59    */
60   static MaterialPtr New();
61
62   /**
63    * @copydoc Dali::Material::SetShader()
64    */
65   void SetShader( Shader& shader );
66
67   /**
68    * @copydoc Dali::Material::GetShader()
69    */
70   Shader* GetShader() const;
71
72   /**
73    * @copydoc Dali::Material::AddTexture()
74    */
75   size_t AddTexture( ImagePtr image, const std::string& uniformName, SamplerPtr sampler );
76
77   /**
78    * @copydoc Dali::Material::RemoveTexture()
79    */
80   void RemoveTexture( size_t index );
81
82   /**
83    * @copydoc Dali::Material::SetTextureImage()
84    */
85   void SetTextureImage( size_t index, Image* image );
86
87   /**
88    * @copydoc Dali::Material::SetTextureSampler()
89    */
90   void SetTextureSampler( size_t index, Sampler* sampler );
91
92   /**
93    * @copydoc Dali::Material::SetTextureUniformName()
94    */
95   void SetTextureUniformName( size_t index, const std::string& uniformName );
96
97   /**
98    * @copydoc Dali::Material::GetTextureIndex()
99    */
100   int GetTextureIndex( const std::string& uniformName );
101
102   /**
103    * @copydoc Dali::Material::SetTextureAffectsTransparency()
104    */
105   void SetTextureAffectsTransparency( size_t index, bool affectsTransparency );
106
107   /**
108    * @copydoc Dali::Material::GetNumberOfTextures()
109    */
110   size_t GetNumberOfTextures() const;
111
112   /**
113    * @copydoc Dali::Material::SetFaceCullingMode()
114    */
115   void SetFaceCullingMode( Dali::Material::FaceCullingMode cullingMode );
116
117   /**
118    * @copydoc Dali::Material::GetFaceCullingMode()
119    */
120   Dali::Material::FaceCullingMode GetFaceCullingMode();
121
122   /**
123    * @copydoc Dali::Material::SetBlendMode()
124    */
125   void SetBlendMode( BlendingMode::Type mode );
126
127   /**
128    * @copydoc Dali::Material::GetBlendMode()
129    */
130   BlendingMode::Type GetBlendMode() const;
131
132   /**
133    * @copydoc Dali::Material::SetBlendFunc()
134    */
135   void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
136
137   /**
138    * @copydoc Dali::Material::SetBlendFunc()
139    */
140   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
141                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
142
143   /**
144    * @copydoc Dali::Material::GetBlendFunc()
145    */
146   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
147                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
148
149   /**
150    * @copydoc Dali::Material::SetBlendEquation()
151    */
152   void SetBlendEquation( BlendingEquation::Type equationRgba );
153
154   /**
155    * @copydoc Dali::Material::SetBlendEquation()
156    */
157   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
158
159   /**
160    * @copydoc Dali::Material::GetBlendEquation()
161    */
162   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
163
164   /**
165    * @copydoc Dali::Material::SetBlendColor()
166    */
167   void SetBlendColor( const Vector4& color );
168
169   /**
170    * @copydoc Dali::Material::GetBlendColor()
171    */
172   Vector4 GetBlendColor() const;
173
174   /**
175    * @brief Get the material scene object
176    *
177    * @return the material scene object
178    */
179   const SceneGraph::Material* GetMaterialSceneObject() const;
180
181 public: // Default property extensions from Object
182
183   /**
184    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
185    */
186   virtual unsigned int GetDefaultPropertyCount() const;
187
188   /**
189    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
190    */
191   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
192
193   /**
194    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
195    */
196   virtual const char* GetDefaultPropertyName(Property::Index index) const;
197
198   /**
199    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
200    */
201   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
202
203   /**
204    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
205    */
206   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
207
208   /**
209    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
210    */
211   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
212
213   /**
214    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
215    */
216   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
217
218   /**
219    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
220    */
221   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
222
223   /**
224    * @copydoc Dali::Internal::Object::SetDefaultProperty()
225    */
226   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
227
228   /**
229    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
230    */
231   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
232
233   /**
234    * @copydoc Dali::Internal::Object::GetDefaultProperty()
235    */
236   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
237
238   /**
239    * @copydoc Dali::Internal::Object::GetPropertyOwner()
240    */
241   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
242
243   /**
244    * @copydoc Dali::Internal::Object::GetSceneObject()
245    */
246   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
247
248   /**
249    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
250    */
251   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
252
253   /**
254    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
255    */
256   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
257
258   /**
259    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
260    */
261   virtual int GetPropertyComponentIndex( Property::Index index ) const;
262
263 public: // Functions from Connectable
264   /**
265    * @copydoc Dali::Internal::Connectable::OnStage()
266    */
267   virtual bool OnStage() const;
268
269   /**
270    * @copydoc Dali::Internal::Connectable::Connect()
271    */
272   virtual void Connect();
273
274   /**
275    * @copydoc Dali::Internal::Connectable::Disconnect()
276    */
277   virtual void Disconnect();
278
279 private: // implementation
280
281   struct Texture
282   {
283     Texture()
284     :mUniformName(""),
285      mImage(NULL),
286      mSampler( NULL )
287     {}
288
289     Texture( const std::string& name, ImagePtr image, SamplerPtr sampler )
290     :mUniformName(name),
291      mImage( image ),
292      mSampler( sampler )
293     {}
294
295     std::string mUniformName;
296     ImagePtr    mImage;
297     SamplerPtr  mSampler;
298   };
299
300   Material();
301
302   /**
303    * Second stage initialization
304    */
305   void Initialize();
306
307 protected:
308   /**
309    * A reference counted object may only be deleted by calling Unreference()
310    */
311   virtual ~Material();
312
313 private: // unimplemented methods
314   Material( const Material& );
315   Material& operator=( const Material& );
316
317 private: // Data
318
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
322
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 reraly used
327   bool mOnStage;
328
329 };
330
331 } // namespace Internal
332
333 // Helpers for public-api forwarding methods
334 inline Internal::Material& GetImplementation( Dali::Material& handle )
335 {
336   DALI_ASSERT_ALWAYS(handle && "Material handle is empty");
337
338   BaseObject& object = handle.GetBaseObject();
339
340   return static_cast<Internal::Material&>(object);
341 }
342
343 inline const Internal::Material& GetImplementation( const Dali::Material& handle )
344 {
345   DALI_ASSERT_ALWAYS(handle && "Material handle is empty");
346
347   const BaseObject& object = handle.GetBaseObject();
348
349   return static_cast<const Internal::Material&>(object);
350 }
351
352 } // namespace Dali
353
354 #endif // DALI_INTERNAL_MATERIAL_H