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 class Geometry;
53 }
54
55 namespace SceneGraph
56 {
57 class RenderQueue;
58 class TextureCache;
59 class RenderInstruction;
60 class RenderInstructionContainer;
61 class Shader;
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( Render::Geometry* 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( Render::Geometry* geometry );
219
220   /**
221    * Adds a property buffer to a geometry from the render manager.
222    * @param[in] geometry The geometry
223    * @param[in] propertyBuffer The property buffer to remove.
224    */
225   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
226
227   /**
228    * Remove a property buffer from a Render::Geometry from the render manager.
229    * @param[in] geometry The geometry
230    * @param[in] propertyBuffer The property buffer to remove.
231    * @post property buffer is destroyed.
232    */
233   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
234
235   /**
236    * Sets the format of an existing property buffer
237    * @param[in] propertyBuffer The property buffer.
238    * @param[in] format The new format of the buffer
239    */
240   void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
241
242   /**
243    * Sets the data of an existing property buffer
244    * @param[in] propertyBuffer The property buffer.
245    * @param[in] data The new data of the buffer
246    * @param[in] size The new size of the buffer
247    */
248   void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size );
249
250   /**
251    * Sets the data for the index buffer of an existing geometry
252    * @param[in] geometry The geometry
253    * @param[in] data A vector containing the indices
254    */
255   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
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( Render::Geometry* geometry, unsigned int geometryType );
263
264   /**
265    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
266    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
267    * object, usually an offscreen render task.
268    * @param[in] renderTracker The render tracker
269    */
270   void AddRenderTracker( Render::RenderTracker* renderTracker );
271
272   /**
273    * Removes a render tracker from the RenderManager.
274    * @param[in] renderTracker The render tracker to remove.
275    */
276   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
277
278   /**
279    * Set the default shader that is to be used in absence of custom shader
280    * @param[in] shader that is the default one
281    */
282   void SetDefaultShader( Shader* shader );
283
284   /**
285    * returns the Program controller for sending program messages
286    * @return the ProgramController
287    */
288   ProgramCache* GetProgramCache();
289
290   // This method should be called from Core::Render()
291
292   /**
293    * Renders the results of the previous "update" traversal.
294    * @param[out] status contains the flag that indicates if render instructions exist
295    * @return true if a further update is required
296    */
297   bool Render( Integration::RenderStatus& status );
298
299 private:
300
301   /**
302    * Helper to process a single RenderInstruction.
303    * @param[in] instruction A description of the rendering operation.
304    * @param[in] defaultShader default shader to use.
305    */
306   void DoRender( RenderInstruction& instruction, Shader& defaultShader );
307
308 private:
309
310   /**
311    * Construct a new RenderManager.
312    */
313   RenderManager();
314
315   // Undefined
316   RenderManager( const RenderManager& );
317
318   // Undefined
319   RenderManager& operator=( const RenderManager& rhs );
320
321 private:
322
323   struct Impl;
324   Impl* mImpl;
325
326 };
327
328 } // namespace SceneGraph
329
330 } // namespace Internal
331
332 } // namespace Dali
333
334 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__