Moving CullFace mode and Blending modes to Pipeline
[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) 2021 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/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class Program;
32 class ProgramCache;
33
34 namespace SceneGraph
35 {
36 class ConnectionObserver;
37 class SceneController;
38
39 /**
40  * A holder class for Program; also enables sharing of uniform properties
41  */
42 class Shader : public PropertyOwner, public UniformMap::Observer
43 {
44 public:
45   /**
46    * Constructor
47    * @param hints Shader hints
48    */
49   Shader(Dali::Shader::Hint::Value& hints);
50
51   /**
52    * Virtual destructor
53    */
54   ~Shader() override;
55
56   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57   // The following methods are called during Update
58   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
60   /**
61    * Query whether a shader hint is set.
62    * @pre The shader has been initialized.
63    * @param[in] hint The hint to check.
64    * @return True if the given hint is set.
65    */
66   bool HintEnabled(Dali::Shader::Hint::Value hint) const
67   {
68     return mHints & hint;
69   }
70
71   /**
72    * @return True if the fragment shader outputs only 1.0 on the alpha channel
73    *
74    * @note Shaders that can output any value on the alpha channel
75    * including 1.0 should return false for this.
76    */
77   bool IsOutputOpaque();
78
79   /**
80    * @return True if the fragment shader can output any value but 1.0 on the alpha channel
81    *
82    * @note Shaders that can output any value on the alpha channel
83    * including 1.0 should return false for this
84    */
85   bool IsOutputTransparent();
86
87   /**
88    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
89    */
90   virtual void ResetDefaultProperties(BufferIndex updateBufferIndex)
91   {
92     // no default properties
93   }
94
95   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96   // The following methods are called during Render
97   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98
99   /**
100    * @brief Set the shader data for this shader.
101    * @param[in] shaderData The program's vertex/fragment source and optionally pre-compiled shader binary.
102    */
103   void SetShaderData(ShaderDataPtr shaderData);
104
105   /**
106    * Get the shader data for this shader.
107    * @return The shader data.
108    */
109   ShaderDataPtr GetShaderData() const;
110
111 public: // Implementation of ConnectionChangePropagator
112   /**
113    * @copydoc ConnectionChangePropagator::AddObserver
114    */
115   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
116
117   /**
118    * @copydoc ConnectionChangePropagator::RemoveObserver
119    */
120   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
121
122 public: // UniformMap::Observer
123   /**
124    * @copydoc UniformMap::Observer::UniformMappingsChanged
125    */
126   void UniformMappingsChanged(const UniformMap& mappings) override;
127
128 private: // Data
129   Dali::Shader::Hint::Value mHints;
130
131   ShaderDataPtr mShaderData;
132
133   ConnectionChangePropagator mConnectionObservers;
134 };
135
136 inline void SetShaderDataMessage(EventThreadServices& eventThreadServices, const Shader& shader, ShaderDataPtr shaderData)
137 {
138   using LocalType = MessageValue1<Shader, ShaderDataPtr>;
139
140   // Reserve some memory inside the message queue
141   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
142
143   // Construct message in the message queue memory; note that delete should not be called on the return value
144   new(slot) LocalType(&shader, &Shader::SetShaderData, shaderData);
145 }
146
147 } // namespace SceneGraph
148
149 } // namespace Internal
150
151 } // namespace Dali
152
153 #endif // DALI_INTERNAL_SCENE_GRAPH_SHADER_H