Merge "Deprecated STENCIL DrawMode Will be replaced by separate ClippingMode enum...
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / scene-graph-shader.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_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/shader-effects/shader-effect.h>
23 #include <dali/internal/common/shader-data.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
26
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32
33 class Program;
34 class ProgramCache;
35
36 namespace SceneGraph
37 {
38
39 class ConnectionObserver;
40 class SceneController;
41 /**
42  * A holder class for Program; also enables sharing of uniform properties
43  */
44 class Shader : public PropertyOwner, public UniformMap::Observer
45 {
46 public:
47
48   /**
49    * Constructor
50    * @param hints Geometry hints
51    */
52   Shader( Dali::ShaderEffect::GeometryHints& hints );
53
54   /**
55    * Virtual destructor
56    */
57   virtual ~Shader();
58
59   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60   // The following methods are called during UpdateManager::Update()
61   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62
63   /**
64    * Query whether a shader geometry hint is set.
65    * @pre The shader has been initialized.
66    * @param[in] hint The geometry hint to check.
67    * @return True if the given geometry hint is set.
68    */
69   bool GeometryHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const
70   {
71     return mGeometryHints & hint;
72   }
73
74   /**
75    * Retrieve the set of geometry hints.
76    * @return The hints.
77    */
78   Dali::ShaderEffect::GeometryHints GetGeometryHints() const
79   {
80     return mGeometryHints;
81   }
82
83   /**
84    * Set the geometry hints.
85    * @param[in] hints The hints.
86    */
87   void SetGeometryHints( Dali::ShaderEffect::GeometryHints hints )
88   {
89     mGeometryHints = hints;
90   }
91
92   /**
93    * @return True if the fragment shader outputs only 1.0 on the alpha channel
94    *
95    * @note Shaders that can output any value on the alpha channel
96    * including 1.0 should return false for this.
97    */
98   bool IsOutputOpaque();
99
100   /**
101    * @return True if the fragment shader can output any value but 1.0 on the alpha channel
102    *
103    * @note Shaders that can output any value on the alpha channel
104    * including 1.0 should return false for this
105    */
106   bool IsOutputTransparent();
107
108   /**
109    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
110    */
111   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex )
112   {
113     // no default properties
114   }
115
116   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117   // The following methods are called in Render thread
118   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119
120   /**
121    * @brief Set the program for this shader.
122    * @param[in] shaderData        The program's vertex/fragment source and optionally precompiled shader binary.
123    * @param[in] programCache      Owner of the Programs.
124    * @param[in] modifiesGeometry  True if the vertex shader changes the positions of vertexes such that
125    * they might exceed the bounding box of vertexes passing through the default transformation.
126    */
127   void SetProgram( Internal::ShaderDataPtr shaderData,
128                    ProgramCache* programCache,
129                    bool modifiesGeometry );
130
131   /**
132    * Get the program built for this shader
133    * @return The program built from the shader sources.
134    */
135   Program* GetProgram();
136
137 public: // Implementation of ObjectOwnerContainer template methods
138
139   /**
140    * Connect the object to the scene graph
141    *
142    * @param[in] sceneController The scene controller - used for sending messages to render thread
143    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
144    */
145   void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
146
147   /**
148    * Disconnect the object from the scene graph
149    * @param[in] sceneController The scene controller - used for sending messages to render thread
150    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
151    */
152   void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
153
154 public: // Implementation of ConnectionChangePropagator
155
156   /**
157    * @copydoc ConnectionChangePropagator::AddObserver
158    */
159   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
160
161   /**
162    * @copydoc ConnectionChangePropagator::RemoveObserver
163    */
164   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
165
166 public:
167
168 public: // UniformMap::Observer
169   /**
170    * @copydoc UniformMap::Observer::UniformMappingsChanged
171    */
172   virtual void UniformMappingsChanged( const UniformMap& mappings );
173
174 private: // Data
175
176   Dali::ShaderEffect::GeometryHints mGeometryHints;    ///< shader geometry hints for building the geometry
177
178   Program*                       mProgram;
179
180   ConnectionChangePropagator     mConnectionObservers;
181 };
182
183 } // namespace SceneGraph
184
185 } // namespace Internal
186
187 } // namespace Dali
188
189 #endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__