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