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