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