[dali_1.1.7] Merge branch '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/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 #include <dali/internal/render/renderers/render-property-buffer.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 class GlAbstraction;
35 class RenderStatus;
36 }
37
38 struct Vector4;
39
40 namespace Internal
41 {
42 class Context;
43 class ProgramCache;
44 class ShaderSaver;
45
46 namespace Render
47 {
48 class Renderer;
49 class Sampler;
50 }
51
52 namespace SceneGraph
53 {
54 class RenderQueue;
55 class TextureCache;
56 class RenderInstruction;
57 class RenderInstructionContainer;
58 class RenderTracker;
59 class Shader;
60 class RenderGeometry;
61 class PropertyBufferDataProvider;
62
63 /**
64  * RenderManager is responsible for rendering the result of the previous "update", which
65  * is provided in a RenderCommand during UpdateManager::Update().
66  */
67 class RenderManager : public PostProcessResourceDispatcher
68 {
69 public:
70
71   /**
72    * Construct a new RenderManager.
73    * @param[in]  glAbstraction The GL abstraction used for rendering.
74    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
75    */
76   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
77
78   /**
79    * Non-virtual destructor; not intended as a base class
80    */
81   ~RenderManager();
82
83   /**
84    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
85    * @return The render queue.
86    */
87   RenderQueue& GetRenderQueue();
88
89   /**
90    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
91    * accessor methods should only be used from the render thread.
92    * @return The texture cache
93    */
94   TextureCache& GetTextureCache();
95
96   /**
97    * @copydoc Dali::Integration::Core::ContextCreated()
98    */
99   void ContextCreated();
100
101   /**
102    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
103    */
104   void ContextDestroyed();
105
106   /**
107    * Dispatch requests onto the postProcessResourcesQueue
108    * @param[in] request The request to dispatch
109    */
110   virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
111
112   /**
113    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
114    * caching and saving.
115    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
116    * @note This should be called during core initialisation if shader binaries are to be used.
117    */
118   void SetShaderSaver( ShaderSaver& upstream );
119
120   /**
121    * Retrieve the render instructions; these should be set during each "update" traversal.
122    * @return The render instruction container.
123    */
124   RenderInstructionContainer& GetRenderInstructionContainer();
125
126   // The following methods should be called via RenderQueue messages
127
128   /**
129    * Set the background color i.e. the glClear color used at the beginning of each frame.
130    * @param[in] color The new background color.
131    */
132   void SetBackgroundColor( const Vector4& color );
133
134   /*
135    * Set the frame time delta (time elapsed since the last frame.
136    * @param[in] deltaTime the delta time
137    */
138   void SetFrameDeltaTime( float deltaTime );
139
140   /**
141    * Returns the rectangle for the default surface (probably the application window).
142    * @return Rectangle for the surface.
143    */
144   void SetDefaultSurfaceRect( const Rect<int>& rect );
145
146   /**
147    * Add a Renderer to the render manager.
148    * @param[in] renderer The renderer to add.
149    * @post renderer is owned by RenderManager
150    */
151   void AddRenderer( Render::Renderer* renderer );
152
153   /**
154    * Remove a Renderer from the render manager.
155    * @param[in] renderer The renderer to remove.
156    * @post renderer is destroyed.
157    */
158   void RemoveRenderer( Render::Renderer* renderer );
159
160   /**
161    * Add a sampler to the render manager.
162    * @param[in] sampler The sampler to add.
163    * @post sampler is owned by RenderManager
164    */
165   void AddSampler( Render::Sampler* sampler );
166
167   /**
168    * Remove a sampler from the render manager.
169    * @param[in] sampler The sampler to remove.
170    * @post sampler is destroyed.
171    */
172   void RemoveSampler( Render::Sampler* sampler );
173
174   /**
175    * Set minification and magnification filter modes for a sampler
176    * @param[in] minFilterMode Filter mode to use when the texture is minificated
177    * @param[in] magFilterMode Filter mode to use when the texture is magnified
178    */
179   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
180
181   /**
182    * Set wrapping mode for a sampler
183    * @param[in] uWrapMode Wrap mode in the x direction
184    * @param[in] vWrapMode Wrap mode in the y direction
185    */
186   void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
187
188   /**
189    * Add a property buffer to the render manager.
190    * @param[in] propertyBuffer The property buffer to add.
191    * @post propertBuffer is owned by RenderManager
192    */
193   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
194
195   /**
196    * Remove a property buffer from the render manager.
197    * @param[in] propertyBuffer The property buffer to remove.
198    * @post propertyBuffer is destroyed.
199    */
200   void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
201
202   /**
203    * Add a geometry to the render manager.
204    * @param[in] geometry The geometry to add.
205    * @post geometry is owned by RenderManager
206    */
207   void AddGeometry( RenderGeometry* geometry );
208
209   /**
210    * Remove a geometry from the render manager.
211    * @param[in] geometry The geometry to remove.
212    * @post geometry is destroyed.
213    */
214   void RemoveGeometry( RenderGeometry* geometry );
215
216   /**
217    * Adds a property buffer to a RenderGeometry from the render manager.
218    * @param[in] geometry The geometry
219    * @param[in] propertyBuffer The property buffer to remove.
220    * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer
221    */
222   void AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer );
223
224   /**
225    * Remove a property buffer from a RenderGeometry from the render manager.
226    * @param[in] geometry The geometry
227    * @param[in] propertyBuffer The property buffer to remove.
228    * @post property buffer is destroyed.
229    */
230   void RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer );
231
232   /**
233    * Sets the format of an existing property buffer
234    * @param[in] propertyBuffer The property buffer.
235    * @param[in] format The new format of the buffer
236    */
237   void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
238
239   /**
240    * Sets the data of an existing property buffer
241    * @param[in] propertyBuffer The property buffer.
242    * @param[in] data The new data of the buffer
243    */
244   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
245
246   /**
247    * Sets the size of an existing property buffer
248    * @param[in] propertyBuffer The property buffer.
249    * @param[in] size The new size of the buffer
250    */
251   void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
252
253   /**
254    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
255    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
256    * object, usually an offscreen render task.
257    * @param[in] renderTracker The render tracker
258    */
259   void AddRenderTracker( RenderTracker* renderTracker );
260
261   /**
262    * Removes a render tracker from the RenderManager.
263    * @param[in] renderTracker The render tracker to remove.
264    */
265   void RemoveRenderTracker( RenderTracker* renderTracker );
266
267   /**
268    * Set the default shader that is to be used in absence of custom shader
269    * @param[in] shader that is the default one
270    */
271   void SetDefaultShader( Shader* shader );
272
273   /**
274    * returns the Program controller for sending program messages
275    * @return the ProgramController
276    */
277   ProgramCache* GetProgramCache();
278
279   // This method should be called from Core::Render()
280
281   /**
282    * Renders the results of the previous "update" traversal.
283    * @param[out] status contains the flag that indicates if render instructions exist
284    * @return true if a further update is required
285    */
286   bool Render( Integration::RenderStatus& status );
287
288 private:
289
290   /**
291    * Helper to process a single RenderInstruction.
292    * @param[in] instruction A description of the rendering operation.
293    * @param[in] defaultShader default shader to use.
294    */
295   void DoRender( RenderInstruction& instruction, Shader& defaultShader );
296
297 private:
298
299   /**
300    * Construct a new RenderManager.
301    */
302   RenderManager();
303
304   // Undefined
305   RenderManager( const RenderManager& );
306
307   // Undefined
308   RenderManager& operator=( const RenderManager& rhs );
309
310 private:
311
312   struct Impl;
313   Impl* mImpl;
314
315 };
316
317 } // namespace SceneGraph
318
319 } // namespace Internal
320
321 } // namespace Dali
322
323 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__