Remove RenderableActor
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-material.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H
2 #define DALI_INTERNAL_SCENE_GRAPH_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 #include <dali/public-api/actors/image-actor.h> // For CullFaceMode
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/blending-options.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/animatable-property.h>
25 #include <dali/internal/update/common/double-buffered-property.h>
26 #include <dali/internal/update/common/property-owner.h>
27 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
28 #include <dali/internal/update/common/uniform-map.h>
29 #include <dali/internal/render/data-providers/material-data-provider.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 namespace SceneGraph
36 {
37 class Sampler;
38 class Shader;
39 class ConnectionObserver;
40 class SceneController;
41
42 class Material : public PropertyOwner, public MaterialDataProvider, public UniformMap::Observer, public ConnectionChangePropagator::Observer
43 {
44 public:
45   /**
46    * This enum defines the outputs of the PrepareRender step, and is used
47    * by the Renderer to determine final opacity.
48    */
49   enum BlendPolicy
50   {
51     OPAQUE,          ///< If the renderer should always be opaque
52     TRANSPARENT,     ///< If the renderer should always be transparent
53     USE_ACTOR_COLOR  ///< If the renderer should determine opacity using the actor color
54   };
55
56   /**
57    * Constructor
58    */
59   Material();
60
61   /**
62    * Destructor
63    */
64   virtual ~Material();
65
66   /**
67    * Set the shader effect for this material
68    * @param[in] shader The shader effect to use
69    */
70   void SetShader( Shader* shader );
71
72   /**
73    * Add a sampler (image + sampler modes) to the material
74    * @param[in] sampler A sampler to add
75    */
76   void AddSampler( Sampler* sampler );
77
78   /**
79    * Remove a sampler (image + sampler modes) from the material
80    * @param[in] sampler A sampler to remove
81    */
82   void RemoveSampler( Sampler* sampler );
83
84   /**
85    * Prepare the material for rendering.
86    *
87    * Determine whether blending is enabled for this material, and store the result.
88    * @param[in] bufferIndex The current buffer index
89    */
90   void PrepareRender( BufferIndex bufferIndex );
91
92   /**
93    * Return the blend policy ( a combination of all the different shader hints, color, samper and image properties ).
94    * This should only be called from the update thread
95    * @return The material's blend policy
96    */
97   BlendPolicy GetBlendPolicy() const;
98
99   /**
100    * Set the blending options. This should only be called from the update thread.
101    * @param[in] updateBufferIndex The current update buffer index.
102    * @param[in] options A bitmask of blending options.
103    */
104   void SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options );
105
106 public: // Implementation of MaterialDataProvider
107
108   /**
109    * @copydoc MaterialDataProvider::GetBlendColor
110    */
111   virtual const Vector4& GetBlendColor(BufferIndex bufferIndex) const;
112
113   /**
114    * @copydoc MaterialDataProvider::GetBlendSrcFactorRgb
115    */
116   virtual BlendingFactor::Type GetBlendSrcFactorRgb(BufferIndex bufferIndex) const;
117
118   /**
119    * @copydoc MaterialDataProvider::GetBlendSrcFactorAlpha
120    */
121   virtual BlendingFactor::Type GetBlendSrcFactorAlpha( BufferIndex bufferIndex ) const;
122
123   /**
124    * @copydoc MaterialDataProvider::GetBlendDestFactorRgb
125    */
126   virtual BlendingFactor::Type GetBlendDestFactorRgb( BufferIndex bufferIndex ) const;
127
128   /**
129    * @copydoc MaterialDataProvider::GetBlendDestFactorAlpha
130    */
131   virtual BlendingFactor::Type GetBlendDestFactorAlpha( BufferIndex bufferIndex ) const;
132
133   /**
134    * @copydoc MaterialDataProvider::GetBlendEquationRgb
135    */
136   virtual BlendingEquation::Type GetBlendEquationRgb( BufferIndex bufferIndex ) const;
137
138   /**
139    * @copydoc MaterialDataProvider::GetBlendEquationAlpha
140    */
141   virtual BlendingEquation::Type GetBlendEquationAlpha( BufferIndex bufferIndex ) const;
142
143 public: // Implementation of ObjectOwnerContainer template methods
144   /**
145    * Connect the object to the scene graph
146    *
147    * @param[in] sceneController The scene controller - used for sending messages to render thread
148    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
149    */
150   void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
151
152   /**
153    * Disconnect the object from the scene graph
154    * @param[in] sceneController The scene controller - used for sending messages to render thread
155    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
156    */
157   void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
158
159 public: // Implementation of ConnectionChangePropagator
160   /**
161    * @copydoc ConnectionChangePropagator::AddObserver
162    */
163   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
164
165   /**
166    * @copydoc ConnectionChangePropagator::RemoveObserver
167    */
168   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
169
170 public:
171   /**
172    * Get the shader effect of this material
173    * @return the shader effect;
174    */
175   Shader* GetShader() const;
176
177   /**
178    * Get the samplers this material uses.
179    * @return the samplers
180    */
181   Vector<Sampler*>& GetSamplers();
182
183 public: // UniformMap::Observer
184   /**
185    * @copydoc UniformMap::Observer::UniformMappingsChanged
186    */
187   virtual void UniformMappingsChanged( const UniformMap& mappings );
188
189 public: // ConnectionChangePropagator::Observer
190
191   /**
192    * @copydoc ConnectionChangePropagator::ConnectionsChanged
193    */
194   virtual void ConnectionsChanged( PropertyOwner& owner );
195
196   /**
197    * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
198    */
199   virtual void ConnectedUniformMapChanged( );
200
201 public: // PropertyOwner implementation
202   /**
203    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
204    */
205   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
206
207 public: // Property data
208   AnimatableProperty<Vector4> mColor;
209   AnimatableProperty<Vector4> mBlendColor;
210   DoubleBufferedProperty<int> mFaceCullingMode;
211   DoubleBufferedProperty<int> mBlendingMode;
212   DoubleBufferedProperty<int> mBlendingOptions;
213
214 private:
215   Shader* mShader;
216   Vector<Sampler*> mSamplers; // Not owned
217   ConnectionChangePropagator mConnectionObservers;
218   BlendPolicy mBlendPolicy; ///< The blend policy as determined by PrepareRender
219 };
220
221 inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Material& material, const Shader& shader )
222 {
223   typedef MessageValue1< Material, Shader* > LocalType;
224
225   // Reserve some memory inside the message queue
226   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
227
228   // Construct message in the message queue memory; note that delete should not be called on the return value
229   new (slot) LocalType( &material, &Material::SetShader, const_cast<Shader*>(&shader) );
230 }
231
232 inline void AddSamplerMessage( EventThreadServices& eventThreadServices, const Material& material, const Sampler& sampler )
233 {
234   typedef MessageValue1< Material, Sampler* > LocalType;
235
236   // Reserve some memory inside the message queue
237   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
238
239   // Construct message in the message queue memory; note that delete should not be called on the return value
240   new (slot) LocalType( &material, &Material::AddSampler, const_cast<Sampler*>(&sampler) );
241 }
242
243 inline void RemoveSamplerMessage( EventThreadServices& eventThreadServices, const Material& material, Sampler& sampler )
244 {
245   typedef MessageValue1< Material, Sampler* > LocalType;
246
247   // Reserve some memory inside the message queue
248   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
249
250   // Construct message in the message queue memory; note that delete should not be called on the return value
251   new (slot) LocalType( &material, &Material::RemoveSampler, const_cast<Sampler*>(&sampler) );
252 }
253
254 inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Material& material, unsigned int options )
255 {
256   typedef MessageDoubleBuffered1< Material, unsigned int > LocalType;
257
258   // Reserve some memory inside the message queue
259   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
260
261   new (slot) LocalType( &material, &Material::SetBlendingOptions, options );
262 }
263
264
265 } // namespace SceneGraph
266 } // namespace Internal
267 } // namespace Dali
268
269 #endif //  DALI_INTERNAL_SCENE_GRAPH_MATERIAL_H