1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
5 * Copyright (c) 2024 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>
30 #include <dali/graphics-api/graphics-texture-upload-helper.h> // for Graphics::UploadParams
38 } // namespace Integration
59 class RenderInstruction;
60 class RenderInstructionContainer;
65 * RenderManager is responsible for rendering the result of the previous "update", which
66 * is provided in a RenderCommand during UpdateManager::Update().
72 * Construct a new RenderManager.
73 * @param[in] graphicsController The graphics controller for a given rendering backend
74 * @param[in] depthBufferAvailable Whether the depth buffer is available
75 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
77 static RenderManager* New(Graphics::Controller& graphicsController,
78 Integration::DepthBufferAvailable depthBufferAvailable,
79 Integration::StencilBufferAvailable stencilBufferAvailable,
80 Integration::PartialUpdateAvailable partialUpdateAvailable);
83 * Non-virtual destructor; not intended as a base class
88 * The graphics context is being shutdown. Clean down any outstanding graphics resources.
90 void ContextDestroyed();
93 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
94 * @return The render queue.
96 RenderQueue& GetRenderQueue();
99 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
100 * caching and saving.
101 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
102 * @note This should be called during core initialisation if shader binaries are to be used.
104 void SetShaderSaver(ShaderSaver& upstream);
106 // The foltlowing methods should be called via RenderQueue messages
109 * Set the frame time delta (time elapsed since the last frame.
110 * @param[in] deltaTime the delta time
112 void SetFrameDeltaTime(float deltaTime);
115 * Add a Renderer to the render manager.
116 * @param[in] renderer The renderer to add.
117 * @post renderer is notionally owned by RenderManager
119 void AddRenderer(const Render::RendererKey& renderer);
122 * Remove a Renderer from the render manager.
123 * @param[in] renderer The renderer to remove.
124 * @post renderer is destroyed.
126 void RemoveRenderer(const Render::RendererKey& renderer);
129 * Add a sampler to the render manager.
130 * @param[in] sampler The sampler to add.
131 * @post sampler is owned by RenderManager
133 void AddSampler(OwnerPointer<Render::Sampler>& sampler);
136 * Remove a sampler from the render manager.
137 * @param[in] sampler The sampler to remove.
138 * @post sampler is destroyed.
140 void RemoveSampler(Render::Sampler* sampler);
143 * Set minification and magnification filter modes for a sampler
144 * @param[in] minFilterMode Filter mode to use when the texture is minificated
145 * @param[in] magFilterMode Filter mode to use when the texture is magnified
147 void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
150 * Set wrapping mode for a sampler
151 * @param[in] rWrapMode Wrap mode in the z direction
152 * @param[in] uWrapMode Wrap mode in the x direction
153 * @param[in] vWrapMode Wrap mode in the y direction
155 void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
158 * Add a property buffer to the render manager.
159 * @param[in] vertexBuffer The property buffer to add.
160 * @post propertBuffer is owned by RenderManager
162 void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
165 * Remove a property buffer from the render manager.
166 * @param[in] vertexBuffer The property buffer to remove.
167 * @post vertexBuffer is destroyed.
169 void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
172 * Add a geometry to the render manager.
173 * @param[in] geometry The geometry to add.
174 * @post geometry is owned by RenderManager
176 void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
179 * Remove a geometry from the render manager.
180 * @param[in] geometry The geometry to remove.
181 * @post geometry is destroyed.
183 void RemoveGeometry(Render::Geometry* geometry);
186 * Adds a property buffer to a geometry from the render manager.
187 * @param[in] geometry The geometry
188 * @param[in] vertexBuffer The property buffer to remove.
190 void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
193 * Remove a property buffer from a Render::Geometry from the render manager.
194 * @param[in] geometry The geometry
195 * @param[in] vertexBuffer The property buffer to remove.
196 * @post property buffer is destroyed.
198 void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
201 * Sets the format of an existing property buffer
202 * @param[in] vertexBuffer The property buffer.
203 * @param[in] format The new format of the buffer
205 void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
208 * Sets the data of an existing property buffer
209 * @param[in] vertexBuffer The property buffer.
210 * @param[in] data The new data of the buffer
211 * @param[in] size The new size of the buffer
213 void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
216 * Sets vertex buffer update callback
217 * @param vertexBuffer
220 void SetVertexBufferUpdateCallback(Render::VertexBuffer* vertexBuffer, Dali::VertexBufferUpdateCallback* callback);
223 * Sets the data for the index buffer of an existing geometry
224 * @param[in] geometry The geometry
225 * @param[in] data A vector containing the indices
227 void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& data);
230 * Sets the data for the index buffer of an existing geometry
231 * @param[in] geometry The geometry
232 * @param[in] data A vector containing the indices
234 void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& data);
237 * Set the geometry type of an existing render geometry
238 * @param[in] geometry The render geometry
239 * @param[in] geometryType The new geometry type
241 void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
244 * Adds a texture to the render manager
245 * @param[in] texture The texture to add
247 void AddTexture(const Render::TextureKey& texture);
250 * Removes a texture from the render manager
251 * @param[in] texture The texture to remove
253 void RemoveTexture(const Render::TextureKey& texture);
256 * Uploads data to an existing texture
257 * @param[in] texture The texture
258 * @param[in] pixelData The pixel data object
259 * @param[in] params The parameters for the upload
261 void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Graphics::UploadParams& params);
264 * Generates mipmaps for a given texture
265 * @param[in] texture The texture
267 void GenerateMipmaps(const Render::TextureKey& texture);
270 * Set the texture size for a given texture
271 * @param[in] texture The texture
272 * @param[in] size The texture size
274 void SetTextureSize(const Render::TextureKey& texture, const Dali::ImageDimensions& size);
277 * Set the texture pixel format for a given texture
278 * @param[in] texture The texture
279 * @param[in] pixelFormat The texture pixel format
281 void SetTextureFormat(const Render::TextureKey& texture, Dali::Pixel::Format pixelFormat);
284 * Sets the updated flag of a texture
285 * @param[in] texture The updated texture
287 void SetTextureUpdated(const Render::TextureKey& textureKey);
290 * Adds a framebuffer to the render manager
291 * @param[in] frameBuffer The framebuffer to add
293 void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
296 * Removes a framebuffer from the render manager
297 * @param[in] frameBuffer The framebuffer to remove
299 void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
302 * Attaches a texture as color output to the existing frame buffer
303 * @param[in] frameBuffer The FrameBuffer
304 * @param[in] texture The texture that will be used as output when rendering
305 * @param[in] mipmapLevel The mipmap of the texture to be attached
306 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
308 void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
311 * Attaches a texture as depth output to the existing frame buffer
312 * @param[in] frameBuffer The FrameBuffer
313 * @param[in] texture The texture that will be used as output when rendering
314 * @param[in] mipmapLevel The mipmap of the texture to be attached
316 void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
319 * Attaches a texture as depth/stencil output to the existing frame buffer
320 * @param[in] frameBuffer The FrameBuffer
321 * @param[in] texture The texture that will be used as output when rendering
322 * @param[in] mipmapLevel The mipmap of the texture to be attached
324 void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
327 * Set a multisampling level value as texture output to the existing frame buffer
328 * @param[in] frameBuffer The FrameBuffer
329 * @param[in] multiSamplingLevel The level of multisampling
331 void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel);
334 * Initializes a Scene to the render manager
335 * @param[in] scene The Scene to initialize
337 void InitializeScene(SceneGraph::Scene* scene);
340 * Uninitializes a Scene to the render manager
341 * @param[in] scene The Scene to uninitialize
343 void UninitializeScene(SceneGraph::Scene* scene);
346 * This is called when the surface of the scene has been replaced.
347 * @param[in] scene The scene.
349 void SurfaceReplaced(SceneGraph::Scene* scene);
352 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
353 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
354 * object, usually an offscreen render task.
355 * @param[in] renderTracker The render tracker
357 void AddRenderTracker(Render::RenderTracker* renderTracker);
360 * Removes a render tracker from the RenderManager.
361 * @param[in] renderTracker The render tracker to remove.
363 void RemoveRenderTracker(Render::RenderTracker* renderTracker);
365 // This method should be called from Core::PreRender()
368 * This is called before rendering any scene in the next frame. This method should be preceded
369 * by a call up Update.
370 * Multi-threading note: this method should be called from a dedicated rendering thread.
371 * @pre The graphics implementation must be initialized
372 * @param[out] status showing whether update is required to run.
373 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
375 void PreRender(Integration::RenderStatus& status, bool forceClear);
377 // This method should be called from Core::PreRender()
380 * This is called before rendering any scene in the next frame. This method should be preceded
381 * by a call up Update.
382 * Multi-threading note: this method should be called from a dedicated rendering thread.
383 * @pre The graphics implementation must be initialized
384 * @param[in] scene The scene to be rendered.
385 * @param[out] damagedRects The list of damaged rects for the current render pass.
387 void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
389 // This method should be called from Core::RenderScene()
392 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
393 * This method should be called twice. The first pass to render off-screen frame buffers if any,
394 * and the second pass to render the surface.
395 * Multi-threading note: this method should be called from a dedicated rendering thread.
396 * @pre The graphics implementation must be initialized
397 * @param[out] status contains the rendering flags.
398 * @param[in] scene The scene to be rendered.
399 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
401 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
404 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
405 * This method should be called twice. The first pass to render off-screen frame buffers if any,
406 * and the second pass to render the surface.
407 * Multi-threading note: this method should be called from a dedicated rendering thread.
408 * @pre The graphics implementation must be initialized
409 * @param[out] status contains the rendering flags.
410 * @param[in] scene The scene to be rendered.
411 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
412 * @param[in] clippingRect The clipping rect for the rendered scene.
414 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
416 // This method should be called from Core::PostRender()
419 * This is called after rendering all the scenes in the next frame. This method should be
420 * followed by a call up RenderScene.
421 * Multi-threading note: this method should be called from a dedicated rendering thread.
422 * @pre The graphics implementation must be initialized
428 * Construct a new RenderManager.
433 RenderManager(const RenderManager&);
436 RenderManager& operator=(const RenderManager& rhs);
443 } // namespace SceneGraph
445 } // namespace Internal
449 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H