[3.0] Remove/move experimental features
[platform/core/uifw/dali-core.git] / dali / internal / event / effects / shader-effect-impl.h
1 #ifndef __DALI_INTERNAL_SHADER_EFFECT_H__
2 #define __DALI_INTERNAL_SHADER_EFFECT_H__
3
4 /*
5  * Copyright (c) 2014 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 // INTERNAL INCLUDES
22 #include <dali/public-api/images/image.h>
23 #include <dali/devel-api/shader-effects/shader-effect.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/effects/shader-declarations.h>
26 #include <dali/internal/event/common/object-impl.h>
27 #include <dali/internal/event/rendering/shader-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * An abstract base class for a shader effect object.
37  * The corresponding scene-graph object is a collection of shader programs,
38  * which can apply the same effect to different geometry types.
39  */
40 class ShaderEffect : public Object
41 {
42 public:
43   typedef Dali::ShaderEffect::UniformCoordinateType UniformCoordinateType;
44
45   /**
46    * Create a new ShaderEffect with no programs
47    * @param hints GeometryHints to define the geometry of the rendered object
48    * @return A smart-pointer to a newly allocated shader effect.
49    */
50   static ShaderEffectPtr New( Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE );
51
52   /**
53    * @copydoc Dali::ShaderEffect::SetEffectImage
54    */
55   void SetEffectImage( Dali::Image image );
56
57   /**
58    * @copydoc Dali::ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType )
59    */
60   void SetUniform( const std::string& name,
61                    Property::Value value,
62                    UniformCoordinateType uniformCoordinateType );
63
64   /**
65    * Add a GeometryType specific default program to this ShaderEffect
66    * @param[in] geometryType    The GeometryType rendered by the shader program
67    * @param[in] vertexSource    The source code for the vertex shader
68    * @param[in] fragmentSource  The source code for the fragment shader
69    */
70   void SetPrograms( const std::string& vertexSource, const std::string& fragmentSource );
71
72   /**
73    * Add a default program to this ShaderEffect.
74    * This overload allows the optional prefixing for both the vertex and fragment shader.
75    * A useful prefix may be shader \#defines for conditional compilation.
76    * @param[in] vertexPrefix    The prefix source code for the vertex shader
77    * @param[in] fragmentPrefix  The prefix source code for the fragment shader
78    * @param[in] vertexSource    The source code for the vertex shader
79    * @param[in] fragmentSource  The source code for the fragment shader
80    */
81   void SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix,
82                     const std::string& vertexSource, const std::string& fragmentSource );
83
84   /**
85    * @brief Notify ShaderEffect that it's being used by an Actor.
86    *
87    * @param[in] actor The Actor that is connecting to this ShaderEffect
88    */
89   void Connect( ActorPtr actor );
90
91   /**
92    * @brief Notify ShaderEffect that an Actor is no longer using it.
93    *
94    * @param[in] actor The Actor that is disconnecting from this ShaderEffect
95    */
96   void Disconnect( ActorPtr actor );
97
98 public:
99
100   /**
101    * Returns the shader for this ShaderEffect
102    *
103    * @return Returns the shader for this ShaderEffect
104    */
105   ShaderPtr GetShader() const { return mShader; }
106
107   /**
108    * Returns the geometry grid size.
109    *
110    * @param[in] size The pixel area size.
111    * @return Returns the geometry grid size
112    */
113   Vector2 GetGridSize( const Vector2& size );
114
115   /**
116    * Returns the effect image for this ShaderEffect
117    *
118    * @return Returns the effect image for this ShaderEffect
119    */
120   Dali::Image GetEffectImage() const { return mEffectImage; }
121
122 public: //  override property functions from Object
123
124   /**
125    * @copydoc Dali::Handle::GetPropertyCount()
126    */
127   virtual unsigned int GetPropertyCount() const;
128
129   /**
130    * @copydoc Dali::Handle::GetPropertyName()
131    */
132   virtual std::string GetPropertyName( Property::Index index ) const;
133
134   /**
135    * @copydoc Dali::Handle::GetPropertyIndex()
136    */
137   virtual Property::Index GetPropertyIndex( const std::string& name ) const;
138
139   /**
140    * @copydoc Dali::Handle::IsPropertyWritable()
141    */
142   virtual bool IsPropertyWritable( Property::Index index ) const;
143
144   /**
145    * @copydoc Dali::Handle::IsPropertyAnimatable()
146    */
147   virtual bool IsPropertyAnimatable( Property::Index index ) const;
148
149   /**
150    * @copydoc Dali::Handle::IsPropertyAConstraintInput()
151    */
152   virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
153
154   /**
155    * @copydoc Dali::Handle::GetPropertyType()
156    */
157   virtual Property::Type GetPropertyType( Property::Index index ) const;
158
159   /**
160    * @copydoc Dali::Handle::SetProperty()
161    */
162   virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
163
164   /**
165    * @copydoc Dali::Handle::GetProperty()
166    */
167   virtual Property::Value GetProperty( Property::Index index ) const;
168
169   /**
170    * @copydoc Dali::Handle::GetPropertyIndices()
171    */
172   virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
173
174   /**
175    * @copydoc Dali::Handle::RegisterProperty()
176    */
177   virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
178
179   /**
180    * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
181    */
182   virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
183
184   /**
185    * @copydoc Dali::Handle::AddPropertyNotification()
186    */
187   virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
188                                                               int componentIndex,
189                                                               const Dali::PropertyCondition& condition );
190
191   /**
192    * @copydoc Dali::Handle::RemovePropertyNotification()
193    */
194   virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
195
196   /**
197    * @copydoc Dali::Handle::RemovePropertyNotifications()
198    */
199   virtual void RemovePropertyNotifications();
200
201 public: // Default property extensions from Object
202   /**
203    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
204    */
205   virtual unsigned int GetDefaultPropertyCount() const;
206
207   /**
208    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
209    */
210   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
211
212   /**
213    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
214    */
215   virtual const char* GetDefaultPropertyName( Property::Index index ) const;
216
217   /**
218    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
219    */
220   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
221
222   /**
223    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
224    */
225   virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
226
227   /**
228    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
229    */
230   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
231
232   /**
233    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
234    */
235   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
236
237   /**
238    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
239    */
240   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
241
242   /**
243    * @copydoc Dali::Internal::Object::SetDefaultProperty()
244    */
245   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
246
247   /**
248    * @copydoc Dali::Internal::Object::GetDefaultProperty()
249    */
250   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
251
252   /**
253    * @copydoc Dali::Internal::Object::GetSceneObject()
254    */
255   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
256
257   /**
258    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
259    */
260   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
261
262   /**
263    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
264    */
265   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
266
267   /**
268    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
269    */
270   virtual int GetPropertyComponentIndex( Property::Index index ) const;
271
272 protected:
273
274   /**
275    * Protected constructor.
276    * @param[in] hints Geometry hints
277    */
278   ShaderEffect( Dali::ShaderEffect::GeometryHints hints );
279
280   /**
281    * A reference counted object may only be deleted by calling Unreference()
282    */
283   virtual ~ShaderEffect();
284
285 private:
286
287   // No copying allowed, thus these are undefined
288   ShaderEffect( const ShaderEffect& );
289   ShaderEffect& operator=( const ShaderEffect& rhs );
290
291 private: // Data
292   std::vector< ActorPtr > mConnectedActors;               ///< The array of actors that are currently connected to this ShaderEffect
293   ShaderPtr               mShader;                        ///< The shader pointer
294   Dali::Image             mEffectImage;                   ///< The Client-side handle to the effect image
295   float                   mGridDensity;                  ///< The grid denisty
296   Dali::ShaderEffect::GeometryHints  mGeometryHints;     ///< shader geometry hints for building the geometry
297
298 };
299
300 } // namespace Internal
301
302 // Helpers for public-api forwarding methods
303
304 inline Internal::ShaderEffect& GetImplementation(Dali::ShaderEffect& effect)
305 {
306   DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
307
308   BaseObject& handle = effect.GetBaseObject();
309
310   return static_cast<Internal::ShaderEffect&>(handle);
311 }
312
313 inline const Internal::ShaderEffect& GetImplementation(const Dali::ShaderEffect& effect)
314 {
315   DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
316
317   const BaseObject& handle = effect.GetBaseObject();
318
319   return static_cast<const Internal::ShaderEffect&>(handle);
320 }
321
322 } // namespace Dali
323
324 #endif // __DALI_INTERNAL_SHADER_EFFECT_H__