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