248c9fdb58ee0015b7e3cd43892a0cd0378a02a8
[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
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    * @copydoc Dali::Integration::Core::ContextCreated()
101    */
102   void ContextCreated();
103
104   /**
105    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
106    */
107   void ContextDestroyed();
108
109   /**
110    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
111    * caching and saving.
112    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
113    * @note This should be called during core initialisation if shader binaries are to be used.
114    */
115   void SetShaderSaver( ShaderSaver& upstream );
116
117   /**
118    * Retrieve the render instructions; these should be set during each "update" traversal.
119    * @return The render instruction container.
120    */
121   RenderInstructionContainer& GetRenderInstructionContainer();
122
123   // The following methods should be called via RenderQueue messages
124
125   /**
126    * Set the background color i.e. the glClear color used at the beginning of each frame.
127    * @param[in] color The new background color.
128    */
129   void SetBackgroundColor( const Vector4& color );
130
131   /*
132    * Set the frame time delta (time elapsed since the last frame.
133    * @param[in] deltaTime the delta time
134    */
135   void SetFrameDeltaTime( float deltaTime );
136
137   /**
138    * Returns the rectangle for the default surface (probably the application window).
139    * @return Rectangle for the surface.
140    */
141   void SetDefaultSurfaceRect( const Rect<int>& rect );
142
143   /**
144    * Returns the orintation for the default surface (probably the application window).
145    * @return Orientation for the surface.
146    */
147   void SetDefaultSurfaceOrientation( int orientation );
148
149   /**
150    * Add a Renderer to the render manager.
151    * @param[in] renderer The renderer to add.
152    * @post renderer is owned by RenderManager
153    */
154   void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
155
156   /**
157    * Remove a Renderer from the render manager.
158    * @param[in] renderer The renderer to remove.
159    * @post renderer is destroyed.
160    */
161   void RemoveRenderer( Render::Renderer* renderer );
162
163   /**
164    * Add a sampler to the render manager.
165    * @param[in] sampler The sampler to add.
166    * @post sampler is owned by RenderManager
167    */
168   void AddSampler( OwnerPointer< Render::Sampler >& sampler );
169
170   /**
171    * Remove a sampler from the render manager.
172    * @param[in] sampler The sampler to remove.
173    * @post sampler is destroyed.
174    */
175   void RemoveSampler( Render::Sampler* sampler );
176
177   /**
178    * Set minification and magnification filter modes for a sampler
179    * @param[in] minFilterMode Filter mode to use when the texture is minificated
180    * @param[in] magFilterMode Filter mode to use when the texture is magnified
181    */
182   void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
183
184   /**
185    * Set wrapping mode for a sampler
186    * @param[in] rWrapMode Wrap mode in the z direction
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, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
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( OwnerPointer< 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( OwnerPointer< 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 AttachVertexBuffer( 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, OwnerPointer< 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, OwnerPointer< Vector<uint8_t> >& data, uint32_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<uint16_t>& 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, uint32_t geometryType );
263
264   /**
265    * Adds a texture to the render manager
266    * @param[in] texture The texture to add
267    */
268   void AddTexture( OwnerPointer< Render::Texture >& texture );
269
270   /**
271    * Removes a texture from the render manager
272    * @param[in] texture The texture to remove
273    */
274   void RemoveTexture( Render::Texture* texture );
275
276   /**
277    * Uploads data to an existing texture
278    * @param[in] texture The texture
279    * @param[in] pixelData The pixel data object
280    * @param[in] params The parameters for the upload
281    */
282   void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
283
284   /**
285    * Generates mipmaps for a given texture
286    * @param[in] texture The texture
287    */
288   void GenerateMipmaps( Render::Texture* texture );
289
290   /**
291    * Adds a framebuffer to the render manager
292    * @param[in] frameBuffer The framebuffer to add
293    */
294   void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
295
296   /**
297    * Removes a framebuffer from the render manager
298    * @param[in] frameBuffer The framebuffer to remove
299    */
300   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
301
302   /**
303    * Attach a texture as color output to an existing FrameBuffer
304    * @param[in] frameBuffer The FrameBuffer
305    * @param[in] texture The texture that will be used as output when rendering
306    * @param[in] mipmapLevel The mipmap of the texture to be attached
307    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
308    */
309   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
310
311   /**
312    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
313    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
314    * object, usually an offscreen render task.
315    * @param[in] renderTracker The render tracker
316    */
317   void AddRenderTracker( Render::RenderTracker* renderTracker );
318
319   /**
320    * Removes a render tracker from the RenderManager.
321    * @param[in] renderTracker The render tracker to remove.
322    */
323   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
324
325   /**
326    * returns the Program controller for sending program messages
327    * @return the ProgramController
328    */
329   ProgramCache* GetProgramCache();
330
331   // This method should be called from Core::Render()
332
333   /**
334    * Renders the results of the previous "update" traversal.
335    * @param[out] status contains the rendering flags.
336    * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
337    */
338   void Render( Integration::RenderStatus& status, bool forceClear );
339
340 private:
341
342   /**
343    * Helper to process a single RenderInstruction.
344    * @param[in] instruction A description of the rendering operation.
345    */
346   void DoRender( RenderInstruction& instruction );
347
348 private:
349
350   /**
351    * Construct a new RenderManager.
352    */
353   RenderManager();
354
355   // Undefined
356   RenderManager( const RenderManager& );
357
358   // Undefined
359   RenderManager& operator=( const RenderManager& rhs );
360
361 private:
362
363   struct Impl;
364   Impl* mImpl;
365
366 };
367
368 } // namespace SceneGraph
369
370 } // namespace Internal
371
372 } // namespace Dali
373
374 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H