Implemented shader program property
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / shader-impl.h
1 #ifndef DALI_INTERNAL_SHADER_H
2 #define DALI_INTERNAL_SHADER_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
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/devel-api/rendering/shader.h> // Dali::Shader
25 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
26 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
27 #include <dali/internal/event/resources/resource-ticket.h> // Dali::Internal::ResourceTicketPtr
28 #include <dali/internal/common/shader-data.h> // ShaderPtr
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace SceneGraph
35 {
36 class Shader;
37 }
38
39 class Shader;
40 typedef IntrusivePtr<Shader> ShaderPtr;
41
42 /**
43  * Shader is an object that contains an array of structures of values that
44  * can be accessed as properties.
45  */
46 class Shader : public Object
47 {
48 public:
49
50   /**
51    * @copydoc Dali::Shader::New()
52    */
53   static ShaderPtr New( const std::string& vertexShader,
54                         const std::string& fragmentShader,
55                         Dali::Shader::ShaderHints hints );
56
57   /**
58    * @brief Get the shader scene object
59    *
60    * @return the shader scene object
61    */
62   const SceneGraph::Shader* GetShaderSceneObject() const;
63
64   /**
65    * Retrieve the scene-graph shader added by this object.
66    * @return A pointer to the shader.
67    */
68   SceneGraph::Shader* GetShaderSceneObject();
69
70 public: // Default property extensions from Object
71
72   /**
73    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
74    */
75   virtual unsigned int GetDefaultPropertyCount() const;
76
77   /**
78    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
79    */
80   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
81
82   /**
83    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
84    */
85   virtual const char* GetDefaultPropertyName(Property::Index index) const;
86
87   /**
88    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
89    */
90   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
91
92   /**
93    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
94    */
95   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
96
97   /**
98    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
99    */
100   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
101
102   /**
103    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
104    */
105   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
106
107   /**
108    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
109    */
110   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
111
112   /**
113    * @copydoc Dali::Internal::Object::SetDefaultProperty()
114    */
115   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
116
117   /**
118    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
119    */
120   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
121
122   /**
123    * @copydoc Dali::Internal::Object::GetDefaultProperty()
124    */
125   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
126
127   /**
128    * @copydoc Dali::Internal::Object::GetPropertyOwner()
129    */
130   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
131
132   /**
133    * @copydoc Dali::Internal::Object::GetSceneObject()
134    */
135   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
136
137   /**
138    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
139    */
140   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
141
142   /**
143    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
144    */
145   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
146
147   /**
148    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
149    */
150   virtual int GetPropertyComponentIndex( Property::Index index ) const;
151
152 private: // implementation
153   Shader();
154
155   /**
156    * Second stage initialization
157    */
158   void Initialize( const std::string& vertexShader, const std::string& fragmentShader, Dali::Shader::ShaderHints hints );
159
160 protected:
161   /**
162    * A reference counted object may only be deleted by calling Unreference()
163    */
164   virtual ~Shader();
165
166 private: // unimplemented methods
167   Shader( const Shader& );
168   Shader& operator=( const Shader& );
169
170 private:
171   SceneGraph::Shader* mSceneObject;
172   Internal::ShaderDataPtr mShaderData;
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178 inline Internal::Shader& GetImplementation( Dali::Shader& handle )
179 {
180   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
181
182   BaseObject& object = handle.GetBaseObject();
183
184   return static_cast<Internal::Shader&>(object);
185 }
186
187 inline const Internal::Shader& GetImplementation( const Dali::Shader& handle )
188 {
189   DALI_ASSERT_ALWAYS(handle && "Shader handle is empty");
190
191   const BaseObject& object = handle.GetBaseObject();
192
193   return static_cast<const Internal::Shader&>(object);
194 }
195
196 } // namespace Dali
197
198 #endif // DALI_INTERNAL_SHADER_H