Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / 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) 2018 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/graphics-api/graphics-api-controller.h>
23 #include <dali/graphics-api/graphics-api-accessor.h>
24 #include <dali/graphics-api/graphics-api-shader.h>
25
26 #include <dali/integration-api/graphics/graphics.h>
27
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/common/shader-data.h>
30 #include <dali/internal/event/common/event-thread-services.h>
31 #include <dali/internal/update/common/property-owner.h>
32 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
33 #include <dali/internal/update/rendering/shader-cache.h>
34
35 namespace Dali
36 {
37 namespace Internal
38 {
39
40 namespace SceneGraph
41 {
42
43 class ConnectionObserver;
44 class SceneController;
45
46 /**
47  * Owner of Graphics Shader; also enables sharing of uniform properties.
48  * Owned by UpdateManager.
49  */
50 class Shader : public PropertyOwner, public UniformMap::Observer
51 {
52 public:
53
54   /**
55    * Constructor
56    * @param hints Shader hints
57    */
58   Shader( Dali::Shader::Hint::Value& hints );
59
60   /**
61    * Virtual destructor
62    */
63   virtual ~Shader();
64
65   /**
66    * Initialize the shader object with the Graphics API when added to UpdateManager
67    *
68    * @param[in] graphics The Graphics API
69    * @param[in] shaderCache A cache
70    */
71   void Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache );
72
73   /**
74    * Query whether a shader hint is set.
75    * @pre The shader has been initialized.
76    * @param[in] hint The hint to check.
77    * @return True if the given hint is set.
78    */
79   bool HintEnabled( Dali::Shader::Hint::Value hint ) const
80   {
81     return mHints & hint;
82   }
83
84   /**
85    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
86    */
87   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex )
88   {
89     // no default properties
90   }
91
92   /**
93    * Get the graphics shader object
94    * @return the graphics shader object
95    */
96   Graphics::API::Accessor<Graphics::API::Shader>& GetGfxObject();
97
98 public: // Messages
99   /**
100    * Set the shader data into the graphics API.
101    *
102    * @param[in] shaderData The shader source or binary.
103    * @param[in] modifiesGeometry Hint to say if the shader modifies geometry. (useful for culling)
104    */
105   void SetShaderProgram( Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
106
107 public: // Implementation of ConnectionChangePropagator
108
109   /**
110    * @copydoc ConnectionChangePropagator::AddObserver
111    */
112   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
113
114   /**
115    * @copydoc ConnectionChangePropagator::RemoveObserver
116    */
117   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
118
119 public: // UniformMap::Observer
120   /**
121    * @copydoc UniformMap::Observer::UniformMappingsChanged
122    */
123   virtual void UniformMappingsChanged( const UniformMap& mappings );
124
125
126 private: // Data
127   Integration::Graphics::Graphics*               mGraphics; ///< Graphics interface object
128   Graphics::API::Accessor<Graphics::API::Shader> mGraphicsShader; ///< The graphics object
129   ShaderCache*                                   mShaderCache;
130   Dali::Shader::Hint::Value                      mHints; ///< Hints for the shader
131   ConnectionChangePropagator                     mConnectionObservers; ///< Watch for connection changes
132 };
133
134
135 inline void SetShaderProgramMessage( EventThreadServices& eventThreadServices,
136                                      Shader& shader,
137                                      Internal::ShaderDataPtr shaderData,
138                                      bool modifiesGeometry )
139 {
140   typedef MessageValue2< Shader, Internal::ShaderDataPtr, bool > LocalType;
141
142   // Reserve some memory inside the message queue
143   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
144
145   // Construct message in the message queue memory; note that delete should not be called on the return value
146   new (slot) LocalType( &shader, &Shader::SetShaderProgram, shaderData, modifiesGeometry );
147 }
148
149
150
151 } // namespace SceneGraph
152
153 } // namespace Internal
154
155 } // namespace Dali
156
157 #endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__