Shader binary synchronous simplified IO
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 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/math/rect.h>
23 #include <dali/internal/common/shader-saver.h>
24 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
25 #include <dali/internal/update/resources/resource-manager-declarations.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 class GlAbstraction;
34 class RenderStatus;
35 }
36
37 struct Vector4;
38
39 namespace Internal
40 {
41 class Context;
42 class ProgramCache;
43 class ShaderSaver;
44
45 namespace SceneGraph
46 {
47 class Renderer;
48 class RenderQueue;
49 class TextureCache;
50 class RenderInstruction;
51 class RenderInstructionContainer;
52 class RenderTracker;
53 class Shader;
54 class RenderGeometry;
55 class PropertyBufferDataProvider;
56
57 /**
58  * RenderManager is responsible for rendering the result of the previous "update", which
59  * is provided in a RenderCommand during UpdateManager::Update().
60  */
61 class RenderManager : public PostProcessResourceDispatcher
62 {
63 public:
64
65   /**
66    * Construct a new RenderManager.
67    * @param[in]  glAbstraction The GL abstraction used for rendering.
68    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
69    */
70   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
71
72   /**
73    * Non-virtual destructor; not intended as a base class
74    */
75   ~RenderManager();
76
77   /**
78    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
79    * @return The render queue.
80    */
81   RenderQueue& GetRenderQueue();
82
83   /**
84    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
85    * accessor methods should only be used from the render thread.
86    * @return The texture cache
87    */
88   TextureCache& GetTextureCache();
89
90   /**
91    * @copydoc Dali::Integration::Core::ContextCreated()
92    */
93   void ContextCreated();
94
95   /**
96    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
97    */
98   void ContextDestroyed();
99
100   /**
101    * Dispatch requests onto the postProcessResourcesQueue
102    * @param[in] request The request to dispatch
103    */
104   virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
105
106   /**
107    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
108    * caching and saving.
109    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
110    * @note This should be called during core initialisation if shader binaries are to be used.
111    */
112   void SetShaderSaver( ShaderSaver& upstream );
113
114   /**
115    * Retrieve the render instructions; these should be set during each "update" traversal.
116    * @return The render instruction container.
117    */
118   RenderInstructionContainer& GetRenderInstructionContainer();
119
120   // The following methods should be called via RenderQueue messages
121
122   /**
123    * Set the background color i.e. the glClear color used at the beginning of each frame.
124    * @param[in] color The new background color.
125    */
126   void SetBackgroundColor( const Vector4& color );
127
128   /*
129    * Set the frame time delta (time elapsed since the last frame.
130    * @param[in] deltaTime the delta time
131    */
132   void SetFrameDeltaTime( float deltaTime );
133
134   /**
135    * Returns the rectangle for the default surface (probably the application window).
136    * @return Rectangle for the surface.
137    */
138   void SetDefaultSurfaceRect( const Rect<int>& rect );
139
140   /**
141    * Add a Renderer to the render manager.
142    * @param[in] renderer The renderer to add.
143    * @post renderer is owned by RenderManager
144    */
145   void AddRenderer( Renderer* renderer );
146
147   /**
148    * Remove a Renderer from the render manager.
149    * @param[in] renderer The renderer to remove.
150    * @post renderer is destroyed.
151    */
152   void RemoveRenderer( Renderer* renderer );
153
154   /**
155    * Add a geometry to the render manager.
156    * @param[in] geometry The geometry to add.
157    * @post geometry is owned by RenderManager
158    */
159   void AddGeometry( RenderGeometry* geometry );
160
161   /**
162    * Remove a geometry from the render manager.
163    * @param[in] geometry The geometry to remove.
164    * @post geometry is destroyed.
165    */
166   void RemoveGeometry( RenderGeometry* geometry );
167
168   /**
169    * Adds a property buffer to a RenderGeometry from the render manager.
170    * @param[in] geometry The geometry
171    * @param[in] propertyBuffer The property buffer to remove.
172    * @param[in] target Specifies the type of the buffer
173    * @param[in] usage Specifies how will the buffer be used
174    */
175   void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
176
177   /**
178    * Remove a property buffer from a RenderGeometry from the render manager.
179    * @param[in] geometry The geometry
180    * @param[in] propertyBuffer The property buffer to remove.
181    * @post property buffer is destroyed.
182    */
183   void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
184
185   /**
186    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
187    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
188    * object, usually an offscreen render task.
189    * @param[in] renderTracker The render tracker
190    */
191   void AddRenderTracker( RenderTracker* renderTracker );
192
193   /**
194    * Removes a render tracker from the RenderManager.
195    * @param[in] renderTracker The render tracker to remove.
196    */
197   void RemoveRenderTracker( RenderTracker* renderTracker );
198
199   /**
200    * Set the default shader that is to be used in absence of custom shader
201    * @param[in] shader that is the default one
202    */
203   void SetDefaultShader( Shader* shader );
204
205   /**
206    * returns the Program controller for sending program messages
207    * @return the ProgramController
208    */
209   ProgramCache* GetProgramCache();
210
211   // This method should be called from Core::Render()
212
213   /**
214    * Renders the results of the previous "update" traversal.
215    * @param[out] status contains the flag that indicates if render instructions exist
216    * @return true if a further update is required
217    */
218   bool Render( Integration::RenderStatus& status );
219
220 private:
221
222   /**
223    * Helper to process a single RenderInstruction.
224    * @param[in] instruction A description of the rendering operation.
225    * @param[in] defaultShader default shader to use.
226    * @param[in] elapsedTime from previous render.
227    */
228   void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
229
230 private:
231
232   /**
233    * Construct a new RenderManager.
234    */
235   RenderManager();
236
237   // Undefined
238   RenderManager( const RenderManager& );
239
240   // Undefined
241   RenderManager& operator=( const RenderManager& rhs );
242
243 private:
244
245   struct Impl;
246   Impl* mImpl;
247
248 };
249
250 } // namespace SceneGraph
251
252 } // namespace Internal
253
254 } // namespace Dali
255
256 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__