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