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