[3.0] Remove/move experimental features
[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/devel-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 Shader hints
51    */
52   Shader( Dali::Shader::Hint::Value& 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 hint is set.
65    * @pre The shader has been initialized.
66    * @param[in] hint The hint to check.
67    * @return True if the given hint is set.
68    */
69   bool HintEnabled( Dali::Shader::Hint::Value hint ) const
70   {
71     return mHints & hint;
72   }
73
74   /**
75    * @return True if the fragment shader outputs only 1.0 on the alpha channel
76    *
77    * @note Shaders that can output any value on the alpha channel
78    * including 1.0 should return false for this.
79    */
80   bool IsOutputOpaque();
81
82   /**
83    * @return True if the fragment shader can output any value but 1.0 on the alpha channel
84    *
85    * @note Shaders that can output any value on the alpha channel
86    * including 1.0 should return false for this
87    */
88   bool IsOutputTransparent();
89
90   /**
91    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
92    */
93   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex )
94   {
95     // no default properties
96   }
97
98   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99   // The following methods are called in Render thread
100   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101
102   /**
103    * @brief Set the program for this shader.
104    * @param[in] shaderData        The program's vertex/fragment source and optionally precompiled shader binary.
105    * @param[in] programCache      Owner of the Programs.
106    * @param[in] modifiesGeometry  True if the vertex shader changes the positions of vertexes such that
107    * they might exceed the bounding box of vertexes passing through the default transformation.
108    */
109   void SetProgram( Internal::ShaderDataPtr shaderData,
110                    ProgramCache* programCache,
111                    bool modifiesGeometry );
112
113   /**
114    * Get the program built for this shader
115    * @return The program built from the shader sources.
116    */
117   Program* GetProgram();
118
119 public: // Implementation of ObjectOwnerContainer template methods
120
121   /**
122    * Connect the object to the scene graph
123    *
124    * @param[in] sceneController The scene controller - used for sending messages to render thread
125    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
126    */
127   void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
128
129   /**
130    * Disconnect the object from the scene graph
131    * @param[in] sceneController The scene controller - used for sending messages to render thread
132    * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
133    */
134   void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
135
136 public: // Implementation of ConnectionChangePropagator
137
138   /**
139    * @copydoc ConnectionChangePropagator::AddObserver
140    */
141   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
142
143   /**
144    * @copydoc ConnectionChangePropagator::RemoveObserver
145    */
146   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
147
148 public:
149
150 public: // UniformMap::Observer
151   /**
152    * @copydoc UniformMap::Observer::UniformMappingsChanged
153    */
154   virtual void UniformMappingsChanged( const UniformMap& mappings );
155
156 private: // Data
157
158   Dali::Shader::Hint::Value     mHints;
159
160   Program*                       mProgram;
161
162   ConnectionChangePropagator     mConnectionObservers;
163 };
164
165 } // namespace SceneGraph
166
167 } // namespace Internal
168
169 } // namespace Dali
170
171 #endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__