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/effects/shader-declarations.h>
25 #include <dali/internal/event/common/object-impl.h>
26 #include <dali/internal/event/resources/resource-ticket.h>
27 #include <dali/internal/render/shaders/scene-graph-shader.h>
41 * An abstract base class for a shader effect object.
42 * The corresponding scene-graph object is a collection of shader programs,
43 * which can apply the same effect to different geometry types.
45 class ShaderEffect : public Object
48 typedef Dali::ShaderEffect::UniformCoordinateType UniformCoordinateType;
52 DOESNT_MODIFY_GEOMETRY,
57 * Create a new ShaderEffect with no programs
58 * @param hints GeometryHints to define the geometry of the rendered object
59 * @return A smart-pointer to a newly allocated shader effect.
61 static ShaderEffectPtr New( Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE );
64 * @copydoc Dali::ShaderEffect::SetEffectImage
66 void SetEffectImage( Dali::Image image );
69 * @copydoc Dali::ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType )
71 void SetUniform( const std::string& name,
72 Property::Value value,
73 UniformCoordinateType uniformCoordinateType );
76 * @copydoc Dali::ShaderEffect::AttachExtension()
78 void AttachExtension( Dali::ShaderEffect::Extension *object );
81 * @copydoc Dali::ShaderEffect::GetExtension()
83 Dali::ShaderEffect::Extension& GetExtension();
86 * @copydoc Dali::ShaderEffect::GetExtension() const
88 const Dali::ShaderEffect::Extension& GetExtension() const;
91 * Add a GeometryType specific default program to this ShaderEffect
92 * @param[in] geometryType The GeometryType rendered by the shader program
93 * @param[in] vertexSource The source code for the vertex shader
94 * @param[in] fragmentSource The source code for the fragment shader
96 void SetPrograms( GeometryType geometryType, const std::string& vertexSource, const std::string& fragmentSource );
99 * Add a GeometryType specific default program to this ShaderEffect.
100 * This overload allows the optional prefixing for both the vertex and fragment shader.
101 * A useful prefix may be shader \#defines for conditional compilation.
102 * @param[in] geometryType The GeometryType rendered by the shader program
103 * @param[in] vertexPrefix The prefix source code for the vertex shader
104 * @param[in] fragmentPrefix The prefix source code for the fragment shader
105 * @param[in] vertexSource The source code for the vertex shader
106 * @param[in] fragmentSource The source code for the fragment shader
108 void SetPrograms( GeometryType geometryType,
109 const std::string& vertexPrefix, const std::string& fragmentPrefix,
110 const std::string& vertexSource, const std::string& fragmentSource );
113 * Send shader program to scene-graph object.
114 * @param[in] geometryType The GeometryType rendered by the shader program
115 * @param[in] subType The subtype, one of ShaderSubTypes.
116 * @param[in] vertexSource The source code for the vertex shader
117 * @param[in] fragmentSource The source code for the fragment shader
118 * @param[in] modifiesGeometry True if the shader modifies geometry
120 void SendProgramMessage( GeometryType geometryType, ShaderSubTypes subType,
121 const std::string& vertexSource, const std::string& fragmentSource,
122 bool modifiesGeometry );
125 * Notify ShaderEffect that it's being used by an Actor.
130 * Notify ShaderEffect that an Actor is no longer using it.
134 public: // Default property extensions from Object
137 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
139 virtual unsigned int GetDefaultPropertyCount() const;
142 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
144 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
147 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
149 virtual const char* GetDefaultPropertyName( Property::Index index ) const;
152 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
154 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
157 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
159 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
162 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
164 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
167 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
169 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
172 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
174 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
177 * @copydoc Dali::Internal::Object::SetDefaultProperty()
179 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
182 * @copydoc Dali::Internal::Object::GetDefaultProperty()
184 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
187 * @copydoc Dali::Internal::Object::NotifyScenePropertyInstalled()
189 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
192 * @copydoc Dali::Internal::Object::GetSceneObject()
194 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
197 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
199 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
202 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
204 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
209 * Protected constructor.
211 ShaderEffect( SceneGraph::UpdateManager& updateManager, Dali::ShaderEffect::GeometryHints hints );
214 * A reference counted object may only be deleted by calling Unreference()
216 virtual ~ShaderEffect();
220 // No copying allowed, thus these are undefined
221 ShaderEffect( const ShaderEffect& );
222 ShaderEffect& operator=( const ShaderEffect& rhs );
226 SceneGraph::UpdateManager& mUpdateManager;///< reference to the update manager
227 SceneGraph::Shader* mSceneObject; ///< pointer to the scene shader, should not be changed on this thread
228 Dali::Image mImage; ///< Client-side handle for the effect image
229 IntrusivePtr<Dali::ShaderEffect::Extension> mExtension;
230 std::vector<ResourceTicketPtr> mTickets; ///< Collection of shader program tickets
231 unsigned int mConnectionCount; ///< number of on-stage ImageActors using this shader effect
232 Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry
233 Dali::Vector< UniformCoordinateType > mCoordinateTypes; ///< cached to avoid sending tons of unnecessary messages
237 } // namespace Internal
239 // Helpers for public-api forwarding methods
241 inline Internal::ShaderEffect& GetImplementation(Dali::ShaderEffect& effect)
243 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
245 BaseObject& handle = effect.GetBaseObject();
247 return static_cast<Internal::ShaderEffect&>(handle);
250 inline const Internal::ShaderEffect& GetImplementation(const Dali::ShaderEffect& effect)
252 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
254 const BaseObject& handle = effect.GetBaseObject();
256 return static_cast<const Internal::ShaderEffect&>(handle);
261 #endif // __DALI_INTERNAL_SHADER_EFFECT_H__