cf401173c50b3d02c5708d2a71ac1695d029efaf
[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) 2023 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/graphics-api/graphics-controller.h>
23 #include <dali/integration-api/core-enumerations.h>
24 #include <dali/internal/common/shader-saver.h>
25 #include <dali/internal/event/rendering/texture-impl.h>
26 #include <dali/internal/render/renderers/render-renderer.h>
27 #include <dali/internal/render/renderers/render-vertex-buffer.h>
28 #include <dali/public-api/math/rect.h>
29
30 namespace Dali
31 {
32 namespace Integration
33 {
34 class RenderStatus;
35 class Scene;
36 } // namespace Integration
37
38 struct Vector4;
39
40 namespace Internal
41 {
42 class ProgramCache;
43 class ShaderSaver;
44
45 namespace Render
46 {
47 class FrameBuffer;
48 class Renderer;
49 struct Sampler;
50 class RenderTracker;
51 class Geometry;
52 class Texture;
53 } // namespace Render
54
55 namespace SceneGraph
56 {
57 class RenderQueue;
58 class RenderInstruction;
59 class RenderInstructionContainer;
60 class Shader;
61 class Scene;
62
63 /**
64  * RenderManager is responsible for rendering the result of the previous "update", which
65  * is provided in a RenderCommand during UpdateManager::Update().
66  */
67 class RenderManager
68 {
69 public:
70   /**
71    * Construct a new RenderManager.
72    * @param[in]  graphicsController         The graphics controller for a given rendering backend
73    * @param[in]  depthBufferAvailable       Whether the depth buffer is available
74    * @param[in]  stencilBufferAvailable     Whether the stencil buffer is available
75    */
76   static RenderManager* New(Graphics::Controller&               graphicsController,
77                             Integration::DepthBufferAvailable   depthBufferAvailable,
78                             Integration::StencilBufferAvailable stencilBufferAvailable,
79                             Integration::PartialUpdateAvailable partialUpdateAvailable);
80
81   /**
82    * Non-virtual destructor; not intended as a base class
83    */
84   ~RenderManager();
85
86   /**
87    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
88    * @return The render queue.
89    */
90   RenderQueue& GetRenderQueue();
91
92   /**
93    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
94    * caching and saving.
95    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
96    * @note This should be called during core initialisation if shader binaries are to be used.
97    */
98   void SetShaderSaver(ShaderSaver& upstream);
99
100   // The foltlowing methods should be called via RenderQueue messages
101
102   /*
103    * Set the frame time delta (time elapsed since the last frame.
104    * @param[in] deltaTime the delta time
105    */
106   void SetFrameDeltaTime(float deltaTime);
107
108   /**
109    * Add a Renderer to the render manager.
110    * @param[in] renderer The renderer to add.
111    * @post renderer is notionally owned by RenderManager
112    */
113   void AddRenderer(const Render::RendererKey& renderer);
114
115   /**
116    * Remove a Renderer from the render manager.
117    * @param[in] renderer The renderer to remove.
118    * @post renderer is destroyed.
119    */
120   void RemoveRenderer(const Render::RendererKey& renderer);
121
122   /**
123    * Add a sampler to the render manager.
124    * @param[in] sampler The sampler to add.
125    * @post sampler is owned by RenderManager
126    */
127   void AddSampler(OwnerPointer<Render::Sampler>& sampler);
128
129   /**
130    * Remove a sampler from the render manager.
131    * @param[in] sampler The sampler to remove.
132    * @post sampler is destroyed.
133    */
134   void RemoveSampler(Render::Sampler* sampler);
135
136   /**
137    * Set minification and magnification filter modes for a sampler
138    * @param[in] minFilterMode Filter mode to use when the texture is minificated
139    * @param[in] magFilterMode Filter mode to use when the texture is magnified
140    */
141   void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
142
143   /**
144    * Set wrapping mode for a sampler
145    * @param[in] rWrapMode Wrap mode in the z direction
146    * @param[in] uWrapMode Wrap mode in the x direction
147    * @param[in] vWrapMode Wrap mode in the y direction
148    */
149   void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
150
151   /**
152    * Add a property buffer to the render manager.
153    * @param[in] vertexBuffer The property buffer to add.
154    * @post propertBuffer is owned by RenderManager
155    */
156   void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
157
158   /**
159    * Remove a property buffer from the render manager.
160    * @param[in] vertexBuffer The property buffer to remove.
161    * @post vertexBuffer is destroyed.
162    */
163   void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
164
165   /**
166    * Add a geometry to the render manager.
167    * @param[in] geometry The geometry to add.
168    * @post geometry is owned by RenderManager
169    */
170   void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
171
172   /**
173    * Remove a geometry from the render manager.
174    * @param[in] geometry The geometry to remove.
175    * @post geometry is destroyed.
176    */
177   void RemoveGeometry(Render::Geometry* geometry);
178
179   /**
180    * Adds a property buffer to a geometry from the render manager.
181    * @param[in] geometry The geometry
182    * @param[in] vertexBuffer The property buffer to remove.
183    */
184   void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
185
186   /**
187    * Remove a property buffer from a Render::Geometry from the render manager.
188    * @param[in] geometry The geometry
189    * @param[in] vertexBuffer The property buffer to remove.
190    * @post property buffer is destroyed.
191    */
192   void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
193
194   /**
195    * Sets the format of an existing property buffer
196    * @param[in] vertexBuffer The property buffer.
197    * @param[in] format The new format of the buffer
198    */
199   void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
200
201   /**
202    * Sets the data of an existing property buffer
203    * @param[in] vertexBuffer The property buffer.
204    * @param[in] data The new data of the buffer
205    * @param[in] size The new size of the buffer
206    */
207   void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
208
209   /**
210    * Sets the data for the index buffer of an existing geometry
211    * @param[in] geometry The geometry
212    * @param[in] data A vector containing the indices
213    */
214   void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& data);
215
216   /**
217    * Sets the data for the index buffer of an existing geometry
218    * @param[in] geometry The geometry
219    * @param[in] data A vector containing the indices
220    */
221   void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& data);
222
223   /**
224    * Set the geometry type of an existing render geometry
225    * @param[in] geometry The render geometry
226    * @param[in] geometryType The new geometry type
227    */
228   void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
229
230   /**
231    * Adds a texture to the render manager
232    * @param[in] texture The texture to add
233    */
234   void AddTexture(const Render::TextureKey& texture);
235
236   /**
237    * Removes a texture from the render manager
238    * @param[in] texture The texture to remove
239    */
240   void RemoveTexture(const Render::TextureKey& texture);
241
242   /**
243    * Uploads data to an existing texture
244    * @param[in] texture The texture
245    * @param[in] pixelData The pixel data object
246    * @param[in] params The parameters for the upload
247    */
248   void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
249
250   /**
251    * Generates mipmaps for a given texture
252    * @param[in] texture The texture
253    */
254   void GenerateMipmaps(const Render::TextureKey& texture);
255
256   /**
257    * Adds a framebuffer to the render manager
258    * @param[in] frameBuffer The framebuffer to add
259    */
260   void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
261
262   /**
263    * Removes a framebuffer from the render manager
264    * @param[in] frameBuffer The framebuffer to remove
265    */
266   void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
267
268   /**
269    * Attaches a texture as color output to the existing frame buffer
270    * @param[in] frameBuffer The FrameBuffer
271    * @param[in] texture The texture that will be used as output when rendering
272    * @param[in] mipmapLevel The mipmap of the texture to be attached
273    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
274    */
275   void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
276
277   /**
278    * Attaches a texture as depth output to the existing frame buffer
279    * @param[in] frameBuffer The FrameBuffer
280    * @param[in] texture The texture that will be used as output when rendering
281    * @param[in] mipmapLevel The mipmap of the texture to be attached
282    */
283   void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
284
285   /**
286    * Attaches a texture as depth/stencil output to the existing frame buffer
287    * @param[in] frameBuffer The FrameBuffer
288    * @param[in] texture The texture that will be used as output when rendering
289    * @param[in] mipmapLevel The mipmap of the texture to be attached
290    */
291   void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
292
293   /**
294    * Set a multisampling level value as texture output to the existing frame buffer
295    * @param[in] frameBuffer The FrameBuffer
296    * @param[in] multiSamplingLevel The level of multisampling
297    */
298   void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel);
299
300   /**
301    * Initializes a Scene to the render manager
302    * @param[in] scene The Scene to initialize
303    */
304   void InitializeScene(SceneGraph::Scene* scene);
305
306   /**
307    * Uninitializes a Scene to the render manager
308    * @param[in] scene The Scene to uninitialize
309    */
310   void UninitializeScene(SceneGraph::Scene* scene);
311
312   /**
313    * This is called when the surface of the scene has been replaced.
314    * @param[in] scene The scene.
315    */
316   void SurfaceReplaced(SceneGraph::Scene* scene);
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   // This method should be called from Core::PreRender()
333
334   /**
335    * This is called before rendering any scene in the next frame. This method should be preceded
336    * by a call up Update.
337    * Multi-threading note: this method should be called from a dedicated rendering thread.
338    * @pre The graphics implementation must be initialized
339    * @param[out] status showing whether update is required to run.
340    * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
341    */
342   void PreRender(Integration::RenderStatus& status, bool forceClear);
343
344   // This method should be called from Core::PreRender()
345
346   /**
347    * This is called before rendering any scene in the next frame. This method should be preceded
348    * by a call up Update.
349    * Multi-threading note: this method should be called from a dedicated rendering thread.
350    * @pre The graphics implementation must be initialized
351    * @param[in] scene The scene to be rendered.
352    * @param[out] damagedRects The list of damaged rects for the current render pass.
353    */
354   void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
355
356   // This method should be called from Core::RenderScene()
357
358   /**
359    * Render a scene in the next frame. This method should be preceded by a call up PreRender.
360    * This method should be called twice. The first pass to render off-screen frame buffers if any,
361    * and the second pass to render the surface.
362    * Multi-threading note: this method should be called from a dedicated rendering thread.
363    * @pre The graphics implementation must be initialized
364    * @param[out] status contains the rendering flags.
365    * @param[in] scene The scene to be rendered.
366    * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
367    */
368   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
369
370   /**
371    * Render a scene in the next frame. This method should be preceded by a call up PreRender.
372    * This method should be called twice. The first pass to render off-screen frame buffers if any,
373    * and the second pass to render the surface.
374    * Multi-threading note: this method should be called from a dedicated rendering thread.
375    * @pre The graphics implementation must be initialized
376    * @param[out] status contains the rendering flags.
377    * @param[in] scene The scene to be rendered.
378    * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
379    * @param[in] clippingRect The clipping rect for the rendered scene.
380    */
381   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
382
383   // This method should be called from Core::PostRender()
384
385   /**
386    * This is called after rendering all the scenes in the next frame. This method should be
387    * followed by a call up RenderScene.
388    * Multi-threading note: this method should be called from a dedicated rendering thread.
389    * @pre The graphics implementation must be initialized
390    */
391   void PostRender();
392
393 private:
394   /**
395    * Construct a new RenderManager.
396    */
397   RenderManager();
398
399   // Undefined
400   RenderManager(const RenderManager&);
401
402   // Undefined
403   RenderManager& operator=(const RenderManager& rhs);
404
405 private:
406   struct Impl;
407   Impl* mImpl;
408 };
409
410 } // namespace SceneGraph
411
412 } // namespace Internal
413
414 } // namespace Dali
415
416 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H