1 #ifndef __DALI_INTERNAL_SHADER_EFFECT_H__
2 #define __DALI_INTERNAL_SHADER_EFFECT_H__
5 * Copyright (c) 2014 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/images/image.h>
23 #include <dali/public-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>
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.
40 class ShaderEffect : public Object
43 typedef Dali::ShaderEffect::UniformCoordinateType UniformCoordinateType;
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.
50 static ShaderEffectPtr New( Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE );
53 * @copydoc Dali::ShaderEffect::SetEffectImage
55 void SetEffectImage( Dali::Image image );
58 * @copydoc Dali::ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType )
60 void SetUniform( const std::string& name,
61 Property::Value value,
62 UniformCoordinateType uniformCoordinateType );
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
70 void SetPrograms( const std::string& vertexSource, const std::string& fragmentSource );
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
81 void SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix,
82 const std::string& vertexSource, const std::string& fragmentSource );
85 * @brief Notify ShaderEffect that it's being used by an Actor.
87 * @param[in] actor The Actor that is connecting to this ShaderEffect
89 void Connect( ActorPtr actor );
92 * @brief Notify ShaderEffect that an Actor is no longer using it.
94 * @param[in] actor The Actor that is disconnecting from this ShaderEffect
96 void Disconnect( ActorPtr actor );
101 * Returns the shader for this ShaderEffect
103 * @return Returns the shader for this ShaderEffect
105 ShaderPtr GetShader() const { return mShader; }
108 * Returns the geometry grid size.
110 * @param[in] size The pixel area size.
111 * @return Returns the geometry grid size
113 Vector2 GetGridSize( const Vector2& size );
116 * Returns the effect image for this ShaderEffect
118 * @return Returns the effect image for this ShaderEffect
120 Dali::Image GetEffectImage() const { return mEffectImage; }
122 public: // override property functions from Object
125 * @copydoc Dali::Handle::GetPropertyCount()
127 virtual unsigned int GetPropertyCount() const;
130 * @copydoc Dali::Handle::GetPropertyName()
132 virtual std::string GetPropertyName( Property::Index index ) const;
135 * @copydoc Dali::Handle::GetPropertyIndex()
137 virtual Property::Index GetPropertyIndex( const std::string& name ) const;
140 * @copydoc Dali::Handle::IsPropertyWritable()
142 virtual bool IsPropertyWritable( Property::Index index ) const;
145 * @copydoc Dali::Handle::IsPropertyAnimatable()
147 virtual bool IsPropertyAnimatable( Property::Index index ) const;
150 * @copydoc Dali::Handle::IsPropertyAConstraintInput()
152 virtual bool IsPropertyAConstraintInput( Property::Index index ) const;
155 * @copydoc Dali::Handle::GetPropertyType()
157 virtual Property::Type GetPropertyType( Property::Index index ) const;
160 * @copydoc Dali::Handle::SetProperty()
162 virtual void SetProperty( Property::Index index, const Property::Value& propertyValue );
165 * @copydoc Dali::Handle::GetProperty()
167 virtual Property::Value GetProperty( Property::Index index ) const;
170 * @copydoc Dali::Handle::GetPropertyIndices()
172 virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
175 * @copydoc Dali::Handle::RegisterProperty()
177 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
180 * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
182 virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
185 * @copydoc Dali::Handle::AddPropertyNotification()
187 virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
189 const Dali::PropertyCondition& condition );
192 * @copydoc Dali::Handle::RemovePropertyNotification()
194 virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
197 * @copydoc Dali::Handle::RemovePropertyNotifications()
199 virtual void RemovePropertyNotifications();
201 public: // Default property extensions from Object
203 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
205 virtual unsigned int GetDefaultPropertyCount() const;
208 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
210 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
213 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
215 virtual const char* GetDefaultPropertyName( Property::Index index ) const;
218 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
220 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
223 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
225 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
228 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
230 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
233 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
235 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
238 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
240 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
243 * @copydoc Dali::Internal::Object::SetDefaultProperty()
245 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
248 * @copydoc Dali::Internal::Object::GetDefaultProperty()
250 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
253 * @copydoc Dali::Internal::Object::GetSceneObject()
255 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
258 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
260 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
263 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
265 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
268 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
270 virtual int GetPropertyComponentIndex( Property::Index index ) const;
275 * Protected constructor.
276 * @param[in] hints Geometry hints
278 ShaderEffect( Dali::ShaderEffect::GeometryHints hints );
281 * A reference counted object may only be deleted by calling Unreference()
283 virtual ~ShaderEffect();
287 // No copying allowed, thus these are undefined
288 ShaderEffect( const ShaderEffect& );
289 ShaderEffect& operator=( const ShaderEffect& rhs );
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
300 } // namespace Internal
302 // Helpers for public-api forwarding methods
304 inline Internal::ShaderEffect& GetImplementation(Dali::ShaderEffect& effect)
306 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
308 BaseObject& handle = effect.GetBaseObject();
310 return static_cast<Internal::ShaderEffect&>(handle);
313 inline const Internal::ShaderEffect& GetImplementation(const Dali::ShaderEffect& effect)
315 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
317 const BaseObject& handle = effect.GetBaseObject();
319 return static_cast<const Internal::ShaderEffect&>(handle);
324 #endif // __DALI_INTERNAL_SHADER_EFFECT_H__