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