1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
36 } // namespace Integration
58 class RenderInstruction;
59 class RenderInstructionContainer;
64 * RenderManager is responsible for rendering the result of the previous "update", which
65 * is provided in a RenderCommand during UpdateManager::Update().
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
76 static RenderManager* New(Graphics::Controller& graphicsController,
77 Integration::DepthBufferAvailable depthBufferAvailable,
78 Integration::StencilBufferAvailable stencilBufferAvailable,
79 Integration::PartialUpdateAvailable partialUpdateAvailable);
82 * Non-virtual destructor; not intended as a base class
87 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
88 * @return The render queue.
90 RenderQueue& GetRenderQueue();
93 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
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.
98 void SetShaderSaver(ShaderSaver& upstream);
100 // The foltlowing methods should be called via RenderQueue messages
103 * Set the frame time delta (time elapsed since the last frame.
104 * @param[in] deltaTime the delta time
106 void SetFrameDeltaTime(float deltaTime);
109 * Add a Renderer to the render manager.
110 * @param[in] renderer The renderer to add.
111 * @post renderer is notionally owned by RenderManager
113 void AddRenderer(const Render::RendererKey& renderer);
116 * Remove a Renderer from the render manager.
117 * @param[in] renderer The renderer to remove.
118 * @post renderer is destroyed.
120 void RemoveRenderer(const Render::RendererKey& renderer);
123 * Add a sampler to the render manager.
124 * @param[in] sampler The sampler to add.
125 * @post sampler is owned by RenderManager
127 void AddSampler(OwnerPointer<Render::Sampler>& sampler);
130 * Remove a sampler from the render manager.
131 * @param[in] sampler The sampler to remove.
132 * @post sampler is destroyed.
134 void RemoveSampler(Render::Sampler* sampler);
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
141 void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
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
149 void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
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
156 void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
159 * Remove a property buffer from the render manager.
160 * @param[in] vertexBuffer The property buffer to remove.
161 * @post vertexBuffer is destroyed.
163 void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
166 * Add a geometry to the render manager.
167 * @param[in] geometry The geometry to add.
168 * @post geometry is owned by RenderManager
170 void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
173 * Remove a geometry from the render manager.
174 * @param[in] geometry The geometry to remove.
175 * @post geometry is destroyed.
177 void RemoveGeometry(Render::Geometry* geometry);
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.
184 void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
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.
192 void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
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
199 void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
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
207 void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
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
214 void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& data);
217 * Set the geometry type of an existing render geometry
218 * @param[in] geometry The render geometry
219 * @param[in] geometryType The new geometry type
221 void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
224 * Adds a texture to the render manager
225 * @param[in] texture The texture to add
227 void AddTexture(const Render::TextureKey& texture);
230 * Removes a texture from the render manager
231 * @param[in] texture The texture to remove
233 void RemoveTexture(const Render::TextureKey& texture);
236 * Uploads data to an existing texture
237 * @param[in] texture The texture
238 * @param[in] pixelData The pixel data object
239 * @param[in] params The parameters for the upload
241 void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
244 * Generates mipmaps for a given texture
245 * @param[in] texture The texture
247 void GenerateMipmaps(const Render::TextureKey& texture);
250 * Adds a framebuffer to the render manager
251 * @param[in] frameBuffer The framebuffer to add
253 void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
256 * Removes a framebuffer from the render manager
257 * @param[in] frameBuffer The framebuffer to remove
259 void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
262 * Attaches a texture as color output to the existing frame buffer
263 * @param[in] frameBuffer The FrameBuffer
264 * @param[in] texture The texture that will be used as output when rendering
265 * @param[in] mipmapLevel The mipmap of the texture to be attached
266 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
268 void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
271 * Attaches a texture as depth output to the existing frame buffer
272 * @param[in] frameBuffer The FrameBuffer
273 * @param[in] texture The texture that will be used as output when rendering
274 * @param[in] mipmapLevel The mipmap of the texture to be attached
276 void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
279 * Attaches a texture as depth/stencil output to the existing frame buffer
280 * @param[in] frameBuffer The FrameBuffer
281 * @param[in] texture The texture that will be used as output when rendering
282 * @param[in] mipmapLevel The mipmap of the texture to be attached
284 void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
287 * Set a multisampling level value as texture output to the existing frame buffer
288 * @param[in] frameBuffer The FrameBuffer
289 * @param[in] multiSamplingLevel The level of multisampling
291 void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel);
294 * Initializes a Scene to the render manager
295 * @param[in] scene The Scene to initialize
297 void InitializeScene(SceneGraph::Scene* scene);
300 * Uninitializes a Scene to the render manager
301 * @param[in] scene The Scene to uninitialize
303 void UninitializeScene(SceneGraph::Scene* scene);
306 * This is called when the surface of the scene has been replaced.
307 * @param[in] scene The scene.
309 void SurfaceReplaced(SceneGraph::Scene* scene);
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
317 void AddRenderTracker(Render::RenderTracker* renderTracker);
320 * Removes a render tracker from the RenderManager.
321 * @param[in] renderTracker The render tracker to remove.
323 void RemoveRenderTracker(Render::RenderTracker* renderTracker);
325 // This method should be called from Core::PreRender()
328 * This is called before rendering any scene in the next frame. This method should be preceded
329 * by a call up Update.
330 * Multi-threading note: this method should be called from a dedicated rendering thread.
331 * @pre The graphics implementation must be initialized
332 * @param[out] status showing whether update is required to run.
333 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
335 void PreRender(Integration::RenderStatus& status, bool forceClear);
337 // This method should be called from Core::PreRender()
340 * This is called before rendering any scene in the next frame. This method should be preceded
341 * by a call up Update.
342 * Multi-threading note: this method should be called from a dedicated rendering thread.
343 * @pre The graphics implementation must be initialized
344 * @param[in] scene The scene to be rendered.
345 * @param[out] damagedRects The list of damaged rects for the current render pass.
347 void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
349 // This method should be called from Core::RenderScene()
352 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
353 * This method should be called twice. The first pass to render off-screen frame buffers if any,
354 * and the second pass to render the surface.
355 * Multi-threading note: this method should be called from a dedicated rendering thread.
356 * @pre The graphics implementation must be initialized
357 * @param[out] status contains the rendering flags.
358 * @param[in] scene The scene to be rendered.
359 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
361 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
364 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
365 * This method should be called twice. The first pass to render off-screen frame buffers if any,
366 * and the second pass to render the surface.
367 * Multi-threading note: this method should be called from a dedicated rendering thread.
368 * @pre The graphics implementation must be initialized
369 * @param[out] status contains the rendering flags.
370 * @param[in] scene The scene to be rendered.
371 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
372 * @param[in] clippingRect The clipping rect for the rendered scene.
374 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
376 // This method should be called from Core::PostRender()
379 * This is called after rendering all the scenes in the next frame. This method should be
380 * followed by a call up RenderScene.
381 * Multi-threading note: this method should be called from a dedicated rendering thread.
382 * @pre The graphics implementation must be initialized
388 * Construct a new RenderManager.
393 RenderManager(const RenderManager&);
396 RenderManager& operator=(const RenderManager& rhs);
403 } // namespace SceneGraph
405 } // namespace Internal
409 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H