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 * Add a GeometryType specific default program to this ShaderEffect
77 * @param[in] geometryType The GeometryType rendered by the shader program
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( GeometryType geometryType, const std::string& vertexSource, const std::string& fragmentSource );
84 * Add a GeometryType specific default program to this ShaderEffect.
85 * This overload allows the optional prefixing for both the vertex and fragment shader.
86 * A useful prefix may be shader \#defines for conditional compilation.
87 * @param[in] geometryType The GeometryType rendered by the shader program
88 * @param[in] vertexPrefix The prefix source code for the vertex shader
89 * @param[in] fragmentPrefix The prefix source code for the fragment shader
90 * @param[in] vertexSource The source code for the vertex shader
91 * @param[in] fragmentSource The source code for the fragment shader
93 void SetPrograms( GeometryType geometryType,
94 const std::string& vertexPrefix, const std::string& fragmentPrefix,
95 const std::string& vertexSource, const std::string& fragmentSource );
98 * Send shader program to scene-graph object.
99 * @param[in] geometryType The GeometryType rendered by the shader program
100 * @param[in] vertexSource The source code for the vertex shader
101 * @param[in] fragmentSource The source code for the fragment shader
102 * @param[in] modifiesGeometry True if the shader modifies geometry
104 void SendProgramMessage( GeometryType geometryType,
105 const std::string& vertexSource, const std::string& fragmentSource,
106 bool modifiesGeometry );
109 * Notify ShaderEffect that it's being used by an Actor.
114 * Notify ShaderEffect that an Actor is no longer using it.
118 public: // Default property extensions from Object
121 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
123 virtual unsigned int GetDefaultPropertyCount() const;
126 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
128 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
131 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
133 virtual const char* GetDefaultPropertyName( Property::Index index ) const;
136 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
138 virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
141 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
143 virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
146 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
148 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
151 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
153 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
156 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
158 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
161 * @copydoc Dali::Internal::Object::SetDefaultProperty()
163 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
166 * @copydoc Dali::Internal::Object::GetDefaultProperty()
168 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
171 * @copydoc Dali::Internal::Object::NotifyScenePropertyInstalled()
173 virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const;
176 * @copydoc Dali::Internal::Object::GetSceneObject()
178 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
181 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
183 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
186 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
188 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
193 * Protected constructor.
194 * @param[in] eventThreadServices the interface to use for sending messages to the update thread
195 * @param[in] hints Geometry hints
197 ShaderEffect( EventThreadServices& eventThreadServices, Dali::ShaderEffect::GeometryHints hints );
200 * A reference counted object may only be deleted by calling Unreference()
202 virtual ~ShaderEffect();
206 // No copying allowed, thus these are undefined
207 ShaderEffect( const ShaderEffect& );
208 ShaderEffect& operator=( const ShaderEffect& rhs );
211 EventThreadServices& mEventThreadServices; ///< Event thread services, for sending messages
212 SceneGraph::Shader* mSceneObject; ///< pointer to the scene shader, should not be changed on this thread
213 Dali::Image mImage; ///< Client-side handle for the effect image
214 std::vector<ResourceTicketPtr> mTickets; ///< Collection of shader program tickets
215 unsigned int mConnectionCount; ///< number of on-stage ImageActors using this shader effect
216 Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry
217 Dali::Vector< UniformCoordinateType > mCoordinateTypes; ///< cached to avoid sending tons of unnecessary messages
221 } // namespace Internal
223 // Helpers for public-api forwarding methods
225 inline Internal::ShaderEffect& GetImplementation(Dali::ShaderEffect& effect)
227 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
229 BaseObject& handle = effect.GetBaseObject();
231 return static_cast<Internal::ShaderEffect&>(handle);
234 inline const Internal::ShaderEffect& GetImplementation(const Dali::ShaderEffect& effect)
236 DALI_ASSERT_ALWAYS(effect && "ShaderEffect handle is empty");
238 const BaseObject& handle = effect.GetBaseObject();
240 return static_cast<const Internal::ShaderEffect&>(handle);
245 #endif // __DALI_INTERNAL_SHADER_EFFECT_H__